#include <cutils/properties.h>
#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
{
{
this->topLeftOrigin = topLeftOrigin;
- locked = nullptr;
+ framebuffer = nullptr;
this->width = width;
this->height = height;
- destFormat = FORMAT_X8R8G8B8;
- sourceFormat = FORMAT_X8R8G8B8;
+ format = FORMAT_X8R8G8B8;
stride = 0;
- if(forceWindowed)
- {
- fullscreen = false;
- }
-
- windowed = !fullscreen;
+ windowed = !fullscreen || forceWindowed;
blitFunction = nullptr;
blitRoutine = nullptr;
-
- blitState.width = 0;
- blitState.height = 0;
- blitState.destFormat = FORMAT_X8R8G8B8;
- blitState.sourceFormat = FORMAT_X8R8G8B8;
- blitState.cursorWidth = 0;
- blitState.cursorHeight = 0;
+ blitState = {};
if(ASYNCHRONOUS_BLIT)
{
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)
{
if(cursorImage)
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)
{
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)
{
- target = source;
+ renderbuffer = source;
}
else
{
- target = (byte*)source + (height - 1) * stride;
+ renderbuffer = (byte*)source + (height - 1) * sourceStride;
}
cursor.x = cursor.positionX - cursor.hotspotX;
void FrameBuffer::copyLocked()
{
- BlitState update = {};
- 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)
+ if(memcmp(&blitState, &updateState, sizeof(BlitState)) != 0)
{
- blitState = update;
+ blitState = updateState;
delete blitRoutine;
blitRoutine = copyRoutine(blitState);
blitFunction = (void(*)(void*, void*, Cursor*))blitRoutine->getEntry();
}
- blitFunction(locked, target, &cursor);
+ blitFunction(framebuffer, renderbuffer, &cursor);
}
Routine *FrameBuffer::copyRoutine(const BlitState &state)
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 blit(void *source, const Rect *sourceRect, const Rect *destRect, Format sourceFormat, size_t sourceStride) = 0;
static Routine *copyRoutine(const BlitState &state);
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 height;
- Format sourceFormat;
- Format destFormat;
int stride;
- bool windowed;
-
- void *locked; // Video memory back buffer
+ Format format;
private:
void copyLocked();
static void threadFunction(void *parameters);
- void *target; // Render target buffer
+ void *renderbuffer; // Render target buffer.
struct Cursor
{
void (*blitFunction)(void *dst, void *src, Cursor *cursor);
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);
if(buffer)
{
- if(locked)
+ if(framebuffer)
{
- locked = nullptr;
+ framebuffer = nullptr;
unlock();
}
if(GrallocModule::getInstance()->lock(buffer->handle,
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);
return nullptr;
switch(buffer->format)
{
- case HAL_PIXEL_FORMAT_RGB_565: destFormat = FORMAT_R5G6B5; break;
- case HAL_PIXEL_FORMAT_RGBA_8888: destFormat = FORMAT_A8B8G8R8; break;
+ case HAL_PIXEL_FORMAT_RGB_565: format = FORMAT_R5G6B5; break;
+ case HAL_PIXEL_FORMAT_RGBA_8888: format = FORMAT_A8B8G8R8; break;
#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
- case HAL_PIXEL_FORMAT_RGBX_8888: destFormat = FORMAT_X8B8G8R8; break;
- case HAL_PIXEL_FORMAT_BGRA_8888: destFormat = FORMAT_A8R8G8B8; break;
+ case HAL_PIXEL_FORMAT_RGBX_8888: format = FORMAT_X8B8G8R8; break;
+ case HAL_PIXEL_FORMAT_BGRA_8888: format = FORMAT_A8R8G8B8; break;
case HAL_PIXEL_FORMAT_RGB_888:
// Frame buffers are expected to have 16-bit or 32-bit colors, not 24-bit.
ALOGE("Unsupported frame buffer format RGB_888"); ASSERT(false);
- destFormat = FORMAT_R8G8B8; // Wrong component order.
+ format = FORMAT_R8G8B8; // Wrong component order.
break;
default:
ALOGE("Unsupported frame buffer format %d", buffer->format); ASSERT(false);
- destFormat = FORMAT_NULL;
+ format = FORMAT_NULL;
break;
}
- stride = buffer->stride * Surface::bytes(destFormat);
- return locked;
+ stride = buffer->stride * Surface::bytes(format);
+ return framebuffer;
}
void FrameBufferAndroid::unlock()
return;
}
- locked = nullptr;
+ framebuffer = nullptr;
if(GrallocModule::getInstance()->unlock(buffer->handle) != 0)
{
frontBuffer = 0;
backBuffer = 0;
- locked = 0;
+ framebuffer = nullptr;
ddraw = LoadLibrary("ddraw.dll");
DirectDrawCreate = (DIRECTDRAWCREATE)GetProcAddress(ddraw, "DirectDrawCreate");
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;
+ case 32: format = FORMAT_X8R8G8B8; break;
+ case 24: format = FORMAT_R8G8B8; break;
+ case 16: format = FORMAT_R5G6B5; 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.");
}
do
{
- destFormat = FORMAT_X8R8G8B8;
+ format = FORMAT_X8R8G8B8;
result = directDraw->SetDisplayMode(width, height, 32);
if(result == DDERR_INVALIDMODE)
{
- destFormat = FORMAT_R8G8B8;
+ format = FORMAT_R8G8B8;
result = directDraw->SetDisplayMode(width, height, 24);
if(result == DDERR_INVALIDMODE)
{
- destFormat = FORMAT_R5G6B5;
+ format = FORMAT_R5G6B5;
result = directDraw->SetDisplayMode(width, height, 16);
if(result == DDERR_INVALIDMODE)
void *FrameBufferDD::lock()
{
- if(locked)
+ if(framebuffer)
{
- return locked;
+ return framebuffer;
}
if(!readySurfaces())
{
- return 0;
+ return nullptr;
}
DDSURFACEDESC DDSD;
height = DDSD.dwHeight;
stride = DDSD.lPitch;
- locked = DDSD.lpSurface;
+ framebuffer = DDSD.lpSurface;
- return locked;
+ return framebuffer;
}
- return 0;
+ return nullptr;
}
void FrameBufferDD::unlock()
{
- if(!locked || !backBuffer) return;
+ if(!framebuffer || !backBuffer) return;
backBuffer->Unlock(0);
- locked = 0;
+ framebuffer = nullptr;
}
void FrameBufferDD::drawText(int x, int y, const char *string, ...)
init(this->windowHandle);
- destFormat = FORMAT_X8R8G8B8;
+ format = FORMAT_X8R8G8B8;
}
FrameBufferGDI::~FrameBufferGDI()
{
stride = width * 4;
- return locked;
+ return framebuffer;
}
void FrameBufferGDI::unlock()
bitmapInfo.bmiHeader.biWidth = width;
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);
updateBounds(window);
: FrameBuffer(width, height, false, false), width(width), height(height),
layer(layer), buffer(nullptr), provider(nullptr), currentImage(nullptr)
{
- destFormat = sw::FORMAT_X8B8G8R8;
+ format = sw::FORMAT_X8B8G8R8;
int bufferSize = width * height * 4 * sizeof(uint8_t);
buffer = new uint8_t[bufferSize];
provider = CGDataProviderCreateWithData(nullptr, buffer, bufferSize, nullptr);
void *FrameBufferOSX::lock()
{
stride = width * 4 * sizeof(uint8_t);
- locked = buffer;
- return locked;
+ framebuffer = buffer;
+ return framebuffer;
};
void FrameBufferOSX::unlock()
{
- locked = nullptr;
+ framebuffer = nullptr;
};
}
{
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,
- sw::Surface::pitchB(width, destFormat, true),
- sw::Surface::sliceB(width, height, destFormat, true));
+ buffer = sw::Surface::create(width, height, 1, format, nullptr,
+ sw::Surface::pitchB(width, format, true),
+ sw::Surface::sliceB(width, height, format, true));
}
FrameBufferOzone::~FrameBufferOzone()
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()
{
buffer->unlockInternal();
- locked = nullptr;
+ framebuffer = nullptr;
}
void FrameBufferOzone::blit(void *source, const Rect *sourceRect, const Rect *destRect, Format sourceFormat, size_t sourceStride)
void *FrameBufferX11::lock()
{
stride = x_image->bytes_per_line;
- locked = buffer;
+ framebuffer = buffer;
- return locked;
+ return framebuffer;
}
void FrameBufferX11::unlock()
{
- locked = nullptr;
+ framebuffer = nullptr;
}
void FrameBufferX11::blit(void *source, const Rect *sourceRect, const Rect *destRect, Format sourceFormat, size_t sourceStride)
return texture->getResource();
}
- return 0;
+ return nullptr;
}
Image::Image(Texture *parentTexture, GLsizei width, GLsizei height, GLenum format, GLenum type)
void Image::unbind()
{
- parentTexture = 0;
+ parentTexture = nullptr;
release();
}