Commit 241f789c by Nicolas Capens Committed by Nicolas Capens

Refactor FrameBuffer blit/flip source.

Pass a surface to the blit/flip functions, instead of a raw pointer. This puts the FrameBuffer in control of locking and unlocking. Change-Id: I55335b3beef8d7083aae7687bd25392964261bde Reviewed-on: https://swiftshader-review.googlesource.com/4482Reviewed-by: 's avatarNicolas Capens <nicolascapens@google.com> Tested-by: 's avatarNicolas Capens <nicolascapens@google.com>
parent d3206e61
......@@ -81,13 +81,9 @@ namespace D3D8
profiler.nextFrame();
#endif
void *source = backBuffer[0]->lockInternal(0, 0, 0, sw::LOCK_READONLY, sw::PUBLIC); // FIXME: External
sw::Format format = backBuffer[0]->getInternalFormat();
int stride = backBuffer[0]->getInternalPitchB();
if(!sourceRect && !destRect) // FIXME: More cases?
{
frameBuffer->flip(destWindowOverride, source, format, stride);
frameBuffer->flip(destWindowOverride, backBuffer[0]);
}
else // TODO: Check for SWAPEFFECT_COPY
{
......@@ -110,11 +106,9 @@ namespace D3D8
dRect.y1 = destRect->bottom;
}
frameBuffer->blit(destWindowOverride, source, sourceRect ? &sRect : nullptr, destRect ? &dRect : nullptr, format, stride);
frameBuffer->blit(destWindowOverride, backBuffer[0], sourceRect ? &sRect : nullptr, destRect ? &dRect : nullptr);
}
backBuffer[0]->unlockInternal(); // FIXME: External
return D3D_OK;
}
......@@ -133,7 +127,7 @@ namespace D3D8
}
this->backBuffer[index]->AddRef();
*backBuffer = this->backBuffer[index];
*backBuffer = this->backBuffer[index];
return D3D_OK;
}
......@@ -155,7 +149,7 @@ namespace D3D8
device->GetCreationParameters(&creationParameters);
HWND windowHandle = presentParameters->hDeviceWindow ? presentParameters->hDeviceWindow : creationParameters.hFocusWindow;
int width = 0;
int height = 0;
......@@ -222,7 +216,7 @@ namespace D3D8
{
return backBuffer[index]->lockInternal(0, 0, 0, sw::LOCK_READWRITE, sw::PUBLIC); // FIXME: External
}
void Direct3DSwapChain8::unlockBackBuffer(int index)
{
backBuffer[index]->unlockInternal(); // FIXME: External
......
......@@ -149,9 +149,6 @@ namespace D3D9
#endif
HWND window = destWindowOverride ? destWindowOverride : presentParameters.hDeviceWindow;
void *source = backBuffer[0]->lockInternal(0, 0, 0, sw::LOCK_READONLY, sw::PUBLIC); // FIXME: External
sw::Format format = backBuffer[0]->getInternalFormat();
int stride = backBuffer[0]->getInternalPitchB();
POINT point;
GetCursorPos(&point);
......@@ -161,7 +158,7 @@ namespace D3D9
if(!sourceRect && !destRect) // FIXME: More cases?
{
frameBuffer->flip(window, source, format, stride);
frameBuffer->flip(window, backBuffer[0]);
}
else // FIXME: Check for SWAPEFFECT_COPY
{
......@@ -184,11 +181,9 @@ namespace D3D9
dRect.y1 = destRect->bottom;
}
frameBuffer->blit(window, source, sourceRect ? &sRect : nullptr, destRect ? &dRect : nullptr, format, stride);
frameBuffer->blit(window, backBuffer[0], sourceRect ? &sRect : nullptr, destRect ? &dRect : nullptr);
}
backBuffer[0]->unlockInternal(); // FIXME: External
return D3D_OK;
}
......
......@@ -103,7 +103,7 @@ namespace sw
cursor.positionY = y;
}
void FrameBuffer::copy(void *source, Format sourceFormat, size_t sourceStride)
void FrameBuffer::copy(sw::Surface *source)
{
if(!source)
{
......@@ -115,23 +115,23 @@ namespace sw
return;
}
int sourceStride = source->getInternalPitchB();
updateState = {};
updateState.width = width;
updateState.height = height;
updateState.destFormat = format;
updateState.destStride = stride;
updateState.sourceFormat = sourceFormat;
updateState.sourceStride = topLeftOrigin ? (int)sourceStride : -(int)sourceStride;
updateState.sourceFormat = source->getInternalFormat();
updateState.sourceStride = topLeftOrigin ? sourceStride : -sourceStride;
updateState.cursorWidth = cursor.width;
updateState.cursorHeight = cursor.height;
if(topLeftOrigin)
{
renderbuffer = source;
}
else
renderbuffer = source->lockInternal(0, 0, 0, sw::LOCK_READONLY, sw::PUBLIC);
if(!topLeftOrigin)
{
renderbuffer = (byte*)source + (height - 1) * sourceStride;
renderbuffer = (byte*)renderbuffer + (height - 1) * sourceStride;
}
cursor.x = cursor.positionX - cursor.hotspotX;
......@@ -147,6 +147,7 @@ namespace sw
copyLocked();
}
source->unlockInternal();
unlock();
profiler.nextFrame(); // Assumes every copy() is a full frame
......
......@@ -42,8 +42,8 @@ namespace sw
virtual ~FrameBuffer() = 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 flip(sw::Surface *source) = 0;
virtual void blit(sw::Surface *source, const Rect *sourceRect, const Rect *destRect) = 0;
virtual void *lock() = 0;
virtual void unlock() = 0;
......@@ -55,7 +55,7 @@ namespace sw
static Routine *copyRoutine(const BlitState &state);
protected:
void copy(void *source, Format sourceFormat, size_t sourceStride);
void copy(sw::Surface *source);
bool windowed;
......
......@@ -61,9 +61,9 @@ namespace sw
nativeWindow->common.decRef(&nativeWindow->common);
}
void FrameBufferAndroid::blit(void *source, const Rect *sourceRect, const Rect *destRect, Format sourceFormat, size_t sourceStride)
void FrameBufferAndroid::blit(sw::Surface *source, const Rect *sourceRect, const Rect *destRect)
{
copy(source, sourceFormat, sourceStride);
copy(source);
if(buffer)
{
......
......@@ -26,12 +26,12 @@ namespace sw
class FrameBufferAndroid : public FrameBuffer
{
public:
FrameBufferAndroid(ANativeWindow* window, int width, int height);
FrameBufferAndroid(ANativeWindow *window, int width, int height);
~FrameBufferAndroid() override;
void flip(void *source, Format sourceFormat, size_t sourceStride) override {blit(source, 0, 0, sourceFormat, sourceStride);};
void blit(void *source, const Rect *sourceRect, const Rect *destRect, Format sourceFormat, size_t sourceStride) override;
void flip(sw::Surface *source) override {blit(source, nullptr, nullptr);};
void blit(sw::Surface *source, const Rect *sourceRect, const Rect *destRect) override;
void *lock() override;
void unlock() override;
......@@ -39,8 +39,8 @@ namespace sw
bool setSwapRectangle(int l, int t, int w, int h);
private:
ANativeWindow* nativeWindow;
ANativeWindowBuffer* buffer;
ANativeWindow *nativeWindow;
ANativeWindowBuffer *buffer;
};
}
......
......@@ -250,9 +250,9 @@ namespace sw
updateBounds(windowHandle);
}
void FrameBufferDD::flip(void *source, Format sourceFormat, size_t sourceStride)
void FrameBufferDD::flip(sw::Surface *source)
{
copy(source, sourceFormat, sourceStride);
copy(source);
if(!readySurfaces())
{
......@@ -281,9 +281,9 @@ namespace sw
}
}
void FrameBufferDD::blit(void *source, const Rect *sourceRect, const Rect *destRect, Format sourceFormat, size_t sourceStride)
void FrameBufferDD::blit(sw::Surface *source, const Rect *sourceRect, const Rect *destRect)
{
copy(source, sourceFormat, sourceStride);
copy(source);
if(!readySurfaces())
{
......@@ -320,20 +320,20 @@ namespace sw
}
}
void FrameBufferDD::flip(HWND windowOverride, void *source, Format sourceFormat, size_t sourceStride)
void FrameBufferDD::flip(HWND windowOverride, sw::Surface *source)
{
updateClipper(windowOverride);
updateBounds(windowOverride);
flip(source, sourceFormat, sourceStride);
flip(source);
}
void FrameBufferDD::blit(HWND windowOverride, void *source, const Rect *sourceRect, const Rect *destRect, Format sourceFormat, size_t sourceStride)
void FrameBufferDD::blit(HWND windowOverride, sw::Surface *source, const Rect *sourceRect, const Rect *destRect)
{
updateClipper(windowOverride);
updateBounds(windowOverride);
blit(source, sourceRect, destRect, sourceFormat, sourceStride);
blit(source, sourceRect, destRect);
}
void FrameBufferDD::screenshot(void *destBuffer)
......
......@@ -28,11 +28,11 @@ namespace sw
~FrameBufferDD() override;
void flip(void *source, Format sourceFormat, size_t sourceStride) override;
void blit(void *source, const Rect *sourceRect, const Rect *destRect, Format sourceFormat, size_t sourceStride) override;
void flip(sw::Surface *source) override;
void blit(sw::Surface *source, const Rect *sourceRect, const Rect *destRect) override;
void flip(HWND windowOverride, void *source, Format sourceFormat, size_t sourceStride) override;
void blit(HWND windowOverride, void *source, const Rect *sourceRect, const Rect *destRect, Format sourceFormat, size_t sourceStride) override;
void flip(HWND windowOverride, sw::Surface *source) override;
void blit(HWND windowOverride, sw::Surface *source, const Rect *sourceRect, const Rect *destRect) override;
void *lock() override;
void unlock() override;
......
......@@ -71,14 +71,14 @@ namespace sw
{
}
void FrameBufferGDI::flip(void *source, Format sourceFormat, size_t sourceStride)
void FrameBufferGDI::flip(sw::Surface *source)
{
blit(source, 0, 0, sourceFormat, sourceStride);
blit(source, nullptr, nullptr);
}
void FrameBufferGDI::blit(void *source, const Rect *sourceRect, const Rect *destRect, Format sourceFormat, size_t sourceStride)
void FrameBufferGDI::blit(sw::Surface *source, const Rect *sourceRect, const Rect *destRect)
{
copy(source, sourceFormat, sourceStride);
copy(source);
int sourceLeft = sourceRect ? sourceRect->x0 : 0;
int sourceTop = sourceRect ? sourceRect->y0 : 0;
......@@ -92,12 +92,12 @@ namespace sw
StretchBlt(windowContext, destLeft, destTop, destWidth, destHeight, bitmapContext, sourceLeft, sourceTop, sourceWidth, sourceHeight, SRCCOPY);
}
void FrameBufferGDI::flip(HWND windowOverride, void *source, Format sourceFormat, size_t sourceStride)
void FrameBufferGDI::flip(HWND windowOverride, sw::Surface *source)
{
blit(windowOverride, source, 0, 0, sourceFormat, sourceStride);
blit(windowOverride, source, nullptr, nullptr);
}
void FrameBufferGDI::blit(HWND windowOverride, void *source, const Rect *sourceRect, const Rect *destRect, Format sourceFormat, size_t sourceStride)
void FrameBufferGDI::blit(HWND windowOverride, sw::Surface *source, const Rect *sourceRect, const Rect *destRect)
{
if(windowed && windowOverride != 0 && windowOverride != bitmapWindow)
{
......@@ -105,7 +105,7 @@ namespace sw
init(windowOverride);
}
blit(source, sourceRect, destRect, sourceFormat, sourceStride);
blit(source, sourceRect, destRect);
}
void FrameBufferGDI::setGammaRamp(GammaRamp *gammaRamp, bool calibrate)
......
......@@ -26,11 +26,11 @@ namespace sw
~FrameBufferGDI() override;
void flip(void *source, Format sourceFormat, size_t sourceStride) override;
void blit(void *source, const Rect *sourceRect, const Rect *destRect, Format sourceFormat, size_t sourceStride) override;
void flip(sw::Surface *source) override;
void blit(sw::Surface *source, const Rect *sourceRect, const Rect *destRect) override;
void flip(HWND windowOverride, void *source, Format sourceFormat, size_t sourceStride) override;
void blit(HWND windowOverride, void *source, const Rect *sourceRect, const Rect *destRect, Format sourceFormat, size_t sourceStride) override;
void flip(HWND windowOverride, sw::Surface *source) override;
void blit(HWND windowOverride, sw::Surface *source, const Rect *sourceRect, const Rect *destRect) override;
void *lock() override;
void unlock() override;
......@@ -48,7 +48,7 @@ namespace sw
HDC windowContext;
HDC bitmapContext;
HWND bitmapWindow;
HBITMAP bitmap;
};
}
......
......@@ -29,8 +29,8 @@ namespace sw
FrameBufferOSX(CALayer *layer, int width, int height);
~FrameBufferOSX() override;
void flip(void *source, Format sourceFormat, size_t sourceStride) override;
void blit(void *source, const Rect *sourceRect, const Rect *destRect, Format sourceFormat, size_t sourceStride) override;
void flip(sw::Surface *source) override;
void blit(sw::Surface *source, const Rect *sourceRect, const Rect *destRect) override;
void *lock() override;
void unlock() override;
......
......@@ -45,14 +45,14 @@ namespace sw {
delete[] buffer;
}
void FrameBufferOSX::flip(void *source, Format sourceFormat, size_t sourceStride)
void FrameBufferOSX::flip(sw::Surface *source)
{
blit(source, nullptr, nullptr, sourceFormat, sourceStride);
blit(source, nullptr, nullptr);
}
void FrameBufferOSX::blit(void *source, const Rect *sourceRect, const Rect *destRect, Format sourceFormat, size_t sourceStride)
void FrameBufferOSX::blit(sw::Surface *source, const Rect *sourceRect, const Rect *destRect)
{
copy(source, sourceFormat, sourceStride);
copy(source);
int bytesPerRow = width * 4 * sizeof(uint8_t);
CGImageRef image = CGImageCreate(width, height, 8, 32, bytesPerRow, colorspace, kCGBitmapByteOrder32Big, provider, nullptr, false, kCGRenderingIntentDefault);
......
......@@ -42,9 +42,9 @@ namespace sw
framebuffer = nullptr;
}
void FrameBufferOzone::blit(void *source, const Rect *sourceRect, const Rect *destRect, Format sourceFormat, size_t sourceStride)
void FrameBufferOzone::blit(sw::Surface *source, const Rect *sourceRect, const Rect *destRect)
{
copy(source, sourceFormat, sourceStride);
copy(source);
}
}
......
......@@ -26,8 +26,8 @@ namespace sw
~FrameBufferOzone() override;
void flip(void *source, Format sourceFormat, size_t sourceStride) override {blit(source, 0, 0, sourceFormat, sourceStride);};
void blit(void *source, const Rect *sourceRect, const Rect *destRect, Format sourceFormat, size_t sourceStride) override;
void flip(sw::Surface *source) override {blit(source, nullptr, nullptr);};
void blit(sw::Surface *source, const Rect *sourceRect, const Rect *destRect) override;
void *lock() override;
void unlock() override;
......
......@@ -33,11 +33,11 @@ namespace sw
~FrameBufferWin() override;
void flip(void *source, Format sourceFormat, size_t sourceStride) override = 0;
void blit(void *source, const Rect *sourceRect, const Rect *destRect, Format sourceFormat, size_t sourceStride) override = 0;
void flip(sw::Surface *source) override = 0;
void blit(sw::Surface *source, const Rect *sourceRect, const Rect *destRect) override = 0;
virtual void flip(HWND windowOverride, void *source, Format sourceFormat, size_t sourceStride) = 0;
virtual void blit(HWND windowOverride, void *source, const Rect *sourceRect, const Rect *destRect, Format sourceFormat, size_t sourceStride) = 0;
virtual void flip(HWND windowOverride, sw::Surface *source) = 0;
virtual void blit(HWND windowOverride, sw::Surface *source, const Rect *sourceRect, const Rect *destRect) = 0;
virtual void setGammaRamp(GammaRamp *gammaRamp, bool calibrate) = 0;
virtual void getGammaRamp(GammaRamp *gammaRamp) = 0;
......
......@@ -130,9 +130,9 @@ namespace sw
framebuffer = nullptr;
}
void FrameBufferX11::blit(void *source, const Rect *sourceRect, const Rect *destRect, Format sourceFormat, size_t sourceStride)
void FrameBufferX11::blit(sw::Surface *source, const Rect *sourceRect, const Rect *destRect)
{
copy(source, sourceFormat, sourceStride);
copy(source);
if(!mit_shm)
{
......
......@@ -31,8 +31,8 @@ namespace sw
~FrameBufferX11() override;
void flip(void *source, Format sourceFormat, size_t sourceStride) override {blit(source, 0, 0, sourceFormat, sourceStride);};
void blit(void *source, const Rect *sourceRect, const Rect *destRect, Format sourceFormat, size_t sourceStride) override;
void flip(sw::Surface *source) override {blit(source, nullptr, nullptr);};
void blit(sw::Surface *source, const Rect *sourceRect, const Rect *destRect) override;
void *lock() override;
void unlock() override;
......
......@@ -259,9 +259,7 @@ void WindowSurface::swap()
{
if(backBuffer && frameBuffer)
{
void *source = backBuffer->lockInternal(0, 0, 0, sw::LOCK_READONLY, sw::PUBLIC);
frameBuffer->flip(source, backBuffer->sw::Surface::getInternalFormat(), backBuffer->getInternalPitchB());
backBuffer->unlockInternal();
frameBuffer->flip(backBuffer);
checkForResize();
}
......
......@@ -160,9 +160,7 @@ void Surface::swap()
{
if(backBuffer)
{
void *source = backBuffer->lockInternal(0, 0, 0, sw::LOCK_READONLY, sw::PUBLIC);
frameBuffer->flip(source, backBuffer->Surface::getInternalFormat(), backBuffer->getInternalPitchB());
backBuffer->unlockInternal();
frameBuffer->flip(backBuffer);
checkForResize();
}
......
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