Commit e5a9637d by Nicolas Capens Committed by Nicolas Capens

Refactor FrameBuffer state.

This mainly groups the state that is used for generating a new blit routine into a second BlitState structure 'updateState'. It also allowed for the FrameBuffer's own parameters to not have a 'dest' prefix. Also, 'locked' was renamed to 'framebuffer', and 'target' to 'renderbuffer'. Change-Id: I64e26f0b06f9f4419b8ca67e6fbb0dee8272898a Reviewed-on: https://swiftshader-review.googlesource.com/11510Reviewed-by: 's avatarNicolas Capens <nicolascapens@google.com> Reviewed-by: 's avatarAlexis Hétu <sugoi@google.com> Tested-by: 's avatarNicolas Capens <nicolascapens@google.com>
parent 3911efd7
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
#include <cutils/properties.h> #include <cutils/properties.h>
#endif #endif
#define ASYNCHRONOUS_BLIT 0 // FIXME: Currently leads to rare race conditions #define ASYNCHRONOUS_BLIT false // FIXME: Currently leads to rare race conditions
namespace sw namespace sw
{ {
...@@ -40,30 +40,18 @@ namespace sw ...@@ -40,30 +40,18 @@ namespace sw
{ {
this->topLeftOrigin = topLeftOrigin; this->topLeftOrigin = topLeftOrigin;
locked = nullptr; framebuffer = nullptr;
this->width = width; this->width = width;
this->height = height; this->height = height;
destFormat = FORMAT_X8R8G8B8; format = FORMAT_X8R8G8B8;
sourceFormat = FORMAT_X8R8G8B8;
stride = 0; stride = 0;
if(forceWindowed) windowed = !fullscreen || forceWindowed;
{
fullscreen = false;
}
windowed = !fullscreen;
blitFunction = nullptr; blitFunction = nullptr;
blitRoutine = nullptr; blitRoutine = nullptr;
blitState = {};
blitState.width = 0;
blitState.height = 0;
blitState.destFormat = FORMAT_X8R8G8B8;
blitState.sourceFormat = FORMAT_X8R8G8B8;
blitState.cursorWidth = 0;
blitState.cursorHeight = 0;
if(ASYNCHRONOUS_BLIT) if(ASYNCHRONOUS_BLIT)
{ {
...@@ -86,21 +74,6 @@ namespace sw ...@@ -86,21 +74,6 @@ namespace sw
delete blitRoutine; delete blitRoutine;
} }
int FrameBuffer::getWidth() const
{
return width;
}
int FrameBuffer::getHeight() const
{
return height;
}
int FrameBuffer::getStride() const
{
return stride;
}
void FrameBuffer::setCursorImage(sw::Surface *cursorImage) void FrameBuffer::setCursorImage(sw::Surface *cursorImage)
{ {
if(cursorImage) if(cursorImage)
...@@ -130,7 +103,7 @@ namespace sw ...@@ -130,7 +103,7 @@ namespace sw
cursor.positionY = y; cursor.positionY = y;
} }
void FrameBuffer::copy(void *source, Format format, size_t stride) void FrameBuffer::copy(void *source, Format sourceFormat, size_t sourceStride)
{ {
if(!source) if(!source)
{ {
...@@ -142,15 +115,22 @@ namespace sw ...@@ -142,15 +115,22 @@ namespace sw
return; return;
} }
sourceFormat = format; updateState = {};
updateState.width = width;
updateState.height = height;
updateState.destFormat = format;
updateState.sourceFormat = sourceFormat;
updateState.stride = topLeftOrigin ? (int)sourceStride : -(int)sourceStride;
updateState.cursorWidth = cursor.width;
updateState.cursorHeight = cursor.height;
if(topLeftOrigin) if(topLeftOrigin)
{ {
target = source; renderbuffer = source;
} }
else else
{ {
target = (byte*)source + (height - 1) * stride; renderbuffer = (byte*)source + (height - 1) * sourceStride;
} }
cursor.x = cursor.positionX - cursor.hotspotX; cursor.x = cursor.positionX - cursor.hotspotX;
...@@ -173,25 +153,16 @@ namespace sw ...@@ -173,25 +153,16 @@ namespace sw
void FrameBuffer::copyLocked() void FrameBuffer::copyLocked()
{ {
BlitState update = {}; if(memcmp(&blitState, &updateState, sizeof(BlitState)) != 0)
update.width = width;
update.height = height;
update.destFormat = destFormat;
update.sourceFormat = sourceFormat;
update.stride = stride;
update.cursorWidth = cursor.width;
update.cursorHeight = cursor.height;
if(memcmp(&blitState, &update, sizeof(BlitState)) != 0)
{ {
blitState = update; blitState = updateState;
delete blitRoutine; delete blitRoutine;
blitRoutine = copyRoutine(blitState); blitRoutine = copyRoutine(blitState);
blitFunction = (void(*)(void*, void*, Cursor*))blitRoutine->getEntry(); blitFunction = (void(*)(void*, void*, Cursor*))blitRoutine->getEntry();
} }
blitFunction(locked, target, &cursor); blitFunction(framebuffer, renderbuffer, &cursor);
} }
Routine *FrameBuffer::copyRoutine(const BlitState &state) Routine *FrameBuffer::copyRoutine(const BlitState &state)
......
...@@ -41,10 +41,6 @@ namespace sw ...@@ -41,10 +41,6 @@ namespace sw
virtual ~FrameBuffer() = 0; virtual ~FrameBuffer() = 0;
int getWidth() const;
int getHeight() const;
int getStride() const;
virtual void flip(void *source, Format sourceFormat, size_t sourceStride) = 0; virtual void flip(void *source, Format sourceFormat, size_t sourceStride) = 0;
virtual void blit(void *source, const Rect *sourceRect, const Rect *destRect, Format sourceFormat, size_t sourceStride) = 0; virtual void blit(void *source, const Rect *sourceRect, const Rect *destRect, Format sourceFormat, size_t sourceStride) = 0;
...@@ -58,22 +54,22 @@ namespace sw ...@@ -58,22 +54,22 @@ namespace sw
static Routine *copyRoutine(const BlitState &state); static Routine *copyRoutine(const BlitState &state);
protected: protected:
void copy(void *source, Format format, size_t stride); void copy(void *source, Format sourceFormat, size_t sourceStride);
bool windowed;
void *framebuffer; // Native window buffer.
int width; int width;
int height; int height;
Format sourceFormat;
Format destFormat;
int stride; int stride;
bool windowed; Format format;
void *locked; // Video memory back buffer
private: private:
void copyLocked(); void copyLocked();
static void threadFunction(void *parameters); static void threadFunction(void *parameters);
void *target; // Render target buffer void *renderbuffer; // Render target buffer.
struct Cursor struct Cursor
{ {
...@@ -92,7 +88,8 @@ namespace sw ...@@ -92,7 +88,8 @@ namespace sw
void (*blitFunction)(void *dst, void *src, Cursor *cursor); void (*blitFunction)(void *dst, void *src, Cursor *cursor);
Routine *blitRoutine; Routine *blitRoutine;
BlitState blitState; BlitState blitState; // State of the current blitRoutine.
BlitState updateState; // State of the routine to be generated.
static void blend(const BlitState &state, const Pointer<Byte> &d, const Pointer<Byte> &s, const Pointer<Byte> &c); static void blend(const BlitState &state, const Pointer<Byte> &d, const Pointer<Byte> &s, const Pointer<Byte> &c);
......
...@@ -67,9 +67,9 @@ namespace sw ...@@ -67,9 +67,9 @@ namespace sw
if(buffer) if(buffer)
{ {
if(locked) if(framebuffer)
{ {
locked = nullptr; framebuffer = nullptr;
unlock(); unlock();
} }
...@@ -86,7 +86,7 @@ namespace sw ...@@ -86,7 +86,7 @@ namespace sw
if(GrallocModule::getInstance()->lock(buffer->handle, if(GrallocModule::getInstance()->lock(buffer->handle,
GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN, GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN,
0, 0, buffer->width, buffer->height, &locked) != 0) 0, 0, buffer->width, buffer->height, &framebuffer) != 0)
{ {
ALOGE("%s failed to lock buffer %p", __FUNCTION__, buffer); ALOGE("%s failed to lock buffer %p", __FUNCTION__, buffer);
return nullptr; return nullptr;
...@@ -101,26 +101,26 @@ namespace sw ...@@ -101,26 +101,26 @@ namespace sw
switch(buffer->format) switch(buffer->format)
{ {
case HAL_PIXEL_FORMAT_RGB_565: destFormat = FORMAT_R5G6B5; break; case HAL_PIXEL_FORMAT_RGB_565: format = FORMAT_R5G6B5; break;
case HAL_PIXEL_FORMAT_RGBA_8888: destFormat = FORMAT_A8B8G8R8; break; case HAL_PIXEL_FORMAT_RGBA_8888: format = FORMAT_A8B8G8R8; break;
#if ANDROID_PLATFORM_SDK_VERSION > 16 #if ANDROID_PLATFORM_SDK_VERSION > 16
case HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED: destFormat = FORMAT_X8B8G8R8; break; case HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED: format = FORMAT_X8B8G8R8; break;
#endif #endif
case HAL_PIXEL_FORMAT_RGBX_8888: destFormat = FORMAT_X8B8G8R8; break; case HAL_PIXEL_FORMAT_RGBX_8888: format = FORMAT_X8B8G8R8; break;
case HAL_PIXEL_FORMAT_BGRA_8888: destFormat = FORMAT_A8R8G8B8; break; case HAL_PIXEL_FORMAT_BGRA_8888: format = FORMAT_A8R8G8B8; break;
case HAL_PIXEL_FORMAT_RGB_888: case HAL_PIXEL_FORMAT_RGB_888:
// Frame buffers are expected to have 16-bit or 32-bit colors, not 24-bit. // Frame buffers are expected to have 16-bit or 32-bit colors, not 24-bit.
ALOGE("Unsupported frame buffer format RGB_888"); ASSERT(false); ALOGE("Unsupported frame buffer format RGB_888"); ASSERT(false);
destFormat = FORMAT_R8G8B8; // Wrong component order. format = FORMAT_R8G8B8; // Wrong component order.
break; break;
default: default:
ALOGE("Unsupported frame buffer format %d", buffer->format); ASSERT(false); ALOGE("Unsupported frame buffer format %d", buffer->format); ASSERT(false);
destFormat = FORMAT_NULL; format = FORMAT_NULL;
break; break;
} }
stride = buffer->stride * Surface::bytes(destFormat); stride = buffer->stride * Surface::bytes(format);
return locked; return framebuffer;
} }
void FrameBufferAndroid::unlock() void FrameBufferAndroid::unlock()
...@@ -131,7 +131,7 @@ namespace sw ...@@ -131,7 +131,7 @@ namespace sw
return; return;
} }
locked = nullptr; framebuffer = nullptr;
if(GrallocModule::getInstance()->unlock(buffer->handle) != 0) if(GrallocModule::getInstance()->unlock(buffer->handle) != 0)
{ {
......
...@@ -38,7 +38,7 @@ namespace sw ...@@ -38,7 +38,7 @@ namespace sw
frontBuffer = 0; frontBuffer = 0;
backBuffer = 0; backBuffer = 0;
locked = 0; framebuffer = nullptr;
ddraw = LoadLibrary("ddraw.dll"); ddraw = LoadLibrary("ddraw.dll");
DirectDrawCreate = (DIRECTDRAWCREATE)GetProcAddress(ddraw, "DirectDrawCreate"); DirectDrawCreate = (DIRECTDRAWCREATE)GetProcAddress(ddraw, "DirectDrawCreate");
...@@ -106,13 +106,13 @@ namespace sw ...@@ -106,13 +106,13 @@ namespace sw
switch(ddsd.ddpfPixelFormat.dwRGBBitCount) switch(ddsd.ddpfPixelFormat.dwRGBBitCount)
{ {
case 32: destFormat = FORMAT_X8R8G8B8; break; case 32: format = FORMAT_X8R8G8B8; break;
case 24: destFormat = FORMAT_R8G8B8; break; case 24: format = FORMAT_R8G8B8; break;
case 16: destFormat = FORMAT_R5G6B5; break; case 16: format = FORMAT_R5G6B5; break;
default: destFormat = FORMAT_NULL; break; default: format = FORMAT_NULL; break;
} }
if((result != DD_OK && result != DDERR_PRIMARYSURFACEALREADYEXISTS) || (destFormat == FORMAT_NULL)) if((result != DD_OK && result != DDERR_PRIMARYSURFACEALREADYEXISTS) || (format == FORMAT_NULL))
{ {
assert(!"Failed to initialize graphics: Incompatible display mode."); assert(!"Failed to initialize graphics: Incompatible display mode.");
} }
...@@ -206,17 +206,17 @@ namespace sw ...@@ -206,17 +206,17 @@ namespace sw
do do
{ {
destFormat = FORMAT_X8R8G8B8; format = FORMAT_X8R8G8B8;
result = directDraw->SetDisplayMode(width, height, 32); result = directDraw->SetDisplayMode(width, height, 32);
if(result == DDERR_INVALIDMODE) if(result == DDERR_INVALIDMODE)
{ {
destFormat = FORMAT_R8G8B8; format = FORMAT_R8G8B8;
result = directDraw->SetDisplayMode(width, height, 24); result = directDraw->SetDisplayMode(width, height, 24);
if(result == DDERR_INVALIDMODE) if(result == DDERR_INVALIDMODE)
{ {
destFormat = FORMAT_R5G6B5; format = FORMAT_R5G6B5;
result = directDraw->SetDisplayMode(width, height, 16); result = directDraw->SetDisplayMode(width, height, 16);
if(result == DDERR_INVALIDMODE) if(result == DDERR_INVALIDMODE)
...@@ -404,14 +404,14 @@ namespace sw ...@@ -404,14 +404,14 @@ namespace sw
void *FrameBufferDD::lock() void *FrameBufferDD::lock()
{ {
if(locked) if(framebuffer)
{ {
return locked; return framebuffer;
} }
if(!readySurfaces()) if(!readySurfaces())
{ {
return 0; return nullptr;
} }
DDSURFACEDESC DDSD; DDSURFACEDESC DDSD;
...@@ -425,21 +425,21 @@ namespace sw ...@@ -425,21 +425,21 @@ namespace sw
height = DDSD.dwHeight; height = DDSD.dwHeight;
stride = DDSD.lPitch; stride = DDSD.lPitch;
locked = DDSD.lpSurface; framebuffer = DDSD.lpSurface;
return locked; return framebuffer;
} }
return 0; return nullptr;
} }
void FrameBufferDD::unlock() void FrameBufferDD::unlock()
{ {
if(!locked || !backBuffer) return; if(!framebuffer || !backBuffer) return;
backBuffer->Unlock(0); backBuffer->Unlock(0);
locked = 0; framebuffer = nullptr;
} }
void FrameBufferDD::drawText(int x, int y, const char *string, ...) void FrameBufferDD::drawText(int x, int y, const char *string, ...)
......
...@@ -37,7 +37,7 @@ namespace sw ...@@ -37,7 +37,7 @@ namespace sw
init(this->windowHandle); init(this->windowHandle);
destFormat = FORMAT_X8R8G8B8; format = FORMAT_X8R8G8B8;
} }
FrameBufferGDI::~FrameBufferGDI() FrameBufferGDI::~FrameBufferGDI()
...@@ -64,7 +64,7 @@ namespace sw ...@@ -64,7 +64,7 @@ namespace sw
{ {
stride = width * 4; stride = width * 4;
return locked; return framebuffer;
} }
void FrameBufferGDI::unlock() void FrameBufferGDI::unlock()
...@@ -146,7 +146,7 @@ namespace sw ...@@ -146,7 +146,7 @@ namespace sw
bitmapInfo.bmiHeader.biWidth = width; bitmapInfo.bmiHeader.biWidth = width;
bitmapInfo.bmiHeader.biCompression = BI_RGB; bitmapInfo.bmiHeader.biCompression = BI_RGB;
bitmap = CreateDIBSection(bitmapContext, &bitmapInfo, DIB_RGB_COLORS, &locked, 0, 0); bitmap = CreateDIBSection(bitmapContext, &bitmapInfo, DIB_RGB_COLORS, &framebuffer, 0, 0);
SelectObject(bitmapContext, bitmap); SelectObject(bitmapContext, bitmap);
updateBounds(window); updateBounds(window);
......
...@@ -25,7 +25,7 @@ namespace sw { ...@@ -25,7 +25,7 @@ namespace sw {
: FrameBuffer(width, height, false, false), width(width), height(height), : FrameBuffer(width, height, false, false), width(width), height(height),
layer(layer), buffer(nullptr), provider(nullptr), currentImage(nullptr) layer(layer), buffer(nullptr), provider(nullptr), currentImage(nullptr)
{ {
destFormat = sw::FORMAT_X8B8G8R8; format = sw::FORMAT_X8B8G8R8;
int bufferSize = width * height * 4 * sizeof(uint8_t); int bufferSize = width * height * 4 * sizeof(uint8_t);
buffer = new uint8_t[bufferSize]; buffer = new uint8_t[bufferSize];
provider = CGDataProviderCreateWithData(nullptr, buffer, bufferSize, nullptr); provider = CGDataProviderCreateWithData(nullptr, buffer, bufferSize, nullptr);
...@@ -72,13 +72,13 @@ namespace sw { ...@@ -72,13 +72,13 @@ namespace sw {
void *FrameBufferOSX::lock() void *FrameBufferOSX::lock()
{ {
stride = width * 4 * sizeof(uint8_t); stride = width * 4 * sizeof(uint8_t);
locked = buffer; framebuffer = buffer;
return locked; return framebuffer;
}; };
void FrameBufferOSX::unlock() void FrameBufferOSX::unlock()
{ {
locked = nullptr; framebuffer = nullptr;
}; };
} }
......
...@@ -18,9 +18,9 @@ namespace sw ...@@ -18,9 +18,9 @@ namespace sw
{ {
FrameBufferOzone::FrameBufferOzone(intptr_t display, intptr_t window, int width, int height) : FrameBuffer(width, height, false, false) FrameBufferOzone::FrameBufferOzone(intptr_t display, intptr_t window, int width, int height) : FrameBuffer(width, height, false, false)
{ {
buffer = sw::Surface::create(width, height, 1, destFormat, nullptr, buffer = sw::Surface::create(width, height, 1, format, nullptr,
sw::Surface::pitchB(width, destFormat, true), sw::Surface::pitchB(width, format, true),
sw::Surface::sliceB(width, height, destFormat, true)); sw::Surface::sliceB(width, height, format, true));
} }
FrameBufferOzone::~FrameBufferOzone() FrameBufferOzone::~FrameBufferOzone()
...@@ -30,16 +30,16 @@ namespace sw ...@@ -30,16 +30,16 @@ namespace sw
void *FrameBufferOzone::lock() void *FrameBufferOzone::lock()
{ {
locked = buffer->lockInternal(0, 0, 0, sw::LOCK_READWRITE, sw::PUBLIC); framebuffer = buffer->lockInternal(0, 0, 0, sw::LOCK_READWRITE, sw::PUBLIC);
return locked; return framebuffer;
} }
void FrameBufferOzone::unlock() void FrameBufferOzone::unlock()
{ {
buffer->unlockInternal(); buffer->unlockInternal();
locked = nullptr; framebuffer = nullptr;
} }
void FrameBufferOzone::blit(void *source, const Rect *sourceRect, const Rect *destRect, Format sourceFormat, size_t sourceStride) void FrameBufferOzone::blit(void *source, const Rect *sourceRect, const Rect *destRect, Format sourceFormat, size_t sourceStride)
......
...@@ -120,14 +120,14 @@ namespace sw ...@@ -120,14 +120,14 @@ namespace sw
void *FrameBufferX11::lock() void *FrameBufferX11::lock()
{ {
stride = x_image->bytes_per_line; stride = x_image->bytes_per_line;
locked = buffer; framebuffer = buffer;
return locked; return framebuffer;
} }
void FrameBufferX11::unlock() void FrameBufferX11::unlock()
{ {
locked = nullptr; framebuffer = nullptr;
} }
void FrameBufferX11::blit(void *source, const Rect *sourceRect, const Rect *destRect, Format sourceFormat, size_t sourceStride) void FrameBufferX11::blit(void *source, const Rect *sourceRect, const Rect *destRect, Format sourceFormat, size_t sourceStride)
......
...@@ -33,7 +33,7 @@ namespace gl ...@@ -33,7 +33,7 @@ namespace gl
return texture->getResource(); return texture->getResource();
} }
return 0; return nullptr;
} }
Image::Image(Texture *parentTexture, GLsizei width, GLsizei height, GLenum format, GLenum type) Image::Image(Texture *parentTexture, GLsizei width, GLsizei height, GLenum format, GLenum type)
...@@ -141,7 +141,7 @@ namespace gl ...@@ -141,7 +141,7 @@ namespace gl
void Image::unbind() void Image::unbind()
{ {
parentTexture = 0; parentTexture = nullptr;
release(); release();
} }
......
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