Commit 10219e72 by Nicolas Capens

Use the full format to specify frame buffer blits.

parent 6296dbb3
#define MAJOR_VERSION 3
#define MINOR_VERSION 2
#define BUILD_VERSION 6
#define BUILD_REVISION 47507
#define BUILD_REVISION 47654
#define STRINGIFY(x) #x
#define MACRO_STRINGIFY(x) STRINGIFY(x)
......
......@@ -186,9 +186,8 @@ void Surface::swap()
if(backBuffer)
{
bool HDR = backBuffer->getInternalFormat() == sw::FORMAT_A16B16G16R16;
void *source = backBuffer->lockInternal(0, 0, 0, sw::LOCK_READONLY, sw::PUBLIC);
frameBuffer->flip(source, HDR);
frameBuffer->flip(source, backBuffer->getInternalFormat());
backBuffer->unlockInternal();
checkForResize();
......
......@@ -40,7 +40,7 @@ public:
Surface(Display *display, const egl::Config *config, EGLNativeWindowType window);
Surface(Display *display, const egl::Config *config, EGLint width, EGLint height, EGLenum textureFormat, EGLenum textureTarget);
~Surface();
virtual ~Surface();
bool initialize();
void swap();
......
......@@ -222,14 +222,6 @@ void Context::makeCurrent(egl::Display *display, egl::Surface *surface)
mVertexDataManager = new VertexDataManager(this);
mIndexDataManager = new IndexDataManager();
const sw::Format renderBufferFormats[] =
{
sw::FORMAT_A8R8G8B8,
sw::FORMAT_X8R8G8B8,
sw::FORMAT_R5G6B5,
sw::FORMAT_D24S8
};
initExtensionString();
mState.viewportX = 0;
......
......@@ -239,7 +239,7 @@ class Context
public:
Context(const egl::Config *config, const Context *shareContext);
~Context();
virtual ~Context();
void makeCurrent(egl::Display *display, egl::Surface *surface);
......
......@@ -58,8 +58,8 @@ namespace sw
this->width = width;
this->height = height;
bitDepth = 32;
HDRdisplay = false;
destFormat = FORMAT_X8R8G8B8;
sourceFormat = FORMAT_X8R8G8B8;
stride = 0;
if(forceWindowed)
......@@ -74,7 +74,8 @@ namespace sw
blitState.width = 0;
blitState.height = 0;
blitState.depth = 0;
blitState.destFormat = FORMAT_X8R8G8B8;
blitState.sourceFormat = FORMAT_X8R8G8B8;
blitState.cursorWidth = 0;
blitState.cursorHeight = 0;
......@@ -145,7 +146,7 @@ namespace sw
cursorPositionY = y;
}
void FrameBuffer::copy(void *source, bool HDR)
void FrameBuffer::copy(void *source, Format format)
{
if(!source)
{
......@@ -164,13 +165,13 @@ namespace sw
else
{
const int width2 = (width + 1) & ~1;
const int sBytes = HDR ? 8 : 4;
const int sBytes = Surface::bytes(sourceFormat);
const int sStride = sBytes * width2;
target = (byte*)source + (height - 1) * sStride;
}
HDRdisplay = HDR;
sourceFormat = format;
cursorX = cursorPositionX - cursorHotspotX;
cursorY = cursorPositionY - cursorHotspotY;
......@@ -194,9 +195,9 @@ namespace sw
update.width = width;
update.height = height;
update.depth = bitDepth;
update.destFormat = destFormat;
update.sourceFormat = sourceFormat;
update.stride = stride;
update.HDR = HDRdisplay;
update.cursorWidth = cursorWidth;
update.cursorHeight = cursorHeight;
......@@ -219,9 +220,9 @@ namespace sw
const int width = state.width;
const int height = state.height;
const int width2 = (state.width + 1) & ~1;
const int dBytes = state.depth / 8;
const int dBytes = Surface::bytes(state.destFormat);
const int dStride = state.stride;
const int sBytes = state.HDR ? 8 : 4;
const int sBytes = Surface::bytes(state.sourceFormat);
const int sStride = topLeftOrigin ? (sBytes * width2) : -(sBytes * width2);
// char compareApp[32] = SCRAMBLE31(validationApp, APPNAME_SCRAMBLE);
......@@ -272,11 +273,11 @@ namespace sw
}
#endif
if(state.depth == 32)
if(state.destFormat == FORMAT_X8R8G8B8)
{
Int x = x0;
if(!state.HDR)
if(state.sourceFormat == FORMAT_X8R8G8B8 || state.sourceFormat == FORMAT_A8R8G8B8)
{
For(, x < width - 3, x += 4)
{
......@@ -286,7 +287,7 @@ namespace sw
d += 4 * dBytes;
}
}
else
else if(state.sourceFormat == FORMAT_A16B16G16R16)
{
For(, x < width - 1, x += 2)
{
......@@ -299,61 +300,65 @@ namespace sw
d += 2 * dBytes;
}
}
else ASSERT(false);
For(, x < width, x++)
{
if(!state.HDR)
if(state.sourceFormat == FORMAT_X8R8G8B8 || state.sourceFormat == FORMAT_A8R8G8B8)
{
*Pointer<Int>(d) = *Pointer<Int>(s);
}
else
else if(state.sourceFormat == FORMAT_A16B16G16R16)
{
UShort4 c = As<UShort4>(Swizzle(*Pointer<Short4>(s), 0xC6)) >> 8;
*Pointer<Int>(d) = Int(As<Int2>(Pack(c, c)));
}
else ASSERT(false);
s += sBytes;
d += dBytes;
}
}
else if(state.depth == 24)
else if(state.destFormat == FORMAT_R8G8B8)
{
For(Int x = x0, x < width, x++)
{
if(!state.HDR)
if(state.sourceFormat == FORMAT_X8R8G8B8 || state.sourceFormat == FORMAT_A8R8G8B8)
{
*Pointer<Byte>(d + 0) = *Pointer<Byte>(s + 0);
*Pointer<Byte>(d + 1) = *Pointer<Byte>(s + 1);
*Pointer<Byte>(d + 2) = *Pointer<Byte>(s + 2);
}
else
else if(state.sourceFormat == FORMAT_A16B16G16R16)
{
*Pointer<Byte>(d + 0) = *Pointer<Byte>(s + 5);
*Pointer<Byte>(d + 1) = *Pointer<Byte>(s + 3);
*Pointer<Byte>(d + 2) = *Pointer<Byte>(s + 1);
}
else ASSERT(false);
s += sBytes;
d += dBytes;
}
}
else if(state.depth == 16)
else if(state.destFormat == FORMAT_R5G6B5)
{
For(Int x = x0, x < width, x++)
{
Int c;
if(!state.HDR)
if(state.sourceFormat == FORMAT_X8R8G8B8 || state.sourceFormat == FORMAT_A8R8G8B8)
{
c = *Pointer<Int>(s);
}
else
else if(state.sourceFormat == FORMAT_A16B16G16R16)
{
UShort4 cc = As<UShort4>(Swizzle(*Pointer<Short4>(s + 0), 0xC6)) >> 8;
c = Int(As<Int2>(Pack(cc, cc)));
}
else ASSERT(false);
*Pointer<Short>(d) = Short((c & 0x00F80000) >> 8 |
(c & 0x0000FC00) >> 5 |
......@@ -439,14 +444,15 @@ namespace sw
c1 = UnpackLow(As<Byte8>(c1), *Pointer<Byte8>(c));
if(!state.HDR)
if(state.sourceFormat == FORMAT_X8R8G8B8 || state.sourceFormat == FORMAT_A8R8G8B8)
{
c2 = UnpackLow(As<Byte8>(c2), *Pointer<Byte8>(s));
}
else
else if(state.sourceFormat == FORMAT_A16B16G16R16)
{
c2 = Swizzle(*Pointer<Short4>(s + 0), 0xC6);
}
else ASSERT(false);
c1 = As<Short4>(As<UShort4>(c1) >> 9);
c2 = As<Short4>(As<UShort4>(c2) >> 9);
......@@ -460,11 +466,11 @@ namespace sw
c1 = As<Short4>(Pack(As<UShort4>(c1), As<UShort4>(c1)));
if(state.depth == 32)
if(state.destFormat == FORMAT_X8R8G8B8)
{
*Pointer<UInt>(d) = UInt(As<Long>(c1));
}
else if(state.depth == 24)
else if(state.destFormat == FORMAT_R8G8B8)
{
Int c = Int(As<Int2>(c1));
......@@ -472,7 +478,7 @@ namespace sw
*Pointer<Byte>(d + 1) = Byte(c >> 8);
*Pointer<Byte>(d + 2) = Byte(c >> 16);
}
else if(state.depth == 16)
else if(state.destFormat == FORMAT_R5G6B5)
{
Int c = Int(As<Int2>(c1));
......
......@@ -24,9 +24,9 @@ namespace sw
{
int width;
int height;
int depth; // Display bit depth; 32 = X8R8G8B8, 24 = R8G8B8, 16 = R5G6B5
Format destFormat;
Format sourceFormat;
int stride;
bool HDR; // A16B16G16R16 source color buffer
int cursorWidth;
int cursorHeight;
};
......@@ -42,8 +42,8 @@ namespace sw
int getHeight() const;
int getStride() const;
virtual void flip(void *source, bool HDR) = 0;
virtual void blit(void *source, const Rect *sourceRect, const Rect *destRect, bool HDR) = 0;
virtual void flip(void *source, Format format) = 0;
virtual void blit(void *source, const Rect *sourceRect, const Rect *destRect, Format format) = 0;
virtual void *lock() = 0;
virtual void unlock() = 0;
......@@ -55,13 +55,13 @@ namespace sw
static Routine *copyRoutine(const BlitState &state);
protected:
void copy(void *source, bool HDR);
void copy(void *source, Format format);
int width;
int height;
Format sourceFormat;
Format destFormat;
int stride;
int bitDepth;
bool HDRdisplay;
bool windowed;
void *locked; // Video memory back buffer
......
......@@ -100,9 +100,16 @@ namespace sw
long result = directDraw->CreateSurface(&ddsd, &frontBuffer, 0);
directDraw->GetDisplayMode(&ddsd);
bitDepth = ddsd.ddpfPixelFormat.dwRGBBitCount;
switch(ddsd.ddpfPixelFormat.dwRGBBitCount)
{
case 32: destFormat = FORMAT_X8R8G8B8; break;
case 24: destFormat = FORMAT_R8G8B8; break;
case 16: destFormat = FORMAT_R5G6B5; break;
default: destFormat = FORMAT_NULL; break;
}
if((result != DD_OK && result != DDERR_PRIMARYSURFACEALREADYEXISTS) || (bitDepth != 32 && bitDepth != 24 && bitDepth != 16))
if((result != DD_OK && result != DDERR_PRIMARYSURFACEALREADYEXISTS) || (destFormat == FORMAT_NULL))
{
assert(!"Failed to initialize graphics: Incompatible display mode.");
}
......@@ -196,18 +203,18 @@ namespace sw
do
{
bitDepth = 32;
result = directDraw->SetDisplayMode(width, height, bitDepth);
destFormat = FORMAT_X8R8G8B8;
result = directDraw->SetDisplayMode(width, height, 32);
if(result == DDERR_INVALIDMODE)
{
bitDepth = 16;
result = directDraw->SetDisplayMode(width, height, bitDepth);
destFormat = FORMAT_R8G8B8;
result = directDraw->SetDisplayMode(width, height, 24);
if(result == DDERR_INVALIDMODE)
{
bitDepth = 24;
result = directDraw->SetDisplayMode(width, height, bitDepth);
destFormat = FORMAT_R5G6B5;
result = directDraw->SetDisplayMode(width, height, 16);
if(result == DDERR_INVALIDMODE)
{
......@@ -240,9 +247,9 @@ namespace sw
updateBounds(windowHandle);
}
void FrameBufferDD::flip(void *source, bool HDR)
void FrameBufferDD::flip(void *source, Format format)
{
copy(source, HDR);
copy(source, format);
if(!readySurfaces())
{
......@@ -271,9 +278,9 @@ namespace sw
}
}
void FrameBufferDD::blit(void *source, const Rect *sourceRect, const Rect *destRect, bool HDR)
void FrameBufferDD::blit(void *source, const Rect *sourceRect, const Rect *destRect, Format format)
{
copy(source, HDR);
copy(source, format);
if(!readySurfaces())
{
......@@ -310,20 +317,20 @@ namespace sw
}
}
void FrameBufferDD::flip(HWND windowOverride, void *source, bool HDR)
void FrameBufferDD::flip(HWND windowOverride, void *source, Format format)
{
updateClipper(windowOverride);
updateBounds(windowOverride);
flip(source, HDR);
flip(source, format);
}
void FrameBufferDD::blit(HWND windowOverride, void *source, const Rect *sourceRect, const Rect *destRect, bool HDR)
void FrameBufferDD::blit(HWND windowOverride, void *source, const Rect *sourceRect, const Rect *destRect, Format format)
{
updateClipper(windowOverride);
updateBounds(windowOverride);
blit(source, sourceRect, destRect, HDR);
blit(source, sourceRect, destRect, format);
}
void FrameBufferDD::screenshot(void *destBuffer)
......
......@@ -25,11 +25,11 @@ namespace sw
virtual ~FrameBufferDD();
virtual void flip(void *source, bool HDR);
virtual void blit(void *source, const Rect *sourceRect, const Rect *destRect, bool HDR);
virtual void flip(void *source, Format format);
virtual void blit(void *source, const Rect *sourceRect, const Rect *destRect, Format format);
virtual void flip(HWND windowOverride, void *source, bool HDR);
virtual void blit(HWND windowOverride, void *source, const Rect *sourceRect, const Rect *destRect, bool HDR);
virtual void flip(HWND windowOverride, void *source, Format format);
virtual void blit(HWND windowOverride, void *source, const Rect *sourceRect, const Rect *destRect, Format format);
virtual void *lock();
virtual void unlock();
......
......@@ -34,7 +34,7 @@ namespace sw
init(this->windowHandle);
bitDepth = 32;
destFormat = FORMAT_X8R8G8B8;
}
FrameBufferGDI::~FrameBufferGDI()
......@@ -68,14 +68,14 @@ namespace sw
{
}
void FrameBufferGDI::flip(void *source, bool HDR)
void FrameBufferGDI::flip(void *source, Format format)
{
blit(source, 0, 0, HDR);
blit(source, 0, 0, format);
}
void FrameBufferGDI::blit(void *source, const Rect *sourceRect, const Rect *destRect, bool HDR)
void FrameBufferGDI::blit(void *source, const Rect *sourceRect, const Rect *destRect, Format format)
{
copy(source, HDR);
copy(source, format);
int sourceLeft = sourceRect ? sourceRect->x0 : 0;
int sourceTop = sourceRect ? sourceRect->y0 : 0;
......@@ -89,12 +89,12 @@ namespace sw
StretchBlt(windowContext, destLeft, destTop, destWidth, destHeight, bitmapContext, sourceLeft, sourceTop, sourceWidth, sourceHeight, SRCCOPY);
}
void FrameBufferGDI::flip(HWND windowOverride, void *source, bool HDR)
void FrameBufferGDI::flip(HWND windowOverride, void *source, Format format)
{
blit(windowOverride, source, 0, 0, HDR);
blit(windowOverride, source, 0, 0, format);
}
void FrameBufferGDI::blit(HWND windowOverride, void *source, const Rect *sourceRect, const Rect *destRect, bool HDR)
void FrameBufferGDI::blit(HWND windowOverride, void *source, const Rect *sourceRect, const Rect *destRect, Format format)
{
if(windowed && windowOverride != 0 && windowOverride != bitmapWindow)
{
......@@ -102,7 +102,7 @@ namespace sw
init(windowOverride);
}
blit(source, sourceRect, destRect, HDR);
blit(source, sourceRect, destRect, format);
}
void FrameBufferGDI::setGammaRamp(GammaRamp *gammaRamp, bool calibrate)
......
......@@ -23,11 +23,11 @@ namespace sw
virtual ~FrameBufferGDI();
virtual void flip(void *source, bool HDR);
virtual void blit(void *source, const Rect *sourceRect, const Rect *destRect, bool HDR);
virtual void flip(void *source, Format format);
virtual void blit(void *source, const Rect *sourceRect, const Rect *destRect, Format format);
virtual void flip(HWND windowOverride, void *source, bool HDR);
virtual void blit(HWND windowOverride, void *source, const Rect *sourceRect, const Rect *destRect, bool HDR);
virtual void flip(HWND windowOverride, void *source, Format format);
virtual void blit(HWND windowOverride, void *source, const Rect *sourceRect, const Rect *destRect, Format format);
virtual void *lock();
virtual void unlock();
......
......@@ -30,11 +30,11 @@ namespace sw
virtual ~FrameBufferWin();
virtual void flip(void *source, bool HDR) = 0;
virtual void blit(void *source, const Rect *sourceRect, const Rect *destRect, bool HDR) = 0;
virtual void flip(void *source, Format format) = 0;
virtual void blit(void *source, const Rect *sourceRect, const Rect *destRect, Format format) = 0;
virtual void flip(HWND windowOverride, void *source, bool HDR) = 0;
virtual void blit(HWND windowOverride, void *source, const Rect *sourceRect, const Rect *destRect, bool HDR) = 0;
virtual void flip(HWND windowOverride, void *source, Format format) = 0;
virtual void blit(HWND windowOverride, void *source, const Rect *sourceRect, const Rect *destRect, Format format) = 0;
virtual void *lock() = 0;
virtual void unlock() = 0;
......@@ -54,8 +54,8 @@ namespace sw
};
}
extern "C"
{
extern "C"
{
sw::FrameBufferWin *createFrameBufferWin(HWND windowHandle, int width, int height, bool fullscreen, bool topLeftOrigin);
}
......
......@@ -121,9 +121,9 @@ namespace sw
locked = 0;
}
void FrameBufferX11::blit(void *source, const Rect *sourceRect, const Rect *destRect, bool HDR)
void FrameBufferX11::blit(void *source, const Rect *sourceRect, const Rect *destRect, Format format)
{
copy(source, HDR);
copy(source, format);
if(!mit_shm)
{
......
......@@ -32,8 +32,8 @@ namespace sw
~FrameBufferX11();
virtual void flip(void *source, bool HDR) {blit(source, 0, 0, false);};
virtual void blit(void *source, const Rect *sourceRect, const Rect *destRect, bool HDR);
virtual void flip(void *source, Format format) {blit(source, 0, 0, format);};
virtual void blit(void *source, const Rect *sourceRect, const Rect *destRect, Format format);
virtual void *lock();
virtual void unlock();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment