Apply the Apache 2.0 license. Change-Id: I4a7aeefedcd2d891093520d5a10ebefadcddb5be Reviewed-on: https://swiftshader-review.googlesource.com/5320 Reviewed-by: Nicolas Capens <capn@google.com> Tested-by: Nicolas Capens <capn@google.com>
diff --git a/src/Main/Config.cpp b/src/Main/Config.cpp index becea9c..cee01ee 100644 --- a/src/Main/Config.cpp +++ b/src/Main/Config.cpp
@@ -1,13 +1,16 @@ -// SwiftShader Software Renderer +// Copyright 2016 The SwiftShader Authors. All Rights Reserved. // -// Copyright(c) 2005-2011 TransGaming Inc. +// 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 // -// All rights reserved. No part of this software may be copied, distributed, transmitted, -// transcribed, stored in a retrieval system, translated into any human or computer -// language by any means, or disclosed to third parties without the explicit written -// agreement of TransGaming Inc. Without such an agreement, no rights or licenses, express -// or implied, including but not limited to any patent rights, are granted to you. +// 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 "Config.hpp"
diff --git a/src/Main/Config.hpp b/src/Main/Config.hpp index 2ceec37..7150750 100644 --- a/src/Main/Config.hpp +++ b/src/Main/Config.hpp
@@ -1,98 +1,101 @@ -// SwiftShader Software Renderer -// -// Copyright(c) 2005-2011 TransGaming Inc. -// -// All rights reserved. No part of this software may be copied, distributed, transmitted, -// transcribed, stored in a retrieval system, translated into any human or computer -// language by any means, or disclosed to third parties without the explicit written -// agreement of TransGaming Inc. Without such an agreement, no rights or licenses, express -// or implied, including but not limited to any patent rights, are granted to you. -// - -#ifndef sw_Config_hpp -#define sw_Config_hpp - -#include "Common/Types.hpp" - -#define PERF_HUD 0 // Display time spent on vertex, setup and pixel processing for each thread -#define PERF_PROFILE 0 // Profile various pipeline stages and display the timing in SwiftConfig - -#if defined(_WIN32) -#define S3TC_SUPPORT 1 -#else -#define S3TC_SUPPORT 0 -#endif - -// Worker thread count when not set by SwiftConfig -// 0 = process affinity count (recommended) -// 1 = rendering on main thread (no worker threads), useful for debugging -#ifndef DEFAULT_THREAD_COUNT -#define DEFAULT_THREAD_COUNT 0 -#endif - -namespace sw -{ - enum - { - PERF_PIXEL, - PERF_PIPE, - PERF_INTERP, - PERF_SHADER, - PERF_TEX, - PERF_ROP, - - PERF_TIMERS - }; - - struct Profiler - { - Profiler(); - - void reset(); - void nextFrame(); - - int framesSec; - int framesTotal; - double FPS; - - #if PERF_PROFILE - double cycles[PERF_TIMERS]; - - int64_t ropOperations; - int64_t ropOperationsTotal; - int64_t ropOperationsFrame; - - int64_t texOperations; - int64_t texOperationsTotal; - int64_t texOperationsFrame; - - int64_t compressedTex; - int64_t compressedTexTotal; - int64_t compressedTexFrame; - #endif - }; - - extern Profiler profiler; - - enum - { - OUTLINE_RESOLUTION = 4096, // Maximum vertical resolution of the render target - MIPMAP_LEVELS = 14, - VERTEX_ATTRIBUTES = 16, - TEXTURE_IMAGE_UNITS = 16, - VERTEX_TEXTURE_IMAGE_UNITS = 16, - TOTAL_IMAGE_UNITS = TEXTURE_IMAGE_UNITS + VERTEX_TEXTURE_IMAGE_UNITS, - FRAGMENT_UNIFORM_VECTORS = 224, - VERTEX_UNIFORM_VECTORS = 256, - MAX_FRAGMENT_UNIFORM_BLOCKS = 12, - MAX_VERTEX_UNIFORM_BLOCKS = 12, - MAX_UNIFORM_BUFFER_BINDINGS = MAX_FRAGMENT_UNIFORM_BLOCKS + MAX_VERTEX_UNIFORM_BLOCKS, // Limited to 127 by SourceParameter.bufferIndex in Shader.hpp - MAX_UNIFORM_BLOCK_SIZE = 16384, - MAX_CLIP_PLANES = 6, - MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS = 64, - MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS = 64, - RENDERTARGETS = 8, - }; -} - -#endif // sw_Config_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_Config_hpp +#define sw_Config_hpp + +#include "Common/Types.hpp" + +#define PERF_HUD 0 // Display time spent on vertex, setup and pixel processing for each thread +#define PERF_PROFILE 0 // Profile various pipeline stages and display the timing in SwiftConfig + +#if defined(_WIN32) +#define S3TC_SUPPORT 1 +#else +#define S3TC_SUPPORT 0 +#endif + +// Worker thread count when not set by SwiftConfig +// 0 = process affinity count (recommended) +// 1 = rendering on main thread (no worker threads), useful for debugging +#ifndef DEFAULT_THREAD_COUNT +#define DEFAULT_THREAD_COUNT 0 +#endif + +namespace sw +{ + enum + { + PERF_PIXEL, + PERF_PIPE, + PERF_INTERP, + PERF_SHADER, + PERF_TEX, + PERF_ROP, + + PERF_TIMERS + }; + + struct Profiler + { + Profiler(); + + void reset(); + void nextFrame(); + + int framesSec; + int framesTotal; + double FPS; + + #if PERF_PROFILE + double cycles[PERF_TIMERS]; + + int64_t ropOperations; + int64_t ropOperationsTotal; + int64_t ropOperationsFrame; + + int64_t texOperations; + int64_t texOperationsTotal; + int64_t texOperationsFrame; + + int64_t compressedTex; + int64_t compressedTexTotal; + int64_t compressedTexFrame; + #endif + }; + + extern Profiler profiler; + + enum + { + OUTLINE_RESOLUTION = 4096, // Maximum vertical resolution of the render target + MIPMAP_LEVELS = 14, + VERTEX_ATTRIBUTES = 16, + TEXTURE_IMAGE_UNITS = 16, + VERTEX_TEXTURE_IMAGE_UNITS = 16, + TOTAL_IMAGE_UNITS = TEXTURE_IMAGE_UNITS + VERTEX_TEXTURE_IMAGE_UNITS, + FRAGMENT_UNIFORM_VECTORS = 224, + VERTEX_UNIFORM_VECTORS = 256, + MAX_FRAGMENT_UNIFORM_BLOCKS = 12, + MAX_VERTEX_UNIFORM_BLOCKS = 12, + MAX_UNIFORM_BUFFER_BINDINGS = MAX_FRAGMENT_UNIFORM_BLOCKS + MAX_VERTEX_UNIFORM_BLOCKS, // Limited to 127 by SourceParameter.bufferIndex in Shader.hpp + MAX_UNIFORM_BLOCK_SIZE = 16384, + MAX_CLIP_PLANES = 6, + MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS = 64, + MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS = 64, + RENDERTARGETS = 8, + }; +} + +#endif // sw_Config_hpp
diff --git a/src/Main/FrameBuffer.cpp b/src/Main/FrameBuffer.cpp index 0c30646..2ac2a49 100644 --- a/src/Main/FrameBuffer.cpp +++ b/src/Main/FrameBuffer.cpp
@@ -1,13 +1,16 @@ -// SwiftShader Software Renderer +// Copyright 2016 The SwiftShader Authors. All Rights Reserved. // -// Copyright(c) 2005-2012 TransGaming Inc. +// 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 // -// All rights reserved. No part of this software may be copied, distributed, transmitted, -// transcribed, stored in a retrieval system, translated into any human or computer -// language by any means, or disclosed to third parties without the explicit written -// agreement of TransGaming Inc. Without such an agreement, no rights or licenses, express -// or implied, including but not limited to any patent rights, are granted to you. +// 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 "FrameBuffer.hpp"
diff --git a/src/Main/FrameBuffer.hpp b/src/Main/FrameBuffer.hpp index a92dadf..f515b4a 100644 --- a/src/Main/FrameBuffer.hpp +++ b/src/Main/FrameBuffer.hpp
@@ -1,100 +1,103 @@ -// SwiftShader Software Renderer -// -// Copyright(c) 2005-2012 TransGaming Inc. -// -// All rights reserved. No part of this software may be copied, distributed, transmitted, -// transcribed, stored in a retrieval system, translated into any human or computer -// language by any means, or disclosed to third parties without the explicit written -// agreement of TransGaming Inc. Without such an agreement, no rights or licenses, express -// or implied, including but not limited to any patent rights, are granted to you. -// - -#ifndef sw_FrameBuffer_hpp -#define sw_FrameBuffer_hpp - -#include "Reactor/Nucleus.hpp" -#include "Renderer/Surface.hpp" -#include "Common/Thread.hpp" - -namespace sw -{ - class Surface; - - struct BlitState - { - int width; - int height; - Format destFormat; - Format sourceFormat; - int stride; - int cursorWidth; - int cursorHeight; - }; - - class FrameBuffer - { - public: - FrameBuffer(int width, int height, bool fullscreen, bool topLeftOrigin); - - virtual ~FrameBuffer(); - - 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; - - 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(void *source, Format format, size_t stride); - int width; - int height; - Format sourceFormat; - Format destFormat; - int stride; - bool windowed; - - void *locked; // Video memory back buffer - - private: - void copyLocked(); - - static void threadFunction(void *parameters); - - void *target; // Render target buffer - - void (*blitFunction)(void *dst, void *src); - Routine *blitRoutine; - BlitState blitState; - - static void blend(const BlitState &state, const Pointer<Byte> &d, const Pointer<Byte> &s, const Pointer<Byte> &c); - - static void *cursor; - static int cursorWidth; - static int cursorHeight; - static int cursorHotspotX; - static int cursorHotspotY; - static int cursorPositionX; - static int cursorPositionY; - static int cursorX; - static int cursorY; - - 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. + +#ifndef sw_FrameBuffer_hpp +#define sw_FrameBuffer_hpp + +#include "Reactor/Nucleus.hpp" +#include "Renderer/Surface.hpp" +#include "Common/Thread.hpp" + +namespace sw +{ + class Surface; + + struct BlitState + { + int width; + int height; + Format destFormat; + Format sourceFormat; + int stride; + int cursorWidth; + int cursorHeight; + }; + + class FrameBuffer + { + public: + FrameBuffer(int width, int height, bool fullscreen, bool topLeftOrigin); + + virtual ~FrameBuffer(); + + 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; + + 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(void *source, Format format, size_t stride); + int width; + int height; + Format sourceFormat; + Format destFormat; + int stride; + bool windowed; + + void *locked; // Video memory back buffer + + private: + void copyLocked(); + + static void threadFunction(void *parameters); + + void *target; // Render target buffer + + void (*blitFunction)(void *dst, void *src); + Routine *blitRoutine; + BlitState blitState; + + static void blend(const BlitState &state, const Pointer<Byte> &d, const Pointer<Byte> &s, const Pointer<Byte> &c); + + static void *cursor; + static int cursorWidth; + static int cursorHeight; + static int cursorHotspotX; + static int cursorHotspotY; + static int cursorPositionX; + static int cursorPositionY; + static int cursorX; + static int cursorY; + + Thread *blitThread; + Event syncEvent; + Event blitEvent; + volatile bool terminate; + + static bool topLeftOrigin; + }; +} + +#endif // sw_FrameBuffer_hpp
diff --git a/src/Main/FrameBufferAndroid.cpp b/src/Main/FrameBufferAndroid.cpp index 9d20ac6..ed50d13 100644 --- a/src/Main/FrameBufferAndroid.cpp +++ b/src/Main/FrameBufferAndroid.cpp
@@ -31,67 +31,70 @@ #endif } - FrameBufferAndroid::FrameBufferAndroid(ANativeWindow* window, int width, int height) - : FrameBuffer(width, height, false, false), - nativeWindow(window), buffer(0), gralloc(0) - { - hw_module_t const* pModule; - hw_get_module(GRALLOC_HARDWARE_MODULE_ID, &pModule); - gralloc = reinterpret_cast<gralloc_module_t const*>(pModule); + FrameBufferAndroid::FrameBufferAndroid(ANativeWindow* window, int width, int height) + : FrameBuffer(width, height, false, false), + nativeWindow(window), buffer(nullptr), gralloc(nullptr) + { + hw_module_t const* pModule; + hw_get_module(GRALLOC_HARDWARE_MODULE_ID, &pModule); + gralloc = reinterpret_cast<gralloc_module_t const*>(pModule); - nativeWindow->common.incRef(&nativeWindow->common); - native_window_set_usage(nativeWindow, GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN); - } + nativeWindow->common.incRef(&nativeWindow->common); + native_window_set_usage(nativeWindow, GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN); + } - FrameBufferAndroid::~FrameBufferAndroid() - { - if (buffer) - { - // Probably doesn't have to cancel assuming a success queueing earlier - cancelBuffer(nativeWindow, buffer, -1); - buffer = 0; - } - nativeWindow->common.decRef(&nativeWindow->common); - } + FrameBufferAndroid::~FrameBufferAndroid() + { + if(buffer) + { + // Probably doesn't have to cancel assuming a success queueing earlier + cancelBuffer(nativeWindow, buffer, -1); + buffer = nullptr; + } - void FrameBufferAndroid::blit(void *source, const Rect *sourceRect, const Rect *destRect, Format sourceFormat, size_t sourceStride) - { - copy(source, sourceFormat, sourceStride); - if (buffer) + nativeWindow->common.decRef(&nativeWindow->common); + } + + void FrameBufferAndroid::blit(void *source, const Rect *sourceRect, const Rect *destRect, Format sourceFormat, size_t sourceStride) + { + copy(source, sourceFormat, sourceStride); + + if(buffer) { queueBuffer(nativeWindow, buffer, -1); - if (locked) + + if(locked) { - locked = 0; + locked = nullptr; unlock(); } + buffer->common.decRef(&buffer->common); } - } + } - void* FrameBufferAndroid::lock() - { - if (dequeueBuffer(nativeWindow, &buffer) != 0) - { - return NULL; - } + void *FrameBufferAndroid::lock() + { + if(dequeueBuffer(nativeWindow, &buffer) != 0) + { + return nullptr; + } - buffer->common.incRef(&buffer->common); + buffer->common.incRef(&buffer->common); - if (gralloc->lock( - gralloc, buffer->handle, - GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN, - 0, 0, buffer->width, buffer->height, &locked) != 0) - { - ALOGE("%s failed to lock buffer %p", __FUNCTION__, buffer); - return NULL; - } + if(gralloc->lock(gralloc, buffer->handle, + GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN, + 0, 0, buffer->width, buffer->height, &locked) != 0) + { + ALOGE("%s failed to lock buffer %p", __FUNCTION__, buffer); + return nullptr; + } - if ((buffer->width < width) || (buffer->height < height)) + if((buffer->width < width) || (buffer->height < height)) { ALOGI("lock failed: buffer of %dx%d too small for window of %dx%d", buffer->width, buffer->height, width, height); - return NULL; + return nullptr; } switch(buffer->format) @@ -104,26 +107,28 @@ case HAL_PIXEL_FORMAT_BGRA_8888: destFormat = FORMAT_A8R8G8B8; break; } - stride = buffer->stride * Surface::bytes(destFormat); - return locked; - } + stride = buffer->stride * Surface::bytes(destFormat); + return locked; + } - void FrameBufferAndroid::unlock() - { - if (!buffer) + void FrameBufferAndroid::unlock() + { + if(!buffer) { ALOGE("%s: badness unlock with no active buffer", __FUNCTION__); return; } - locked = 0; - if (gralloc->unlock(gralloc, buffer->handle) != 0) + + locked = nullptr; + + if(gralloc->unlock(gralloc, buffer->handle) != 0) { ALOGE("%s: badness unlock failed", __FUNCTION__); } - } + } } sw::FrameBuffer *createFrameBuffer(void *display, ANativeWindow* window, int width, int height) { - return new sw::FrameBufferAndroid(window, width, height); + return new sw::FrameBufferAndroid(window, width, height); }
diff --git a/src/Main/FrameBufferAndroid.hpp b/src/Main/FrameBufferAndroid.hpp index 359cea9..2e567d8 100644 --- a/src/Main/FrameBufferAndroid.hpp +++ b/src/Main/FrameBufferAndroid.hpp
@@ -9,26 +9,26 @@ namespace sw { - class FrameBufferAndroid : public FrameBuffer - { - public: - FrameBufferAndroid(ANativeWindow* window, int width, int height); + class FrameBufferAndroid : public FrameBuffer + { + public: + FrameBufferAndroid(ANativeWindow* window, int width, int height); - ~FrameBufferAndroid(); + ~FrameBufferAndroid(); - void flip(void *source, Format sourceFormat, size_t sourceStride) override {blit(source, 0, 0, sourceFormat, sourceStride);}; + 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 *lock() override; void unlock() override; - bool setSwapRectangle(int l, int t, int w, int h); + bool setSwapRectangle(int l, int t, int w, int h); - private: - ANativeWindow* nativeWindow; - ANativeWindowBuffer* buffer; - gralloc_module_t const* gralloc; - }; + private: + ANativeWindow* nativeWindow; + ANativeWindowBuffer* buffer; + gralloc_module_t const* gralloc; + }; } #endif // sw_FrameBufferAndroid
diff --git a/src/Main/FrameBufferDD.cpp b/src/Main/FrameBufferDD.cpp index 81b2ef2..5fd8dbb 100644 --- a/src/Main/FrameBufferDD.cpp +++ b/src/Main/FrameBufferDD.cpp
@@ -1,13 +1,16 @@ -// SwiftShader Software Renderer +// Copyright 2016 The SwiftShader Authors. All Rights Reserved. // -// Copyright(c) 2005-2012 TransGaming Inc. +// 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 // -// All rights reserved. No part of this software may be copied, distributed, transmitted, -// transcribed, stored in a retrieval system, translated into any human or computer -// language by any means, or disclosed to third parties without the explicit written -// agreement of TransGaming Inc. Without such an agreement, no rights or licenses, express -// or implied, including but not limited to any patent rights, are granted to you. +// 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 "FrameBufferDD.hpp" @@ -92,7 +95,7 @@ else { IDirectDrawClipper *clipper; - + DDSURFACEDESC ddsd = {0}; ddsd.dwSize = sizeof(ddsd); ddsd.dwFlags = DDSD_CAPS; @@ -100,7 +103,7 @@ long result = directDraw->CreateSurface(&ddsd, &frontBuffer, 0); directDraw->GetDisplayMode(&ddsd); - + switch(ddsd.ddpfPixelFormat.dwRGBBitCount) { case 32: destFormat = FORMAT_X8R8G8B8; break; @@ -372,7 +375,7 @@ if(frontBuffer) { - frontBuffer->QueryInterface(IID_IDirectDrawGammaControl, (void**)&gammaControl); + frontBuffer->QueryInterface(IID_IDirectDrawGammaControl, (void**)&gammaControl); if(gammaControl) { @@ -389,7 +392,7 @@ if(frontBuffer) { - frontBuffer->QueryInterface(IID_IDirectDrawGammaControl, (void**)&gammaControl); + frontBuffer->QueryInterface(IID_IDirectDrawGammaControl, (void**)&gammaControl); if(gammaControl) { @@ -406,7 +409,7 @@ { return locked; } - + if(!readySurfaces()) { return 0;
diff --git a/src/Main/FrameBufferDD.hpp b/src/Main/FrameBufferDD.hpp index 1f42552..c2d160a 100644 --- a/src/Main/FrameBufferDD.hpp +++ b/src/Main/FrameBufferDD.hpp
@@ -1,66 +1,69 @@ -// SwiftShader Software Renderer -// -// Copyright(c) 2005-2012 TransGaming Inc. -// -// All rights reserved. No part of this software may be copied, distributed, transmitted, -// transcribed, stored in a retrieval system, translated into any human or computer -// language by any means, or disclosed to third parties without the explicit written -// agreement of TransGaming Inc. Without such an agreement, no rights or licenses, express -// or implied, including but not limited to any patent rights, are granted to you. -// - -#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); - - virtual ~FrameBufferDD(); - - 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(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 *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. + +#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); + + virtual ~FrameBufferDD(); + + 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(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 *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
diff --git a/src/Main/FrameBufferGDI.cpp b/src/Main/FrameBufferGDI.cpp index 9251edb..e528d26 100644 --- a/src/Main/FrameBufferGDI.cpp +++ b/src/Main/FrameBufferGDI.cpp
@@ -1,13 +1,16 @@ -// SwiftShader Software Renderer +// Copyright 2016 The SwiftShader Authors. All Rights Reserved. // -// Copyright(c) 2005-2012 TransGaming Inc. +// 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 // -// All rights reserved. No part of this software may be copied, distributed, transmitted, -// transcribed, stored in a retrieval system, translated into any human or computer -// language by any means, or disclosed to third parties without the explicit written -// agreement of TransGaming Inc. Without such an agreement, no rights or licenses, express -// or implied, including but not limited to any patent rights, are granted to you. +// 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" @@ -27,7 +30,7 @@ deviceMode.dmSize = sizeof(DEVMODE); deviceMode.dmPelsWidth= width; deviceMode.dmPelsHeight = height; - deviceMode.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT; + deviceMode.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT; ChangeDisplaySettings(&deviceMode, CDS_FULLSCREEN); } @@ -72,7 +75,7 @@ { blit(source, 0, 0, sourceFormat, sourceStride); } - + void FrameBufferGDI::blit(void *source, const Rect *sourceRect, const Rect *destRect, Format sourceFormat, size_t sourceStride) { copy(source, sourceFormat, sourceStride); @@ -142,7 +145,7 @@ bitmapInfo.bmiHeader.biHeight = -height; bitmapInfo.bmiHeader.biWidth = width; bitmapInfo.bmiHeader.biCompression = BI_RGB; - + bitmap = CreateDIBSection(bitmapContext, &bitmapInfo, DIB_RGB_COLORS, &locked, 0, 0); SelectObject(bitmapContext, bitmap);
diff --git a/src/Main/FrameBufferGDI.hpp b/src/Main/FrameBufferGDI.hpp index b4b4976..f81cb8f 100644 --- a/src/Main/FrameBufferGDI.hpp +++ b/src/Main/FrameBufferGDI.hpp
@@ -1,53 +1,56 @@ -// SwiftShader Software Renderer -// -// Copyright(c) 2005-2012 TransGaming Inc. -// -// All rights reserved. No part of this software may be copied, distributed, transmitted, -// transcribed, stored in a retrieval system, translated into any human or computer -// language by any means, or disclosed to third parties without the explicit written -// agreement of TransGaming Inc. Without such an agreement, no rights or licenses, express -// or implied, including but not limited to any patent rights, are granted to you. -// - -#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); - - virtual ~FrameBufferGDI(); - - 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(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 *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_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); + + virtual ~FrameBufferGDI(); + + 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(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 *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
diff --git a/src/Main/FrameBufferOSX.hpp b/src/Main/FrameBufferOSX.hpp index 41a6348..41f95fe 100644 --- a/src/Main/FrameBufferOSX.hpp +++ b/src/Main/FrameBufferOSX.hpp
@@ -1,3 +1,17 @@ +// 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
diff --git a/src/Main/FrameBufferOSX.mm b/src/Main/FrameBufferOSX.mm index 40827cc..3a0cfc7 100644 --- a/src/Main/FrameBufferOSX.mm +++ b/src/Main/FrameBufferOSX.mm
@@ -1,3 +1,17 @@ +// 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 "Common/Debug.hpp" @@ -27,7 +41,7 @@ CGImageRelease(currentImage); CGColorSpaceRelease(colorspace); CGDataProviderRelease(provider); - + delete[] buffer; } @@ -61,7 +75,7 @@ locked = buffer; return locked; }; - + void FrameBufferOSX::unlock() { locked = nullptr; @@ -84,6 +98,6 @@ layer = reinterpret_cast<CALayer*>(window); } else ASSERT(0); - + return new sw::FrameBufferOSX(layer, width, height); }
diff --git a/src/Main/FrameBufferWin.cpp b/src/Main/FrameBufferWin.cpp index 860a424..cad8954 100644 --- a/src/Main/FrameBufferWin.cpp +++ b/src/Main/FrameBufferWin.cpp
@@ -1,75 +1,78 @@ -// SwiftShader Software Renderer -// -// Copyright(c) 2005-2012 TransGaming Inc. -// -// All rights reserved. No part of this software may be copied, distributed, transmitted, -// transcribed, stored in a retrieval system, translated into any human or computer -// language by any means, or disclosed to third parties without the explicit written -// agreement of TransGaming Inc. Without such an agreement, no rights or licenses, express -// or implied, including but not limited to any patent rights, are granted to you. -// - -#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 "Common/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. + +#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 "Common/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); +}
diff --git a/src/Main/FrameBufferWin.hpp b/src/Main/FrameBufferWin.hpp index c0d554d..91b194a 100644 --- a/src/Main/FrameBufferWin.hpp +++ b/src/Main/FrameBufferWin.hpp
@@ -1,53 +1,56 @@ -// SwiftShader Software Renderer -// -// Copyright(c) 2005-2012 TransGaming Inc. -// -// All rights reserved. No part of this software may be copied, distributed, transmitted, -// transcribed, stored in a retrieval system, translated into any human or computer -// language by any means, or disclosed to third parties without the explicit written -// agreement of TransGaming Inc. Without such an agreement, no rights or licenses, express -// or implied, including but not limited to any patent rights, are granted to you. -// - -#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); - - virtual ~FrameBufferWin(); - - 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 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. + +#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); + + virtual ~FrameBufferWin(); + + 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 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
diff --git a/src/Main/FrameBufferX11.cpp b/src/Main/FrameBufferX11.cpp index e079e8c..60e0e73 100644 --- a/src/Main/FrameBufferX11.cpp +++ b/src/Main/FrameBufferX11.cpp
@@ -1,13 +1,16 @@ -// SwiftShader Software Renderer +// Copyright 2016 The SwiftShader Authors. All Rights Reserved. // -// Copyright(c) 2005-2012 TransGaming Inc. +// 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 // -// All rights reserved. No part of this software may be copied, distributed, transmitted, -// transcribed, stored in a retrieval system, translated into any human or computer -// language by any means, or disclosed to third parties without the explicit written -// agreement of TransGaming Inc. Without such an agreement, no rights or licenses, express -// or implied, including but not limited to any patent rights, are granted to you. +// 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. // Surface.cpp: Implements the egl::Surface class, representing a drawing surface // such as the client area of a window, including any back buffers.
diff --git a/src/Main/FrameBufferX11.hpp b/src/Main/FrameBufferX11.hpp index 0473553..a9c481b 100644 --- a/src/Main/FrameBufferX11.hpp +++ b/src/Main/FrameBufferX11.hpp
@@ -1,13 +1,16 @@ -// SwiftShader Software Renderer +// Copyright 2016 The SwiftShader Authors. All Rights Reserved. // -// Copyright(c) 2005-2012 TransGaming Inc. +// 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 // -// All rights reserved. No part of this software may be copied, distributed, transmitted, -// transcribed, stored in a retrieval system, translated into any human or computer -// language by any means, or disclosed to third parties without the explicit written -// agreement of TransGaming Inc. Without such an agreement, no rights or licenses, express -// or implied, including but not limited to any patent rights, are granted to you. +// 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. // Surface.cpp: Implements the egl::Surface class, representing a drawing surface // such as the client area of a window, including any back buffers.
diff --git a/src/Main/SwiftConfig.cpp b/src/Main/SwiftConfig.cpp index 9dce441..c3eb19c 100644 --- a/src/Main/SwiftConfig.cpp +++ b/src/Main/SwiftConfig.cpp
@@ -1,13 +1,16 @@ -// SwiftShader Software Renderer +// Copyright 2016 The SwiftShader Authors. All Rights Reserved. // -// Copyright(c) 2005-2012 TransGaming Inc. +// 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 // -// All rights reserved. No part of this software may be copied, distributed, transmitted, -// transcribed, stored in a retrieval system, translated into any human or computer -// language by any means, or disclosed to third parties without the explicit written -// agreement of TransGaming Inc. Without such an agreement, no rights or licenses, express -// or implied, including but not limited to any patent rights, are granted to you. +// 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 "SwiftConfig.hpp" @@ -32,7 +35,7 @@ ss << number; return ss.str(); } - + std::string ftoa(double number) { std::stringstream ss; @@ -139,7 +142,7 @@ if(bytesReceived > 0) { receiveBuffer[bytesReceived] = 0; - + respond(clientSocket, receiveBuffer); } } @@ -194,7 +197,7 @@ else // POST data in next packet { int bytesReceived = clientSocket->receive(receiveBuffer, bufferLength); - + if(bytesReceived > 0) { receiveBuffer[bytesReceived] = 0; @@ -291,7 +294,7 @@ html += "<option value='2048'" + (config.textureMemory == 2048 ? selected : empty) + ">2048 MB</option>\n"; html += "</select></td></tr>\n"; html += "<tr><td>Device identifier:</td><td><select name='identifier' title='The information used by some applications to determine device capabilities.'>\n"; - html += "<option value='0'" + (config.identifier == 0 ? selected : empty) + ">TransGaming SwiftShader (default)</option>\n"; + html += "<option value='0'" + (config.identifier == 0 ? selected : empty) + ">Google SwiftShader (default)</option>\n"; html += "<option value='1'" + (config.identifier == 1 ? selected : empty) + ">NVIDIA GeForce 7900 GS</option>\n"; html += "<option value='2'" + (config.identifier == 2 ? selected : empty) + ">ATI Mobility Radeon X1600</option>\n"; html += "<option value='3'" + (config.identifier == 3 ? selected : empty) + ">Intel GMA X3100</option>\n"; @@ -686,7 +689,7 @@ { config.forceClearRegisters = true; } - #ifndef NDEBUG + #ifndef NDEBUG else if(sscanf(post, "minPrimitives=%d", &integer)) { config.minPrimitives = integer; @@ -770,7 +773,7 @@ void SwiftConfig::writeConfiguration() { Configurator ini("SwiftShader.ini"); - + ini.addValue("Capabilities", "PixelShaderVersion", itoa(config.pixelShaderVersion)); ini.addValue("Capabilities", "VertexShaderVersion", itoa(config.vertexShaderVersion)); ini.addValue("Capabilities", "TextureMemory", itoa(config.textureMemory));
diff --git a/src/Main/SwiftConfig.hpp b/src/Main/SwiftConfig.hpp index 14142ec..f8fd87e 100644 --- a/src/Main/SwiftConfig.hpp +++ b/src/Main/SwiftConfig.hpp
@@ -1,112 +1,115 @@ -// SwiftShader Software Renderer -// -// Copyright(c) 2005-2012 TransGaming Inc. -// -// All rights reserved. No part of this software may be copied, distributed, transmitted, -// transcribed, stored in a retrieval system, translated into any human or computer -// language by any means, or disclosed to third parties without the explicit written -// agreement of TransGaming Inc. Without such an agreement, no rights or licenses, express -// or implied, including but not limited to any patent rights, are granted to you. -// - -#ifndef sw_SwiftConfig_hpp -#define sw_SwiftConfig_hpp - -#include "Reactor/Nucleus.hpp" - -#include "Common/Thread.hpp" -#include "Common/MutexLock.hpp" -#include "Common/Socket.hpp" - -#include <string> - -namespace sw -{ - class SwiftConfig - { - public: - struct Configuration - { - int pixelShaderVersion; - int vertexShaderVersion; - int textureMemory; - int identifier; - int vertexRoutineCacheSize; - int pixelRoutineCacheSize; - int setupRoutineCacheSize; - int vertexCacheSize; - int textureSampleQuality; - int mipmapQuality; - bool perspectiveCorrection; - int transcendentalPrecision; - int threadCount; - bool enableSSE; - bool enableSSE2; - bool enableSSE3; - bool enableSSSE3; - bool enableSSE4_1; - Optimization optimization[10]; - bool disableServer; - bool keepSystemCursor; - bool forceWindowed; - bool complementaryDepthBuffer; - bool postBlendSRGB; - bool exactColorRounding; - bool disableAlphaMode; - bool disable10BitMode; - int transparencyAntialiasing; - int frameBufferAPI; - bool precache; - int shadowMapping; - bool forceClearRegisters; - #ifndef NDEBUG - unsigned int minPrimitives; - unsigned int maxPrimitives; - #endif - }; - - SwiftConfig(bool disableServerOverride); - - ~SwiftConfig(); - - bool hasNewConfiguration(bool reset = true); - void getConfiguration(Configuration &configuration); - - private: - enum Status - { - OK = 200, - NotFound = 404 - }; - - void createServer(); - void destroyServer(); - - static void serverRoutine(void *parameters); - - void serverLoop(); - void respond(Socket *clientSocket, const char *request); - std::string page(); - std::string profile(); - void send(Socket *clientSocket, Status code, std::string body = ""); - void parsePost(const char *post); - - void readConfiguration(bool disableServerOverride = false); - void writeConfiguration(); - - Configuration config; - - Thread *serverThread; - volatile bool terminate; - BackoffLock criticalSection; // Protects reading and writing the configuration settings - - bool newConfig; - - Socket *listenSocket; - - int bufferLength; - char *receiveBuffer; - }; -} - -#endif // sw_SwiftConfig_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_SwiftConfig_hpp +#define sw_SwiftConfig_hpp + +#include "Reactor/Nucleus.hpp" + +#include "Common/Thread.hpp" +#include "Common/MutexLock.hpp" +#include "Common/Socket.hpp" + +#include <string> + +namespace sw +{ + class SwiftConfig + { + public: + struct Configuration + { + int pixelShaderVersion; + int vertexShaderVersion; + int textureMemory; + int identifier; + int vertexRoutineCacheSize; + int pixelRoutineCacheSize; + int setupRoutineCacheSize; + int vertexCacheSize; + int textureSampleQuality; + int mipmapQuality; + bool perspectiveCorrection; + int transcendentalPrecision; + int threadCount; + bool enableSSE; + bool enableSSE2; + bool enableSSE3; + bool enableSSSE3; + bool enableSSE4_1; + Optimization optimization[10]; + bool disableServer; + bool keepSystemCursor; + bool forceWindowed; + bool complementaryDepthBuffer; + bool postBlendSRGB; + bool exactColorRounding; + bool disableAlphaMode; + bool disable10BitMode; + int transparencyAntialiasing; + int frameBufferAPI; + bool precache; + int shadowMapping; + bool forceClearRegisters; + #ifndef NDEBUG + unsigned int minPrimitives; + unsigned int maxPrimitives; + #endif + }; + + SwiftConfig(bool disableServerOverride); + + ~SwiftConfig(); + + bool hasNewConfiguration(bool reset = true); + void getConfiguration(Configuration &configuration); + + private: + enum Status + { + OK = 200, + NotFound = 404 + }; + + void createServer(); + void destroyServer(); + + static void serverRoutine(void *parameters); + + void serverLoop(); + void respond(Socket *clientSocket, const char *request); + std::string page(); + std::string profile(); + void send(Socket *clientSocket, Status code, std::string body = ""); + void parsePost(const char *post); + + void readConfiguration(bool disableServerOverride = false); + void writeConfiguration(); + + Configuration config; + + Thread *serverThread; + volatile bool terminate; + BackoffLock criticalSection; // Protects reading and writing the configuration settings + + bool newConfig; + + Socket *listenSocket; + + int bufferLength; + char *receiveBuffer; + }; +} + +#endif // sw_SwiftConfig_hpp
diff --git a/src/Main/libX11.cpp b/src/Main/libX11.cpp index 4b72a7c..7739e4a 100644 --- a/src/Main/libX11.cpp +++ b/src/Main/libX11.cpp
@@ -1,3 +1,17 @@ +// 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 "libX11.hpp" #include "Common/SharedLibrary.hpp" @@ -6,27 +20,27 @@ LibX11exports::LibX11exports(void *libX11, void *libXext) { - XOpenDisplay = (Display *(*)(char*))getProcAddress(libX11, "XOpenDisplay"); - XGetWindowAttributes = (Status (*)(Display*, Window, XWindowAttributes*))getProcAddress(libX11, "XGetWindowAttributes"); - XDefaultScreenOfDisplay = (Screen *(*)(Display*))getProcAddress(libX11, "XDefaultScreenOfDisplay"); - XWidthOfScreen = (int (*)(Screen*))getProcAddress(libX11, "XWidthOfScreen"); - XHeightOfScreen = (int (*)(Screen*))getProcAddress(libX11, "XHeightOfScreen"); - XPlanesOfScreen = (int (*)(Screen*))getProcAddress(libX11, "XPlanesOfScreen"); - XDefaultGC = (GC (*)(Display*, int))getProcAddress(libX11, "XDefaultGC"); - XDefaultDepth = (int (*)(Display*, int))getProcAddress(libX11, "XDefaultDepth"); - XMatchVisualInfo = (Status (*)(Display*, int, int, int, XVisualInfo*))getProcAddress(libX11, "XMatchVisualInfo"); - XDefaultVisual = (Visual *(*)(Display*, int screen_number))getProcAddress(libX11, "XDefaultVisual"); - XSetErrorHandler = (int (*(*)(int (*)(Display*, XErrorEvent*)))(Display*, XErrorEvent*))getProcAddress(libX11, "XSetErrorHandler"); - XSync = (int (*)(Display*, Bool))getProcAddress(libX11, "XSync"); - XCreateImage = (XImage *(*)(Display*, Visual*, unsigned int, int, int, char*, unsigned int, unsigned int, int, int))getProcAddress(libX11, "XCreateImage"); - XCloseDisplay = (int (*)(Display*))getProcAddress(libX11, "XCloseDisplay"); - XPutImage = (int (*)(Display*, Drawable, GC, XImage*, int, int, int, int, unsigned int, unsigned int))getProcAddress(libX11, "XPutImage"); + XOpenDisplay = (Display *(*)(char*))getProcAddress(libX11, "XOpenDisplay"); + XGetWindowAttributes = (Status (*)(Display*, Window, XWindowAttributes*))getProcAddress(libX11, "XGetWindowAttributes"); + XDefaultScreenOfDisplay = (Screen *(*)(Display*))getProcAddress(libX11, "XDefaultScreenOfDisplay"); + XWidthOfScreen = (int (*)(Screen*))getProcAddress(libX11, "XWidthOfScreen"); + XHeightOfScreen = (int (*)(Screen*))getProcAddress(libX11, "XHeightOfScreen"); + XPlanesOfScreen = (int (*)(Screen*))getProcAddress(libX11, "XPlanesOfScreen"); + XDefaultGC = (GC (*)(Display*, int))getProcAddress(libX11, "XDefaultGC"); + XDefaultDepth = (int (*)(Display*, int))getProcAddress(libX11, "XDefaultDepth"); + XMatchVisualInfo = (Status (*)(Display*, int, int, int, XVisualInfo*))getProcAddress(libX11, "XMatchVisualInfo"); + XDefaultVisual = (Visual *(*)(Display*, int screen_number))getProcAddress(libX11, "XDefaultVisual"); + XSetErrorHandler = (int (*(*)(int (*)(Display*, XErrorEvent*)))(Display*, XErrorEvent*))getProcAddress(libX11, "XSetErrorHandler"); + XSync = (int (*)(Display*, Bool))getProcAddress(libX11, "XSync"); + XCreateImage = (XImage *(*)(Display*, Visual*, unsigned int, int, int, char*, unsigned int, unsigned int, int, int))getProcAddress(libX11, "XCreateImage"); + XCloseDisplay = (int (*)(Display*))getProcAddress(libX11, "XCloseDisplay"); + XPutImage = (int (*)(Display*, Drawable, GC, XImage*, int, int, int, int, unsigned int, unsigned int))getProcAddress(libX11, "XPutImage"); - XShmQueryExtension = (Bool (*)(Display*))getProcAddress(libXext, "XShmQueryExtension"); - XShmCreateImage = (XImage *(*)(Display*, Visual*, unsigned int, int, char*, XShmSegmentInfo*, unsigned int, unsigned int))getProcAddress(libXext, "XShmCreateImage"); - XShmAttach = (Bool (*)(Display*, XShmSegmentInfo*))getProcAddress(libXext, "XShmAttach"); - XShmDetach = (Bool (*)(Display*, XShmSegmentInfo*))getProcAddress(libXext, "XShmDetach"); - XShmPutImage = (int (*)(Display*, Drawable, GC, XImage*, int, int, int, int, unsigned int, unsigned int, bool))getProcAddress(libXext, "XShmPutImage"); + XShmQueryExtension = (Bool (*)(Display*))getProcAddress(libXext, "XShmQueryExtension"); + XShmCreateImage = (XImage *(*)(Display*, Visual*, unsigned int, int, char*, XShmSegmentInfo*, unsigned int, unsigned int))getProcAddress(libXext, "XShmCreateImage"); + XShmAttach = (Bool (*)(Display*, XShmSegmentInfo*))getProcAddress(libXext, "XShmAttach"); + XShmDetach = (Bool (*)(Display*, XShmSegmentInfo*))getProcAddress(libXext, "XShmDetach"); + XShmPutImage = (int (*)(Display*, Drawable, GC, XImage*, int, int, int, int, unsigned int, unsigned int, bool))getProcAddress(libXext, "XShmPutImage"); } LibX11exports *LibX11::operator->() @@ -36,31 +50,31 @@ LibX11exports *LibX11::loadExports() { - static void *libX11 = nullptr; - static void *libXext = nullptr; - static LibX11exports *libX11exports = nullptr; + static void *libX11 = nullptr; + static void *libXext = nullptr; + static LibX11exports *libX11exports = nullptr; - if(!libX11) - { - libX11 = loadLibrary("libX11.so"); + if(!libX11) + { + libX11 = loadLibrary("libX11.so"); - if(libX11) - { - libXext = loadLibrary("libXext.so"); - libX11exports = new LibX11exports(libX11, libXext); - } - else // Might have failed to load due to sandboxing. Search the global scope for pre-loaded library. - { - if(getProcAddress(RTLD_DEFAULT, "XOpenDisplay")) - { - libX11exports = new LibX11exports(RTLD_DEFAULT, RTLD_DEFAULT); - } + if(libX11) + { + libXext = loadLibrary("libXext.so"); + libX11exports = new LibX11exports(libX11, libXext); + } + else // Might have failed to load due to sandboxing. Search the global scope for pre-loaded library. + { + if(getProcAddress(RTLD_DEFAULT, "XOpenDisplay")) + { + libX11exports = new LibX11exports(RTLD_DEFAULT, RTLD_DEFAULT); + } - libX11 = (void*)-1; // Don't attempt loading more than once. - } - } + libX11 = (void*)-1; // Don't attempt loading more than once. + } + } - return libX11exports; + return libX11exports; } LibX11 libX11;
diff --git a/src/Main/libX11.hpp b/src/Main/libX11.hpp index 897a662..f9f88be 100644 --- a/src/Main/libX11.hpp +++ b/src/Main/libX11.hpp
@@ -1,3 +1,17 @@ +// 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 libX11_hpp #define libX11_hpp @@ -8,29 +22,29 @@ struct LibX11exports { - LibX11exports(void *libX11, void *libXext); + LibX11exports(void *libX11, void *libXext); - Display *(*XOpenDisplay)(char *display_name); - Status (*XGetWindowAttributes)(Display *display, Window w, XWindowAttributes *window_attributes_return); - Screen *(*XDefaultScreenOfDisplay)(Display *display); - int (*XWidthOfScreen)(Screen *screen); - int (*XHeightOfScreen)(Screen *screen); - int (*XPlanesOfScreen)(Screen *screen); - GC (*XDefaultGC)(Display *display, int screen_number); - int (*XDefaultDepth)(Display *display, int screen_number); - Status (*XMatchVisualInfo)(Display *display, int screen, int depth, int screen_class, XVisualInfo *vinfo_return); - Visual *(*XDefaultVisual)(Display *display, int screen_number); - int (*(*XSetErrorHandler)(int (*handler)(Display*, XErrorEvent*)))(Display*, XErrorEvent*); - int (*XSync)(Display *display, Bool discard); - XImage *(*XCreateImage)(Display *display, Visual *visual, unsigned int depth, int format, int offset, char *data, unsigned int width, unsigned int height, int bitmap_pad, int bytes_per_line); - int (*XCloseDisplay)(Display *display); - int (*XPutImage)(Display *display, Drawable d, GC gc, XImage *image, int src_x, int src_y, int dest_x, int dest_y, unsigned int width, unsigned int height); + Display *(*XOpenDisplay)(char *display_name); + Status (*XGetWindowAttributes)(Display *display, Window w, XWindowAttributes *window_attributes_return); + Screen *(*XDefaultScreenOfDisplay)(Display *display); + int (*XWidthOfScreen)(Screen *screen); + int (*XHeightOfScreen)(Screen *screen); + int (*XPlanesOfScreen)(Screen *screen); + GC (*XDefaultGC)(Display *display, int screen_number); + int (*XDefaultDepth)(Display *display, int screen_number); + Status (*XMatchVisualInfo)(Display *display, int screen, int depth, int screen_class, XVisualInfo *vinfo_return); + Visual *(*XDefaultVisual)(Display *display, int screen_number); + int (*(*XSetErrorHandler)(int (*handler)(Display*, XErrorEvent*)))(Display*, XErrorEvent*); + int (*XSync)(Display *display, Bool discard); + XImage *(*XCreateImage)(Display *display, Visual *visual, unsigned int depth, int format, int offset, char *data, unsigned int width, unsigned int height, int bitmap_pad, int bytes_per_line); + int (*XCloseDisplay)(Display *display); + int (*XPutImage)(Display *display, Drawable d, GC gc, XImage *image, int src_x, int src_y, int dest_x, int dest_y, unsigned int width, unsigned int height); - Bool (*XShmQueryExtension)(Display *display); - XImage *(*XShmCreateImage)(Display *display, Visual *visual, unsigned int depth, int format, char *data, XShmSegmentInfo *shminfo, unsigned int width, unsigned int height); - Bool (*XShmAttach)(Display *display, XShmSegmentInfo *shminfo); - Bool (*XShmDetach)(Display *display, XShmSegmentInfo *shminfo); - int (*XShmPutImage)(Display *display, Drawable d, GC gc, XImage *image, int src_x, int src_y, int dest_x, int dest_y, unsigned int width, unsigned int height, bool send_event); + Bool (*XShmQueryExtension)(Display *display); + XImage *(*XShmCreateImage)(Display *display, Visual *visual, unsigned int depth, int format, char *data, XShmSegmentInfo *shminfo, unsigned int width, unsigned int height); + Bool (*XShmAttach)(Display *display, XShmSegmentInfo *shminfo); + Bool (*XShmDetach)(Display *display, XShmSegmentInfo *shminfo); + int (*XShmPutImage)(Display *display, Drawable d, GC gc, XImage *image, int src_x, int src_y, int dest_x, int dest_y, unsigned int width, unsigned int height, bool send_event); }; #undef Bool @@ -43,7 +57,7 @@ return loadExports(); } - LibX11exports *operator->(); + LibX11exports *operator->(); private: LibX11exports *loadExports();