Commit 9705dec5 by Alexis Hetu Committed by Alexis Hétu

Remove old Framebuffer code from Vulkan

Framebuffer related code is being implemented properly in VkSurfaceKHR.cpp and related files, so old OpenGL framebuffer code can be removed to avoid confusion. Bug b/124265819 Change-Id: I08a87c17e8b029c6f82d252e1ff1ef810ab200ae Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/27108Tested-by: 's avatarAlexis Hétu <sugoi@google.com> Reviewed-by: 's avatarNicolas Capens <nicolascapens@google.com> Kokoro-Presubmit: kokoro <noreply+kokoro@google.com>
parent f2878347
......@@ -17,7 +17,6 @@
#include "Clipper.hpp"
#include "Primitive.hpp"
#include "Polygon.hpp"
#include "WSI/FrameBuffer.hpp"
#include "Device/SwiftConfig.hpp"
#include "Reactor/Reactor.hpp"
#include "Pipeline/Constants.hpp"
......
......@@ -173,22 +173,6 @@ copy "$(OutDir)vk_swiftshader.dll" "$(SolutionDir)out\$(Configuration)_$(Platfor
<ClCompile Include="..\System\Timer.cpp" />
<ClCompile Include="..\WSI\VkSurfaceKHR.cpp" />
<ClCompile Include="..\WSI\VkSwapchainKHR.cpp" />
<ClCompile Include="..\WSI\FrameBuffer.cpp" />
<ClCompile Include="..\WSI\FrameBufferAndroid.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\WSI\FrameBufferDD.cpp" />
<ClCompile Include="..\WSI\FrameBufferGDI.cpp" />
<ClCompile Include="..\WSI\FrameBufferOzone.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\WSI\FrameBufferWin.cpp" />
<ClCompile Include="..\WSI\FrameBufferX11.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\WSI\libX11.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
......@@ -289,36 +273,12 @@ copy "$(OutDir)vk_swiftshader.dll" "$(SolutionDir)out\$(Configuration)_$(Platfor
<ClInclude Include="..\System\Types.hpp" />
<ClInclude Include="..\WSI\VkSurfaceKHR.hpp" />
<ClInclude Include="..\WSI\VkSwapchainKHR.hpp" />
<ClInclude Include="..\WSI\FrameBuffer.hpp" />
<ClInclude Include="..\WSI\FrameBufferAndroid.hpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClInclude>
<ClInclude Include="..\WSI\FrameBufferDD.hpp" />
<ClInclude Include="..\WSI\FrameBufferGDI.hpp" />
<ClInclude Include="..\WSI\FrameBufferOSX.hpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClInclude>
<ClInclude Include="..\WSI\FrameBufferOzone.hpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClInclude>
<ClInclude Include="..\WSI\FrameBufferWin.hpp" />
<ClInclude Include="..\WSI\FrameBufferX11.hpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClInclude>
<ClInclude Include="..\WSI\libX11.hpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="..\WSI\FrameBufferOSX.mm">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</None>
<None Include="swiftshader_icd.def" />
</ItemGroup>
<ItemGroup>
......
......@@ -126,27 +126,6 @@
<ClCompile Include="..\Pipeline\Constants.cpp">
<Filter>Source Files\Pipeline</Filter>
</ClCompile>
<ClCompile Include="..\WSI\FrameBuffer.cpp">
<Filter>Source Files\WSI</Filter>
</ClCompile>
<ClCompile Include="..\WSI\FrameBufferAndroid.cpp">
<Filter>Source Files\WSI</Filter>
</ClCompile>
<ClCompile Include="..\WSI\FrameBufferDD.cpp">
<Filter>Source Files\WSI</Filter>
</ClCompile>
<ClCompile Include="..\WSI\FrameBufferGDI.cpp">
<Filter>Source Files\WSI</Filter>
</ClCompile>
<ClCompile Include="..\WSI\FrameBufferOzone.cpp">
<Filter>Source Files\WSI</Filter>
</ClCompile>
<ClCompile Include="..\WSI\FrameBufferWin.cpp">
<Filter>Source Files\WSI</Filter>
</ClCompile>
<ClCompile Include="..\WSI\FrameBufferX11.cpp">
<Filter>Source Files\WSI</Filter>
</ClCompile>
<ClCompile Include="..\WSI\libX11.cpp">
<Filter>Source Files\WSI</Filter>
</ClCompile>
......@@ -446,30 +425,6 @@
<ClInclude Include="..\Device\Blitter.hpp">
<Filter>Header Files\Device</Filter>
</ClInclude>
<ClInclude Include="..\WSI\FrameBuffer.hpp">
<Filter>Header Files\WSI</Filter>
</ClInclude>
<ClInclude Include="..\WSI\FrameBufferAndroid.hpp">
<Filter>Header Files\WSI</Filter>
</ClInclude>
<ClInclude Include="..\WSI\FrameBufferDD.hpp">
<Filter>Header Files\WSI</Filter>
</ClInclude>
<ClInclude Include="..\WSI\FrameBufferGDI.hpp">
<Filter>Header Files\WSI</Filter>
</ClInclude>
<ClInclude Include="..\WSI\FrameBufferOSX.hpp">
<Filter>Header Files\WSI</Filter>
</ClInclude>
<ClInclude Include="..\WSI\FrameBufferOzone.hpp">
<Filter>Header Files\WSI</Filter>
</ClInclude>
<ClInclude Include="..\WSI\FrameBufferWin.hpp">
<Filter>Header Files\WSI</Filter>
</ClInclude>
<ClInclude Include="..\WSI\FrameBufferX11.hpp">
<Filter>Header Files\WSI</Filter>
</ClInclude>
<ClInclude Include="..\WSI\libX11.hpp">
<Filter>Header Files\WSI</Filter>
</ClInclude>
......@@ -564,9 +519,6 @@
</ItemGroup>
<ItemGroup>
<None Include="swiftshader_icd.def" />
<None Include="..\WSI\FrameBufferOSX.mm">
<Filter>Source Files\WSI</Filter>
</None>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="Vulkan.rc">
......
// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef sw_FrameBuffer_hpp
#define sw_FrameBuffer_hpp
#include "Reactor/Reactor.hpp"
#include "Device/Surface.hpp"
#include "System/Thread.hpp"
namespace sw
{
using namespace rr;
class Surface;
struct BlitState
{
int width;
int height;
VkFormat destFormat;
VkFormat sourceFormat;
int destStride;
int sourceStride;
int cursorWidth;
int cursorHeight;
};
class FrameBuffer
{
public:
FrameBuffer(int width, int height, bool fullscreen, bool topLeftOrigin);
virtual ~FrameBuffer() = 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;
static void setCursorImage(sw::Surface *cursor);
static void setCursorOrigin(int x0, int y0);
static void setCursorPosition(int x, int y);
static Routine *copyRoutine(const BlitState &state);
protected:
void copy(sw::Surface *source);
bool windowed;
void *framebuffer; // Native window buffer.
int width;
int height;
int stride;
VkFormat format;
private:
void copyLocked();
static void threadFunction(void *parameters);
void *renderbuffer; // Render target buffer.
struct Cursor
{
void *image;
int x;
int y;
int width;
int height;
int hotspotX;
int hotspotY;
int positionX;
int positionY;
};
static Cursor cursor;
void (*blitFunction)(void *dst, void *src, Cursor *cursor);
Routine *blitRoutine;
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);
Thread *blitThread;
Event syncEvent;
Event blitEvent;
volatile bool terminate;
static bool topLeftOrigin;
};
}
#endif // sw_FrameBuffer_hpp
// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "FrameBufferAndroid.hpp"
#include "System/GrallocAndroid.hpp"
#include <system/window.h>
namespace sw
{
inline int dequeueBuffer(ANativeWindow* window, ANativeWindowBuffer** buffer)
{
#if ANDROID_PLATFORM_SDK_VERSION > 16
return native_window_dequeue_buffer_and_wait(window, buffer);
#else
return window->dequeueBuffer(window, buffer);
#endif
}
inline int queueBuffer(ANativeWindow* window, ANativeWindowBuffer* buffer, int fenceFd)
{
#if ANDROID_PLATFORM_SDK_VERSION > 16
return window->queueBuffer(window, buffer, fenceFd);
#else
return window->queueBuffer(window, buffer);
#endif
}
inline int cancelBuffer(ANativeWindow* window, ANativeWindowBuffer* buffer, int fenceFd)
{
#if ANDROID_PLATFORM_SDK_VERSION > 16
return window->cancelBuffer(window, buffer, fenceFd);
#else
return window->cancelBuffer(window, buffer);
#endif
}
FrameBufferAndroid::FrameBufferAndroid(ANativeWindow* window, int width, int height)
: FrameBuffer(width, height, false, false),
nativeWindow(window), buffer(nullptr)
{
nativeWindow->common.incRef(&nativeWindow->common);
native_window_set_usage(nativeWindow, GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN);
}
FrameBufferAndroid::~FrameBufferAndroid()
{
nativeWindow->common.decRef(&nativeWindow->common);
}
void FrameBufferAndroid::blit(sw::Surface *source, const Rect *sourceRect, const Rect *destRect)
{
copy(source);
if(buffer)
{
if(framebuffer)
{
framebuffer = nullptr;
unlock();
}
queueBuffer(nativeWindow, buffer, -1);
}
}
void *FrameBufferAndroid::lock()
{
if(dequeueBuffer(nativeWindow, &buffer) != 0)
{
return nullptr;
}
if(GrallocModule::getInstance()->lock(buffer->handle,
GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN,
0, 0, buffer->width, buffer->height, &framebuffer) != 0)
{
TRACE("%s failed to lock buffer %p", __FUNCTION__, buffer);
return nullptr;
}
if((buffer->width < width) || (buffer->height < height))
{
TRACE("lock failed: buffer of %dx%d too small for window of %dx%d",
buffer->width, buffer->height, width, height);
return nullptr;
}
switch(buffer->format)
{
case HAL_PIXEL_FORMAT_RGB_565: format = VK_FORMAT_R5G6B5_UNORM_PACK16; break;
case HAL_PIXEL_FORMAT_RGBA_8888: format = VK_FORMAT_R8G8B8A8_UNORM; break;
#if ANDROID_PLATFORM_SDK_VERSION > 16
case HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED: format = FORMAT_X8B8G8R8; break;
#endif
case HAL_PIXEL_FORMAT_RGBX_8888: format = FORMAT_X8B8G8R8; break;
case HAL_PIXEL_FORMAT_BGRA_8888: format = VK_FORMAT_B8G8R8A8_UNORM; break;
case HAL_PIXEL_FORMAT_RGB_888:
// Frame buffers are expected to have 16-bit or 32-bit colors, not 24-bit.
TRACE("Unsupported frame buffer format RGB_888"); ASSERT(false);
format = FORMAT_R8G8B8; // Wrong component order.
break;
default:
TRACE("Unsupported frame buffer format %d", buffer->format); ASSERT(false);
format = VK_FORMAT_UNDEFINED;
break;
}
stride = buffer->stride * Surface::bytes(format);
return framebuffer;
}
void FrameBufferAndroid::unlock()
{
if(!buffer)
{
TRACE("%s: badness unlock with no active buffer", __FUNCTION__);
return;
}
framebuffer = nullptr;
if(GrallocModule::getInstance()->unlock(buffer->handle) != 0)
{
TRACE("%s: badness unlock failed", __FUNCTION__);
}
}
}
sw::FrameBuffer *createFrameBuffer(void *display, ANativeWindow* window, int width, int height)
{
return new sw::FrameBufferAndroid(window, width, height);
}
// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef sw_FrameBufferAndroid_hpp
#define sw_FrameBufferAndroid_hpp
#include "WSI/FrameBuffer.hpp"
#include "System/Debug.hpp"
struct ANativeWindow;
struct ANativeWindowBuffer;
namespace sw
{
class FrameBufferAndroid : public FrameBuffer
{
public:
FrameBufferAndroid(ANativeWindow *window, int width, int height);
~FrameBufferAndroid() 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;
bool setSwapRectangle(int l, int t, int w, int h);
private:
ANativeWindow *nativeWindow;
ANativeWindowBuffer *buffer;
};
}
#endif // sw_FrameBufferAndroid
// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef sw_FrameBufferDD_hpp
#define sw_FrameBufferDD_hpp
#include "FrameBufferWin.hpp"
#include <ddraw.h>
namespace sw
{
class FrameBufferDD : public FrameBufferWin
{
public:
FrameBufferDD(HWND windowHandle, int width, int height, bool fullscreen, bool topLeftOrigin);
~FrameBufferDD() override;
void flip(sw::Surface *source) override;
void blit(sw::Surface *source, const Rect *sourceRect, const Rect *destRect) 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;
void setGammaRamp(GammaRamp *gammaRamp, bool calibrate) override;
void getGammaRamp(GammaRamp *gammaRamp) override;
void screenshot(void *destBuffer) override;
bool getScanline(bool &inVerticalBlank, unsigned int &scanline) override;
void drawText(int x, int y, const char *string, ...);
private:
void initFullscreen();
void initWindowed();
void createSurfaces();
bool readySurfaces();
void updateClipper(HWND windowOverride);
void restoreSurfaces();
void releaseAll();
HMODULE ddraw;
typedef HRESULT (WINAPI *DIRECTDRAWCREATE)( GUID FAR *lpGUID, LPDIRECTDRAW FAR *lplpDD, IUnknown FAR *pUnkOuter );
HRESULT (WINAPI *DirectDrawCreate)( GUID FAR *lpGUID, LPDIRECTDRAW FAR *lplpDD, IUnknown FAR *pUnkOuter );
typedef HRESULT (WINAPI *DIRECTDRAWENUMERATEEXA)( LPDDENUMCALLBACKEXA lpCallback, LPVOID lpContext, DWORD dwFlags);
HRESULT (WINAPI *DirectDrawEnumerateExA)( LPDDENUMCALLBACKEXA lpCallback, LPVOID lpContext, DWORD dwFlags);
IDirectDraw *directDraw;
IDirectDrawSurface *frontBuffer;
IDirectDrawSurface *backBuffer;
};
}
#endif // sw_FrameBufferDD_hpp
// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "FrameBufferGDI.hpp"
#include "System/Debug.hpp"
namespace sw
{
extern bool forceWindowed;
FrameBufferGDI::FrameBufferGDI(HWND windowHandle, int width, int height, bool fullscreen, bool topLeftOrigin) : FrameBufferWin(windowHandle, width, height, fullscreen, topLeftOrigin)
{
if(!windowed)
{
SetWindowPos(windowHandle, HWND_TOPMOST, 0, 0, width, height, SWP_SHOWWINDOW);
DEVMODE deviceMode;
deviceMode.dmSize = sizeof(DEVMODE);
deviceMode.dmPelsWidth= width;
deviceMode.dmPelsHeight = height;
deviceMode.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT;
ChangeDisplaySettings(&deviceMode, CDS_FULLSCREEN);
}
init(this->windowHandle);
format = VK_FORMAT_B8G8R8A8_UNORM;
}
FrameBufferGDI::~FrameBufferGDI()
{
release();
if(!windowed)
{
ChangeDisplaySettings(0, 0);
RECT clientRect;
RECT windowRect;
GetClientRect(windowHandle, &clientRect);
GetWindowRect(windowHandle, &windowRect);
int windowWidth = width + (windowRect.right - windowRect.left) - (clientRect.right - clientRect.left);
int windowHeight = height + (windowRect.bottom - windowRect.top) - (clientRect.bottom - clientRect.top);
int desktopWidth = GetSystemMetrics(SM_CXSCREEN);
int desktopHeight = GetSystemMetrics(SM_CYSCREEN);
SetWindowPos(windowHandle, HWND_TOP, desktopWidth / 2 - windowWidth / 2, desktopHeight / 2 - windowHeight / 2, windowWidth, windowHeight, SWP_SHOWWINDOW);
}
}
void *FrameBufferGDI::lock()
{
stride = width * 4;
return framebuffer;
}
void FrameBufferGDI::unlock()
{
}
void FrameBufferGDI::flip(sw::Surface *source)
{
blit(source, nullptr, nullptr);
}
void FrameBufferGDI::blit(sw::Surface *source, const Rect *sourceRect, const Rect *destRect)
{
copy(source);
int sourceLeft = sourceRect ? sourceRect->x0 : 0;
int sourceTop = sourceRect ? sourceRect->y0 : 0;
int sourceWidth = sourceRect ? sourceRect->x1 - sourceRect->x0 : width;
int sourceHeight = sourceRect ? sourceRect->y1 - sourceRect->y0 : height;
int destLeft = destRect ? destRect->x0 : 0;
int destTop = destRect ? destRect->y0 : 0;
int destWidth = destRect ? destRect->x1 - destRect->x0 : bounds.right - bounds.left;
int destHeight = destRect ? destRect->y1 - destRect->y0 : bounds.bottom - bounds.top;
StretchBlt(windowContext, destLeft, destTop, destWidth, destHeight, bitmapContext, sourceLeft, sourceTop, sourceWidth, sourceHeight, SRCCOPY);
}
void FrameBufferGDI::flip(HWND windowOverride, sw::Surface *source)
{
blit(windowOverride, source, nullptr, nullptr);
}
void FrameBufferGDI::blit(HWND windowOverride, sw::Surface *source, const Rect *sourceRect, const Rect *destRect)
{
if(windowed && windowOverride != 0 && windowOverride != bitmapWindow)
{
release();
init(windowOverride);
}
blit(source, sourceRect, destRect);
}
void FrameBufferGDI::setGammaRamp(GammaRamp *gammaRamp, bool calibrate)
{
SetDeviceGammaRamp(windowContext, gammaRamp);
}
void FrameBufferGDI::getGammaRamp(GammaRamp *gammaRamp)
{
GetDeviceGammaRamp(windowContext, gammaRamp);
}
void FrameBufferGDI::screenshot(void *destBuffer)
{
UNIMPLEMENTED();
}
bool FrameBufferGDI::getScanline(bool &inVerticalBlank, unsigned int &scanline)
{
UNIMPLEMENTED();
return false;
}
void FrameBufferGDI::init(HWND window)
{
bitmapWindow = window;
windowContext = GetDC(window);
bitmapContext = CreateCompatibleDC(windowContext);
BITMAPINFO bitmapInfo;
memset(&bitmapInfo, 0, sizeof(BITMAPINFO));
bitmapInfo.bmiHeader.biSize = sizeof(BITMAPINFO);
bitmapInfo.bmiHeader.biBitCount = 32;
bitmapInfo.bmiHeader.biPlanes = 1;
bitmapInfo.bmiHeader.biHeight = -height;
bitmapInfo.bmiHeader.biWidth = width;
bitmapInfo.bmiHeader.biCompression = BI_RGB;
bitmap = CreateDIBSection(bitmapContext, &bitmapInfo, DIB_RGB_COLORS, &framebuffer, 0, 0);
SelectObject(bitmapContext, bitmap);
updateBounds(window);
}
void FrameBufferGDI::release()
{
SelectObject(bitmapContext, 0);
DeleteObject(bitmap);
ReleaseDC(bitmapWindow, windowContext);
DeleteDC(bitmapContext);
}
}
// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef sw_FrameBufferGDI_hpp
#define sw_FrameBufferGDI_hpp
#include "FrameBufferWin.hpp"
namespace sw
{
class FrameBufferGDI : public FrameBufferWin
{
public:
FrameBufferGDI(HWND windowHandle, int width, int height, bool fullscreen, bool topLeftOrigin);
~FrameBufferGDI() override;
void flip(sw::Surface *source) override;
void blit(sw::Surface *source, const Rect *sourceRect, const Rect *destRect) 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;
void setGammaRamp(GammaRamp *gammaRamp, bool calibrate) override;
void getGammaRamp(GammaRamp *gammaRamp) override;
void screenshot(void *destBuffer) override;
bool getScanline(bool &inVerticalBlank, unsigned int &scanline) override;
private:
void init(HWND bitmapWindow);
void release();
HDC windowContext;
HDC bitmapContext;
HWND bitmapWindow;
HBITMAP bitmap;
};
}
#endif // sw_FrameBufferGDI_hpp
// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef sw_FrameBufferOSX_hpp
#define sw_FrameBufferOSX_hpp
#include "WSI/FrameBuffer.hpp"
#import <Cocoa/Cocoa.h>
@class CALayer;
namespace sw
{
class FrameBufferOSX : public FrameBuffer
{
public:
FrameBufferOSX(CALayer *layer, int width, int height);
~FrameBufferOSX() 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;
private:
int width;
int height;
CALayer *layer;
uint8_t *buffer;
CGDataProviderRef provider;
CGColorSpaceRef colorspace;
CGImageRef currentImage;
};
}
#endif // sw_FrameBufferOSX
// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "FrameBufferOSX.hpp"
#include "System/Debug.hpp"
#include <EGL/egl.h>
#import <QuartzCore/QuartzCore.h>
namespace sw {
FrameBufferOSX::FrameBufferOSX(CALayer* layer, int width, int height)
: FrameBuffer(width, height, false, false), width(width), height(height),
layer(layer), buffer(nullptr), provider(nullptr), currentImage(nullptr)
{
format = sw::FORMAT_X8B8G8R8;
int bufferSize = width * height * 4 * sizeof(uint8_t);
buffer = new uint8_t[bufferSize];
provider = CGDataProviderCreateWithData(nullptr, buffer, bufferSize, nullptr);
colorspace = CGColorSpaceCreateDeviceRGB();
}
FrameBufferOSX::~FrameBufferOSX()
{
//[CATransaction begin];
//[layer setContents:nullptr];
//[CATransaction commit];
CGImageRelease(currentImage);
CGColorSpaceRelease(colorspace);
CGDataProviderRelease(provider);
delete[] buffer;
}
void FrameBufferOSX::flip(sw::Surface *source)
{
blit(source, nullptr, nullptr);
}
void FrameBufferOSX::blit(sw::Surface *source, const Rect *sourceRect, const Rect *destRect)
{
copy(source);
int bytesPerRow = width * 4 * sizeof(uint8_t);
CGImageRef image = CGImageCreate(width, height, 8, 32, bytesPerRow, colorspace, kCGBitmapByteOrder32Big, provider, nullptr, false, kCGRenderingIntentDefault);
[CATransaction begin];
[layer setContents:(id)image];
[CATransaction commit];
[CATransaction flush];
if(currentImage)
{
CGImageRelease(currentImage);
}
currentImage = image;
}
void *FrameBufferOSX::lock()
{
stride = width * 4 * sizeof(uint8_t);
framebuffer = buffer;
return framebuffer;
};
void FrameBufferOSX::unlock()
{
framebuffer = nullptr;
};
}
sw::FrameBuffer *createFrameBuffer(void *display, EGLNativeWindowType nativeWindow, int width, int height)
{
NSObject *window = reinterpret_cast<NSObject*>(nativeWindow);
CALayer *layer = nullptr;
if([window isKindOfClass:[NSView class]])
{
NSView *view = reinterpret_cast<NSView*>(window);
[view setWantsLayer:YES];
layer = [view layer];
}
else if([window isKindOfClass:[CALayer class]])
{
layer = reinterpret_cast<CALayer*>(window);
}
else ASSERT(0);
return new sw::FrameBufferOSX(layer, width, height);
}
// Copyright 2017 The SwiftShader Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "FrameBufferOzone.hpp"
namespace sw
{
FrameBufferOzone::FrameBufferOzone(intptr_t display, intptr_t window, int width, int height) : FrameBuffer(width, height, false, false)
{
buffer = sw::Surface::create(width, height, 1, format, nullptr,
sw::Surface::pitchB(width, 0, format, true),
sw::Surface::sliceB(width, height, 0, format, true));
}
FrameBufferOzone::~FrameBufferOzone()
{
delete buffer;
}
void *FrameBufferOzone::lock()
{
framebuffer = buffer->lockInternal(0, 0, 0, sw::LOCK_READWRITE, sw::PUBLIC);
return framebuffer;
}
void FrameBufferOzone::unlock()
{
buffer->unlockInternal();
framebuffer = nullptr;
}
void FrameBufferOzone::blit(sw::Surface *source, const Rect *sourceRect, const Rect *destRect)
{
copy(source);
}
}
NO_SANITIZE_FUNCTION sw::FrameBuffer *createFrameBuffer(void* display, intptr_t window, int width, int height)
{
return new sw::FrameBufferOzone((intptr_t)display, window, width, height);
}
// Copyright 2017 The SwiftShader Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef sw_FrameBufferOzone_hpp
#define sw_FrameBufferOzone_hpp
#include "WSI/FrameBuffer.hpp"
namespace sw
{
class FrameBufferOzone : public FrameBuffer
{
public:
FrameBufferOzone(intptr_t display, intptr_t window, int width, int height);
~FrameBufferOzone() 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;
private:
sw::Surface* buffer;
};
}
#endif // sw_FrameBufferOzone_hpp
// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "FrameBufferWin.hpp"
namespace sw
{
FrameBufferWin::FrameBufferWin(HWND windowHandle, int width, int height, bool fullscreen, bool topLeftOrigin) : FrameBuffer(width, height, fullscreen, topLeftOrigin), windowHandle(windowHandle)
{
if(!windowed)
{
// Force fullscreen window style (no borders)
originalWindowStyle = GetWindowLong(windowHandle, GWL_STYLE);
SetWindowLong(windowHandle, GWL_STYLE, WS_POPUP);
}
}
FrameBufferWin::~FrameBufferWin()
{
if(!windowed && GetWindowLong(windowHandle, GWL_STYLE) == WS_POPUP)
{
SetWindowLong(windowHandle, GWL_STYLE, originalWindowStyle);
}
}
void FrameBufferWin::updateBounds(HWND windowOverride)
{
HWND window = windowOverride ? windowOverride : windowHandle;
if(windowed)
{
GetClientRect(window, &bounds);
ClientToScreen(window, (POINT*)&bounds);
ClientToScreen(window, (POINT*)&bounds + 1);
}
else
{
SetRect(&bounds, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN));
}
}
}
#include "FrameBufferDD.hpp"
#include "FrameBufferGDI.hpp"
#include "System/Configurator.hpp"
sw::FrameBufferWin *createFrameBufferWin(HWND windowHandle, int width, int height, bool fullscreen, bool topLeftOrigin)
{
sw::Configurator ini("SwiftShader.ini");
int api = ini.getInteger("Testing", "FrameBufferAPI", 0);
if(api == 0 && topLeftOrigin)
{
return new sw::FrameBufferDD(windowHandle, width, height, fullscreen, topLeftOrigin);
}
else
{
return new sw::FrameBufferGDI(windowHandle, width, height, fullscreen, topLeftOrigin);
}
return 0;
}
sw::FrameBuffer *createFrameBuffer(void *display, HWND window, int width, int height)
{
return createFrameBufferWin(window, width, height, false, false);
}
// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef sw_FrameBufferWin_hpp
#define sw_FrameBufferWin_hpp
#include "FrameBuffer.hpp"
namespace sw
{
struct GammaRamp
{
short red[256];
short green[256];
short blue[256];
};
class FrameBufferWin : public FrameBuffer
{
public:
FrameBufferWin(HWND windowHandle, int width, int height, bool fullscreen, bool topLeftOrigin);
~FrameBufferWin() override;
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, 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;
virtual void screenshot(void *destBuffer) = 0;
virtual bool getScanline(bool &inVerticalBlank, unsigned int &scanline) = 0;
protected:
void updateBounds(HWND windowOverride);
HWND windowHandle;
DWORD originalWindowStyle;
RECT bounds;
};
}
sw::FrameBufferWin *createFrameBufferWin(HWND windowHandle, int width, int height, bool fullscreen, bool topLeftOrigin);
#endif // sw_FrameBufferWin_hpp
// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "FrameBufferX11.hpp"
#include "libX11.hpp"
#include "System/Timer.hpp"
#include <sys/ipc.h>
#include <sys/shm.h>
#include <string.h>
#include <assert.h>
#include <stdlib.h>
namespace sw
{
static int (*PreviousXErrorHandler)(Display *display, XErrorEvent *event) = 0;
static bool shmBadAccess = false;
// Catches BadAcces errors so we can fall back to not using MIT-SHM
static int XShmErrorHandler(Display *display, XErrorEvent *event)
{
if(event->error_code == BadAccess)
{
shmBadAccess = true;
return 0;
}
else
{
return PreviousXErrorHandler(display, event);
}
}
FrameBufferX11::FrameBufferX11(Display *display, Window window, int width, int height) : FrameBuffer(width, height, false, false), ownX11(!display), x_display(display), x_window(window)
{
if(!x_display)
{
x_display = libX11->XOpenDisplay(0);
assert(x_display);
}
int screen = DefaultScreen(x_display);
x_gc = libX11->XDefaultGC(x_display, screen);
int depth = libX11->XDefaultDepth(x_display, screen);
XVisualInfo x_visual;
Status status = libX11->XMatchVisualInfo(x_display, screen, 32, TrueColor, &x_visual);
bool match = (status != 0 && x_visual.blue_mask == 0xFF); // Prefer X8R8G8B8
Visual *visual = match ? x_visual.visual : libX11->XDefaultVisual(x_display, screen);
mit_shm = (libX11->XShmQueryExtension && libX11->XShmQueryExtension(x_display) == True);
if(mit_shm)
{
x_image = libX11->XShmCreateImage(x_display, visual, depth, ZPixmap, 0, &shminfo, width, height);
shminfo.shmid = shmget(IPC_PRIVATE, x_image->bytes_per_line * x_image->height, IPC_CREAT | SHM_R | SHM_W);
shminfo.shmaddr = x_image->data = (char*)shmat(shminfo.shmid, 0, 0);
shminfo.readOnly = False;
PreviousXErrorHandler = libX11->XSetErrorHandler(XShmErrorHandler);
libX11->XShmAttach(x_display, &shminfo); // May produce a BadAccess error
libX11->XSync(x_display, False);
libX11->XSetErrorHandler(PreviousXErrorHandler);
if(shmBadAccess)
{
mit_shm = false;
XDestroyImage(x_image);
shmdt(shminfo.shmaddr);
shmctl(shminfo.shmid, IPC_RMID, 0);
shmBadAccess = false;
}
}
if(!mit_shm)
{
int bytes_per_line = width * 4;
int bytes_per_image = height * bytes_per_line;
char *buffer = (char*)malloc(bytes_per_image);
memset(buffer, 0, bytes_per_image);
x_image = libX11->XCreateImage(x_display, visual, depth, ZPixmap, 0, buffer, width, height, 32, bytes_per_line);
assert(x_image);
if(!x_image)
{
free(buffer);
}
}
}
FrameBufferX11::~FrameBufferX11()
{
if(!mit_shm)
{
XDestroyImage(x_image);
}
else
{
libX11->XShmDetach(x_display, &shminfo);
XDestroyImage(x_image);
shmdt(shminfo.shmaddr);
shmctl(shminfo.shmid, IPC_RMID, 0);
}
if(ownX11)
{
libX11->XCloseDisplay(x_display);
}
}
void *FrameBufferX11::lock()
{
if(x_image)
{
stride = x_image->bytes_per_line;
framebuffer = x_image->data;
}
return framebuffer;
}
void FrameBufferX11::unlock()
{
framebuffer = nullptr;
}
void FrameBufferX11::blit(sw::Surface *source, const Rect *sourceRect, const Rect *destRect)
{
copy(source);
if(!mit_shm)
{
libX11->XPutImage(x_display, x_window, x_gc, x_image, 0, 0, 0, 0, width, height);
}
else
{
libX11->XShmPutImage(x_display, x_window, x_gc, x_image, 0, 0, 0, 0, width, height, False);
}
libX11->XSync(x_display, False);
if(false) // Draw the framerate on screen
{
static double fpsTime = sw::Timer::seconds();
static int frames = -1;
double time = sw::Timer::seconds();
double delta = time - fpsTime;
frames++;
static double FPS = 0.0;
static double maxFPS = 0.0;
if(delta > 1.0)
{
FPS = frames / delta;
fpsTime = time;
frames = 0;
if(FPS > maxFPS)
{
maxFPS = FPS;
}
}
char string[256];
sprintf(string, "FPS: %.2f (max: %.2f)", FPS, maxFPS);
libX11->XDrawString(x_display, x_window, x_gc, 50, 50, string, strlen(string));
}
}
}
NO_SANITIZE_FUNCTION sw::FrameBuffer *createFrameBuffer(void *display, Window window, int width, int height)
{
return new sw::FrameBufferX11((::Display*)display, window, width, height);
}
// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef sw_FrameBufferX11_hpp
#define sw_FrameBufferX11_hpp
#include "WSI/FrameBuffer.hpp"
#include "System/Debug.hpp"
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/extensions/XShm.h>
namespace sw
{
class FrameBufferX11 : public FrameBuffer
{
public:
FrameBufferX11(Display *display, Window window, int width, int height);
~FrameBufferX11() 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;
private:
const bool ownX11;
Display *x_display;
const Window x_window;
XImage *x_image = nullptr;
GC x_gc;
bool mit_shm;
XShmSegmentInfo shminfo;
};
}
#endif // sw_FrameBufferX11_hpp
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