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/4482 Reviewed-by: Nicolas Capens <nicolascapens@google.com> Tested-by: Nicolas Capens <nicolascapens@google.com>
diff --git a/src/Main/FrameBuffer.cpp b/src/Main/FrameBuffer.cpp index ccf9083..82dff46 100644 --- a/src/Main/FrameBuffer.cpp +++ b/src/Main/FrameBuffer.cpp
@@ -103,7 +103,7 @@ 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 @@ 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->lockInternal(0, 0, 0, sw::LOCK_READONLY, sw::PUBLIC); + + if(!topLeftOrigin) { - renderbuffer = source; - } - else - { - renderbuffer = (byte*)source + (height - 1) * sourceStride; + renderbuffer = (byte*)renderbuffer + (height - 1) * sourceStride; } cursor.x = cursor.positionX - cursor.hotspotX; @@ -147,6 +147,7 @@ copyLocked(); } + source->unlockInternal(); unlock(); profiler.nextFrame(); // Assumes every copy() is a full frame
diff --git a/src/Main/FrameBuffer.hpp b/src/Main/FrameBuffer.hpp index fbb2a79..dd539e1 100644 --- a/src/Main/FrameBuffer.hpp +++ b/src/Main/FrameBuffer.hpp
@@ -42,8 +42,8 @@ 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 @@ static Routine *copyRoutine(const BlitState &state); protected: - void copy(void *source, Format sourceFormat, size_t sourceStride); + void copy(sw::Surface *source); bool windowed;
diff --git a/src/Main/FrameBufferAndroid.cpp b/src/Main/FrameBufferAndroid.cpp index 5bac870..9b47171 100644 --- a/src/Main/FrameBufferAndroid.cpp +++ b/src/Main/FrameBufferAndroid.cpp
@@ -61,9 +61,9 @@ 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) {
diff --git a/src/Main/FrameBufferAndroid.hpp b/src/Main/FrameBufferAndroid.hpp index 4400188..b71c32b 100644 --- a/src/Main/FrameBufferAndroid.hpp +++ b/src/Main/FrameBufferAndroid.hpp
@@ -26,12 +26,12 @@ 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 @@ bool setSwapRectangle(int l, int t, int w, int h); private: - ANativeWindow* nativeWindow; - ANativeWindowBuffer* buffer; + ANativeWindow *nativeWindow; + ANativeWindowBuffer *buffer; }; }
diff --git a/src/Main/FrameBufferDD.cpp b/src/Main/FrameBufferDD.cpp index 1f87bdf..46ed89f 100644 --- a/src/Main/FrameBufferDD.cpp +++ b/src/Main/FrameBufferDD.cpp
@@ -250,9 +250,9 @@ 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 @@ } } - 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 @@ } } - 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)
diff --git a/src/Main/FrameBufferDD.hpp b/src/Main/FrameBufferDD.hpp index efe6d68..22d76c9 100644 --- a/src/Main/FrameBufferDD.hpp +++ b/src/Main/FrameBufferDD.hpp
@@ -28,11 +28,11 @@ ~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;
diff --git a/src/Main/FrameBufferGDI.cpp b/src/Main/FrameBufferGDI.cpp index 2668e10..90a469e 100644 --- a/src/Main/FrameBufferGDI.cpp +++ b/src/Main/FrameBufferGDI.cpp
@@ -71,14 +71,14 @@ { } - 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 @@ 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 @@ init(windowOverride); } - blit(source, sourceRect, destRect, sourceFormat, sourceStride); + blit(source, sourceRect, destRect); } void FrameBufferGDI::setGammaRamp(GammaRamp *gammaRamp, bool calibrate)
diff --git a/src/Main/FrameBufferGDI.hpp b/src/Main/FrameBufferGDI.hpp index efe44a9..add2504 100644 --- a/src/Main/FrameBufferGDI.hpp +++ b/src/Main/FrameBufferGDI.hpp
@@ -26,11 +26,11 @@ ~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 @@ HDC windowContext; HDC bitmapContext; HWND bitmapWindow; - + HBITMAP bitmap; }; }
diff --git a/src/Main/FrameBufferOSX.hpp b/src/Main/FrameBufferOSX.hpp index 41f95fe..07f8d63 100644 --- a/src/Main/FrameBufferOSX.hpp +++ b/src/Main/FrameBufferOSX.hpp
@@ -29,8 +29,8 @@ 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;
diff --git a/src/Main/FrameBufferOSX.mm b/src/Main/FrameBufferOSX.mm index c99d11a..6d58ae7 100644 --- a/src/Main/FrameBufferOSX.mm +++ b/src/Main/FrameBufferOSX.mm
@@ -45,14 +45,14 @@ 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);
diff --git a/src/Main/FrameBufferOzone.cpp b/src/Main/FrameBufferOzone.cpp index 3261f30..c551a46 100644 --- a/src/Main/FrameBufferOzone.cpp +++ b/src/Main/FrameBufferOzone.cpp
@@ -42,9 +42,9 @@ 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); } }
diff --git a/src/Main/FrameBufferOzone.hpp b/src/Main/FrameBufferOzone.hpp index 6843926..0dc9f60 100644 --- a/src/Main/FrameBufferOzone.hpp +++ b/src/Main/FrameBufferOzone.hpp
@@ -26,8 +26,8 @@ ~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;
diff --git a/src/Main/FrameBufferWin.hpp b/src/Main/FrameBufferWin.hpp index e302195..15c1e0e 100644 --- a/src/Main/FrameBufferWin.hpp +++ b/src/Main/FrameBufferWin.hpp
@@ -33,11 +33,11 @@ ~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;
diff --git a/src/Main/FrameBufferX11.cpp b/src/Main/FrameBufferX11.cpp index 2e50f42..ca0bb4b 100644 --- a/src/Main/FrameBufferX11.cpp +++ b/src/Main/FrameBufferX11.cpp
@@ -130,9 +130,9 @@ 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) {
diff --git a/src/Main/FrameBufferX11.hpp b/src/Main/FrameBufferX11.hpp index ab0c205..f25487b 100644 --- a/src/Main/FrameBufferX11.hpp +++ b/src/Main/FrameBufferX11.hpp
@@ -31,8 +31,8 @@ ~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;