From 6f70d43719d0583d486a000f66e915c10a6b83a2 Mon Sep 17 00:00:00 2001 From: robertphillips Date: Wed, 30 Mar 2016 09:26:24 -0700 Subject: [PATCH] Revert of Move SkGLContext and some GrGLInterface implementations to skgputest module (patchset #13 id:240001 of https://codereview.chromium.org/1815823002/ ) Reason for revert: red bots Original issue's description: > Move SkGLContext and some GrGLInterface implementations to skgputest module > > BUG=skia: > GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1815823002 > CQ_EXTRA_TRYBOTS=client.skia.compile:Build-Ubuntu-GCC-x86_64-Release-CMake-Trybot,Build-Mac-Clang-x86_64-Release-CMake-Trybot > > Committed: https://skia.googlesource.com/skia/+/fe3456cb006110d045b26ff3f8681b893a757b58 TBR=jvanverth@google.com,bsalomon@google.com # Skipping CQ checks because original CL landed less than 1 days ago. NOPRESUBMIT=true NOTREECHECKS=true NOTRY=true BUG=skia: Review URL: https://codereview.chromium.org/1845473004 --- bench/nanobench.cpp | 19 +- bench/nanobench.h | 4 +- cmake/CMakeLists.txt | 3 + dm/DM.cpp | 4 +- dm/DMGpuSupport.h | 21 +- dm/DMSrcSink.cpp | 2 - dm/DMSrcSink.h | 17 +- gm/image.cpp | 2 +- gyp/SampleApp.gyp | 1 - gyp/flags.gyp | 9 +- gyp/gpu.gyp | 56 ++ gyp/gpu.gypi | 59 +- gyp/gputest.gyp | 79 +-- gyp/kilobench.gyp | 2 - gyp/pathops_unittest.gyp | 9 + gyp/skiaserve.gyp | 1 - gyp/visualbench.gyp | 1 - include/gpu/gl/GrGLInterface.h | 31 +- .../gpu/gl/SkGLContext.h | 70 +- include/gpu/gl/SkNullGLContext.h | 26 + include/gpu/gl/angle/SkANGLEGLContext.h | 61 ++ .../command_buffer/SkCommandBufferGLContext.h | 63 ++ samplecode/SampleApp.cpp | 15 +- {tools => src}/gpu/GrContextFactory.cpp | 41 +- {tools => src}/gpu/GrContextFactory.h | 19 +- {tools => src}/gpu/GrTest.cpp | 0 {tools => src}/gpu/GrTest.h | 0 src/gpu/gl/GrGLTestInterface.h | 4 - .../gpu/gl/SkGLContext.cpp | 45 +- src/gpu/gl/SkNullGLContext.cpp | 26 + src/gpu/gl/angle/GrGLCreateANGLEInterface.cpp | 57 ++ .../gpu/gl/angle/SkANGLEGLContext.cpp | 149 +---- .../SkCommandBufferGLContext.cpp | 71 +- {tools => src}/gpu/gl/debug/GrBufferObj.cpp | 1 - {tools => src}/gpu/gl/debug/GrBufferObj.h | 3 +- {tools => src}/gpu/gl/debug/GrFBBindableObj.h | 1 - {tools => src}/gpu/gl/debug/GrFakeRefObj.h | 0 .../gpu/gl/debug/GrFrameBufferObj.cpp | 1 - .../gpu/gl/debug/GrFrameBufferObj.h | 1 - .../gpu/gl/debug/GrGLCreateDebugInterface.cpp | 468 +++++++------ {tools => src}/gpu/gl/debug/GrProgramObj.cpp | 1 - {tools => src}/gpu/gl/debug/GrProgramObj.h | 1 - .../gpu/gl/debug/GrRenderBufferObj.h | 1 - {tools => src}/gpu/gl/debug/GrShaderObj.cpp | 1 - {tools => src}/gpu/gl/debug/GrShaderObj.h | 3 +- {tools => src}/gpu/gl/debug/GrTextureObj.cpp | 1 - {tools => src}/gpu/gl/debug/GrTextureObj.h | 1 - .../gpu/gl/debug/GrTextureUnitObj.cpp | 1 - .../gpu/gl/debug/GrTextureUnitObj.h | 0 .../gpu/gl/debug/GrVertexArrayObj.h | 0 src/gpu/gl/debug/SkDebugGLContext.cpp | 16 + src/gpu/gl/debug/SkDebugGLContext.h | 27 + .../gl/egl/SkCreatePlatformGLContext_egl.cpp | 20 +- .../gl/glx/SkCreatePlatformGLContext_glx.cpp | 13 +- .../gl/iOS/SkCreatePlatformGLContext_iOS.mm | 12 +- .../gl/mac/SkCreatePlatformGLContext_mac.cpp | 14 +- src/gpu/gl/mesa/GrGLCreateMesaInterface.cpp | 24 + .../gpu/gl/mesa/SkMesaGLContext.cpp | 81 +-- src/gpu/gl/mesa/SkMesaGLContext.h | 44 ++ .../nacl/SkCreatePlatformGLContext_nacl.cpp | 12 + .../gl/win/SkCreatePlatformGLContext_win.cpp | 12 +- src/views/win/SkOSWindow_win.cpp | 32 +- tests/EGLImageTest.cpp | 8 +- tests/GLProgramsTest.cpp | 2 +- tests/GrContextFactoryTest.cpp | 2 - tests/GrPorterDuffTest.cpp | 4 +- tests/ImageTest.cpp | 2 - tests/RectangleTextureTest.cpp | 2 +- tests/Test.h | 32 +- tests/TestConfigParsing.cpp | 2 - tests/TestTest.cpp | 4 +- tests/TextureStorageAllocator.cpp | 2 +- tests/skia_test.cpp | 1 - tools/VisualBench/VisualBench.h | 2 +- tools/flags/SkCommonFlagsConfig.cpp | 4 - tools/flags/SkCommonFlagsConfig.h | 2 +- tools/gpu/gl/angle/GLContext_angle.h | 30 - .../command_buffer/GLContext_command_buffer.h | 68 -- tools/gpu/gl/debug/DebugGLContext.h | 17 - tools/gpu/gl/mesa/GLContext_mesa.h | 17 - tools/gpu/gl/mesa/osmesa_wrapper.h | 16 - tools/gpu/gl/null/NullGLContext.cpp | 630 ------------------ tools/gpu/gl/null/NullGLContext.h | 17 - tools/kilobench/kilobench.cpp | 21 +- tools/skiaserve/Request.cpp | 6 +- tools/skiaserve/Request.h | 4 +- 86 files changed, 1014 insertions(+), 1640 deletions(-) rename tools/gpu/gl/GLContext.h => include/gpu/gl/SkGLContext.h (65%) create mode 100644 include/gpu/gl/SkNullGLContext.h create mode 100644 include/gpu/gl/angle/SkANGLEGLContext.h create mode 100644 include/gpu/gl/command_buffer/SkCommandBufferGLContext.h rename {tools => src}/gpu/GrContextFactory.cpp (79%) rename {tools => src}/gpu/GrContextFactory.h (90%) rename {tools => src}/gpu/GrTest.cpp (100%) rename {tools => src}/gpu/GrTest.h (100%) rename tools/gpu/gl/GLContext.cpp => src/gpu/gl/SkGLContext.cpp (81%) create mode 100644 src/gpu/gl/SkNullGLContext.cpp create mode 100644 src/gpu/gl/angle/GrGLCreateANGLEInterface.cpp rename tools/gpu/gl/angle/GLContext_angle.cpp => src/gpu/gl/angle/SkANGLEGLContext.cpp (58%) rename tools/gpu/gl/command_buffer/GLContext_command_buffer.cpp => src/gpu/gl/command_buffer/SkCommandBufferGLContext.cpp (86%) rename {tools => src}/gpu/gl/debug/GrBufferObj.cpp (99%) rename {tools => src}/gpu/gl/debug/GrBufferObj.h (98%) rename {tools => src}/gpu/gl/debug/GrFBBindableObj.h (99%) rename {tools => src}/gpu/gl/debug/GrFakeRefObj.h (100%) rename {tools => src}/gpu/gl/debug/GrFrameBufferObj.cpp (99%) rename {tools => src}/gpu/gl/debug/GrFrameBufferObj.h (99%) rename tools/gpu/gl/debug/DebugGLContext.cpp => src/gpu/gl/debug/GrGLCreateDebugInterface.cpp (76%) rename {tools => src}/gpu/gl/debug/GrProgramObj.cpp (99%) rename {tools => src}/gpu/gl/debug/GrProgramObj.h (99%) rename {tools => src}/gpu/gl/debug/GrRenderBufferObj.h (99%) rename {tools => src}/gpu/gl/debug/GrShaderObj.cpp (99%) rename {tools => src}/gpu/gl/debug/GrShaderObj.h (96%) rename {tools => src}/gpu/gl/debug/GrTextureObj.cpp (99%) rename {tools => src}/gpu/gl/debug/GrTextureObj.h (99%) rename {tools => src}/gpu/gl/debug/GrTextureUnitObj.cpp (99%) rename {tools => src}/gpu/gl/debug/GrTextureUnitObj.h (100%) rename {tools => src}/gpu/gl/debug/GrVertexArrayObj.h (100%) create mode 100644 src/gpu/gl/debug/SkDebugGLContext.cpp create mode 100644 src/gpu/gl/debug/SkDebugGLContext.h rename tools/gpu/gl/egl/CreatePlatformGLContext_egl.cpp => src/gpu/gl/egl/SkCreatePlatformGLContext_egl.cpp (95%) rename tools/gpu/gl/glx/CreatePlatformGLContext_glx.cpp => src/gpu/gl/glx/SkCreatePlatformGLContext_glx.cpp (97%) rename tools/gpu/gl/iOS/CreatePlatformGLContext_iOS.mm => src/gpu/gl/iOS/SkCreatePlatformGLContext_iOS.mm (89%) rename tools/gpu/gl/mac/CreatePlatformGLContext_mac.cpp => src/gpu/gl/mac/SkCreatePlatformGLContext_mac.cpp (91%) create mode 100644 src/gpu/gl/mesa/GrGLCreateMesaInterface.cpp rename tools/gpu/gl/mesa/GLContext_mesa.cpp => src/gpu/gl/mesa/SkMesaGLContext.cpp (52%) create mode 100644 src/gpu/gl/mesa/SkMesaGLContext.h create mode 100644 src/gpu/gl/nacl/SkCreatePlatformGLContext_nacl.cpp rename tools/gpu/gl/win/CreatePlatformGLContext_win.cpp => src/gpu/gl/win/SkCreatePlatformGLContext_win.cpp (94%) delete mode 100644 tools/gpu/gl/angle/GLContext_angle.h delete mode 100644 tools/gpu/gl/command_buffer/GLContext_command_buffer.h delete mode 100644 tools/gpu/gl/debug/DebugGLContext.h delete mode 100644 tools/gpu/gl/mesa/GLContext_mesa.h delete mode 100644 tools/gpu/gl/mesa/osmesa_wrapper.h delete mode 100644 tools/gpu/gl/null/NullGLContext.cpp delete mode 100644 tools/gpu/gl/null/NullGLContext.h diff --git a/bench/nanobench.cpp b/bench/nanobench.cpp index 235de02f57..c0f674fc59 100644 --- a/bench/nanobench.cpp +++ b/bench/nanobench.cpp @@ -56,9 +56,6 @@ #include "gl/GrGLDefines.h" #include "GrCaps.h" #include "GrContextFactory.h" - #include "gl/GrGLUtil.h" - using sk_gpu_test::GrContextFactory; - using sk_gpu_test::GLContext; SkAutoTDelete gGrFactory; #endif @@ -158,21 +155,21 @@ bool Target::capturePixels(SkBitmap* bmp) { #if SK_SUPPORT_GPU struct GPUTarget : public Target { explicit GPUTarget(const Config& c) : Target(c), gl(nullptr) { } - GLContext* gl; + SkGLContext* gl; void setup() override { this->gl->makeCurrent(); // Make sure we're done with whatever came before. - GR_GL_CALL(this->gl->gl(), Finish()); + SK_GL(*this->gl, Finish()); } void endTiming() override { if (this->gl) { - GR_GL_CALL(this->gl->gl(), Flush()); + SK_GL(*this->gl, Flush()); this->gl->waitOnSyncOrSwap(); } } void fence() override { - GR_GL_CALL(this->gl->gl(), Finish()); + SK_GL(*this->gl, Finish()); } bool needsFrameTiming(int* maxFrameLag) const override { @@ -203,16 +200,16 @@ struct GPUTarget : public Target { } void fillOptions(ResultsWriter* log) override { const GrGLubyte* version; - GR_GL_CALL_RET(this->gl->gl(), version, GetString(GR_GL_VERSION)); + SK_GL_RET(*this->gl, version, GetString(GR_GL_VERSION)); log->configOption("GL_VERSION", (const char*)(version)); - GR_GL_CALL_RET(this->gl->gl(), version, GetString(GR_GL_RENDERER)); + SK_GL_RET(*this->gl, version, GetString(GR_GL_RENDERER)); log->configOption("GL_RENDERER", (const char*) version); - GR_GL_CALL_RET(this->gl->gl(), version, GetString(GR_GL_VENDOR)); + SK_GL_RET(*this->gl, version, GetString(GR_GL_VENDOR)); log->configOption("GL_VENDOR", (const char*) version); - GR_GL_CALL_RET(this->gl->gl(), version, GetString(GR_GL_SHADING_LANGUAGE_VERSION)); + SK_GL_RET(*this->gl, version, GetString(GR_GL_SHADING_LANGUAGE_VERSION)); log->configOption("GL_SHADING_LANGUAGE_VERSION", (const char*) version); } }; diff --git a/bench/nanobench.h b/bench/nanobench.h index 844811e26d..5e4efbf077 100644 --- a/bench/nanobench.h +++ b/bench/nanobench.h @@ -29,8 +29,8 @@ struct Config { SkColorProfileType profile; int samples; #if SK_SUPPORT_GPU - sk_gpu_test::GrContextFactory::GLContextType ctxType; - sk_gpu_test::GrContextFactory::GLContextOptions ctxOptions; + GrContextFactory::GLContextType ctxType; + GrContextFactory::GLContextOptions ctxOptions; bool useDFText; #else int bogusInt; diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 67cdb1d719..d3ffa35e90 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -90,6 +90,7 @@ remove_srcs( ../src/gpu/GrContextFactory.cpp # For internal testing only. ../src/gpu/gl/GrGLCreateNativeInterface_none.cpp ../src/gpu/gl/GrGLDefaultInterface_none.cpp + ../src/gpu/gl/SkCreatePlatformGLContext*.cpp # For internal testing only. ../src/gpu/gl/command_buffer/* ../src/gpu/gl/egl/* ../src/gpu/gl/glfw/* @@ -120,6 +121,8 @@ if (WIN32) endif() endif() +remove_srcs(../src/gpu/gl/angle/*) # TODO + # Certain files must be compiled with support for SSSE3, SSE4.1, AVX, or AVX2 intrinsics. file (GLOB_RECURSE ssse3_srcs ../src/*ssse3*.cpp ../src/*SSSE3*.cpp) file (GLOB_RECURSE sse41_srcs ../src/*sse4*.cpp ../src/*SSE4*.cpp) diff --git a/dm/DM.cpp b/dm/DM.cpp index 363f9f078c..34f8a961e3 100644 --- a/dm/DM.cpp +++ b/dm/DM.cpp @@ -70,8 +70,6 @@ DEFINE_int32(shard, 0, "Which shard do I run?"); DEFINE_bool(simpleCodec, false, "Only decode images to native scale"); using namespace DM; -using sk_gpu_test::GrContextFactory; -using sk_gpu_test::GLContext; /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ @@ -1413,7 +1411,7 @@ int dm_main() { namespace skiatest { namespace { typedef void(*TestWithGrContext)(skiatest::Reporter*, GrContext*); -typedef void(*TestWithGrContextAndGLContext)(skiatest::Reporter*, GrContext*, GLContext*); +typedef void(*TestWithGrContextAndGLContext)(skiatest::Reporter*, GrContext*, SkGLContext*); #if SK_SUPPORT_GPU template void call_test(T test, skiatest::Reporter* reporter, const GrContextFactory::ContextInfo& context); diff --git a/dm/DMGpuSupport.h b/dm/DMGpuSupport.h index c713244e9d..73adeb0302 100644 --- a/dm/DMGpuSupport.h +++ b/dm/DMGpuSupport.h @@ -28,13 +28,12 @@ namespace DM { static const bool kGPUDisabled = false; -static inline sk_sp NewGpuSurface( - sk_gpu_test::GrContextFactory* grFactory, - sk_gpu_test::GrContextFactory::GLContextType type, - sk_gpu_test::GrContextFactory::GLContextOptions options, - SkImageInfo info, - int samples, - bool useDIText) { +static inline sk_sp NewGpuSurface(GrContextFactory* grFactory, + GrContextFactory::GLContextType type, + GrContextFactory::GLContextOptions options, + SkImageInfo info, + int samples, + bool useDIText) { uint32_t flags = useDIText ? SkSurfaceProps::kUseDeviceIndependentFonts_Flag : 0; SkSurfaceProps props(flags, SkSurfaceProps::kLegacyFontHost_InitType); return SkSurface::MakeRenderTarget(grFactory->get(type, options), SkBudgeted::kNo, @@ -60,7 +59,6 @@ public: void dumpGpuStats(SkString*) const {} }; -namespace sk_gpu_test { class GrContextFactory { public: GrContextFactory() {}; @@ -85,15 +83,14 @@ public: void abandonContexts() {} }; -} // namespace sk_gpu_test namespace DM { static const bool kGPUDisabled = true; -static inline SkSurface* NewGpuSurface(sk_gpu_test::GrContextFactory*, - sk_gpu_test::GrContextFactory::GLContextType, - sk_gpu_test::GrContextFactory::GLContextOptions, +static inline SkSurface* NewGpuSurface(GrContextFactory*, + GrContextFactory::GLContextType, + GrContextFactory::GLContextOptions, SkImageInfo, int, bool) { diff --git a/dm/DMSrcSink.cpp b/dm/DMSrcSink.cpp index e704f74d03..9e9ba9ed82 100644 --- a/dm/DMSrcSink.cpp +++ b/dm/DMSrcSink.cpp @@ -45,8 +45,6 @@ DEFINE_bool(multiPage, false, "For document-type backends, render the source" " into multiple pages"); DEFINE_bool(RAW_threading, true, "Allow RAW decodes to run on multiple threads?"); -using sk_gpu_test::GrContextFactory; - namespace DM { GMSrc::GMSrc(skiagm::GMRegistry::Factory factory) : fFactory(factory) {} diff --git a/dm/DMSrcSink.h b/dm/DMSrcSink.h index 3a35acf005..1a56e817ca 100644 --- a/dm/DMSrcSink.h +++ b/dm/DMSrcSink.h @@ -232,8 +232,7 @@ public: class GPUSink : public Sink { public: - GPUSink(sk_gpu_test::GrContextFactory::GLContextType, - sk_gpu_test::GrContextFactory::GLContextOptions, + GPUSink(GrContextFactory::GLContextType, GrContextFactory::GLContextOptions, int samples, bool diText, SkColorType colorType, SkColorProfileType profileType, bool threaded); @@ -242,13 +241,13 @@ public: const char* fileExtension() const override { return "png"; } SinkFlags flags() const override { return SinkFlags{ SinkFlags::kGPU, SinkFlags::kDirect }; } private: - sk_gpu_test::GrContextFactory::GLContextType fContextType; - sk_gpu_test::GrContextFactory::GLContextOptions fContextOptions; - int fSampleCount; - bool fUseDIText; - SkColorType fColorType; - SkColorProfileType fProfileType; - bool fThreaded; + GrContextFactory::GLContextType fContextType; + GrContextFactory::GLContextOptions fContextOptions; + int fSampleCount; + bool fUseDIText; + SkColorType fColorType; + SkColorProfileType fProfileType; + bool fThreaded; }; class PDFSink : public Sink { diff --git a/gm/image.cpp b/gm/image.cpp index a84e19b3f7..5333b1725d 100644 --- a/gm/image.cpp +++ b/gm/image.cpp @@ -433,7 +433,7 @@ DEF_SIMPLE_GM(new_texture_image, canvas, 225, 60) { GrContext* context = nullptr; #if SK_SUPPORT_GPU context = canvas->getGrContext(); - sk_gpu_test::GrContextFactory factory; + GrContextFactory factory; #endif if (!context) { skiagm::GM::DrawGpuOnlyMessage(canvas); diff --git a/gyp/SampleApp.gyp b/gyp/SampleApp.gyp index 52061f28b3..47a2e90365 100644 --- a/gyp/SampleApp.gyp +++ b/gyp/SampleApp.gyp @@ -153,7 +153,6 @@ 'lua.gyp:lua', 'pdf.gyp:pdf', 'skia_lib.gyp:skia_lib', - 'gputest.gyp:skgputest', 'tools.gyp:resources', 'tools.gyp:sk_tool_utils', 'tools.gyp:timer', diff --git a/gyp/flags.gyp b/gyp/flags.gyp index 166e24b55a..258ca40fab 100644 --- a/gyp/flags.gyp +++ b/gyp/flags.gyp @@ -24,14 +24,7 @@ 'include_dirs': [ '../tools/flags', ], - }, - 'conditions': [ - ['skia_gpu', { - 'dependencies': [ - 'gputest.gyp:skgputest', - ], - }], - ], + } }, { 'target_name': 'flags_common', diff --git a/gyp/gpu.gyp b/gyp/gpu.gyp index 2fedbed93c..80fc932b8a 100644 --- a/gyp/gpu.gyp +++ b/gyp/gpu.gyp @@ -102,6 +102,11 @@ 'sources': [ '<@(skgpu_sources)', '<@(skgpu_native_gl_sources)', + '<@(skgpu_angle_gl_sources)', + '<@(skgpu_command_buffer_gl_sources)', + '<@(skgpu_mesa_gl_sources)', + '<@(skgpu_debug_gl_sources)', + '<@(skgpu_null_gl_sources)', '<@(skgpu_vk_sources)', 'gpu.gypi', # Makes the gypi appear in IDEs (but does not modify the build). ], @@ -146,6 +151,23 @@ ], }, }], + [ 'skia_egl == 1', { + 'defines': [ + 'SK_EGL=1', + ], + }], + [ 'skia_egl == 0', { + 'defines': [ + 'SK_EGL=0', + ], + }], + [ 'skia_mesa and skia_os == "linux"', { + 'link_settings': { + 'libraries': [ + '-lOSMesa', + ], + }, + }], [ 'skia_os == "mac"', { 'link_settings': { 'libraries': [ @@ -157,12 +179,46 @@ '../src/gpu/gl/GrGLCreateNativeInterface_none.cpp', ], }], + [ 'not skia_mesa', { + 'sources!': [ + '../src/gpu/gl/mesa/SkMesaGLContext.cpp', + '../src/gpu/gl/mesa/GrGLCreateMesaInterface.cpp', + ], + }], + [ 'skia_mesa and skia_os == "mac"', { + 'link_settings': { + 'libraries': [ + '/opt/X11/lib/libOSMesa.dylib', + ], + }, + 'include_dirs': [ + '/opt/X11/include/', + ], + }], [ 'skia_os in ["win", "ios"]', { 'sources!': [ '../src/gpu/gl/GrGLDefaultInterface_none.cpp', '../src/gpu/gl/GrGLCreateNativeInterface_none.cpp', ], }], + [ 'skia_angle', { + 'dependencies': [ + 'angle.gyp:*', + ], + 'export_dependent_settings': [ + 'angle.gyp:*', + ], + }, { # not skia_angle + 'sources!': [ + '<@(skgpu_angle_gl_sources)', + ], + }], + [ 'skia_command_buffer', { + }, { # not skia_command_buffer + 'sources!': [ + '<@(skgpu_command_buffer_gl_sources)', + ], + }], [ 'skia_os == "android"', { 'sources!': [ '../src/gpu/gl/GrGLDefaultInterface_none.cpp', diff --git a/gyp/gpu.gypi b/gyp/gpu.gypi index bcc7def624..9e1f9118b4 100644 --- a/gyp/gpu.gypi +++ b/gyp/gpu.gypi @@ -318,7 +318,6 @@ '<(skia_src_path)/gpu/gl/GrGLContext.cpp', '<(skia_src_path)/gpu/gl/GrGLContext.h', '<(skia_src_path)/gpu/gl/GrGLCreateNativeInterface_none.cpp', - '<(skia_src_path)/gpu/gl/GrGLCreateNullInterface.cpp', '<(skia_src_path)/gpu/gl/GrGLDefaultInterface_none.cpp', '<(skia_src_path)/gpu/gl/GrGLDefines.h', '<(skia_src_path)/gpu/gl/GrGLGLSL.cpp', @@ -409,6 +408,8 @@ '<(skia_include_path)/gpu/SkGrPixelRef.h', '<(skia_include_path)/gpu/SkGrTexturePixelRef.h', + '<(skia_include_path)/gpu/gl/SkGLContext.h', + '<(skia_src_path)/gpu/SkGpuDevice.cpp', '<(skia_src_path)/gpu/SkGpuDevice.h', '<(skia_src_path)/gpu/SkGpuDevice_drawTexture.cpp', @@ -421,6 +422,8 @@ '<(skia_src_path)/image/SkImage_Gpu.cpp', '<(skia_src_path)/image/SkSurface_Gpu.h', '<(skia_src_path)/image/SkSurface_Gpu.cpp', + + '<(skia_src_path)/gpu/gl/SkGLContext.cpp' ], 'skgpu_vk_sources': [ '<(skia_include_path)/gpu/vk/GrVkBackendContext.h', @@ -498,6 +501,60 @@ '<(skia_src_path)/gpu/gl/egl/GrGLCreateNativeInterface_egl.cpp', '<(skia_src_path)/gpu/gl/iOS/GrGLCreateNativeInterface_iOS.cpp', '<(skia_src_path)/gpu/gl/android/GrGLCreateNativeInterface_android.cpp', + + # Sk files + '<(skia_src_path)/gpu/gl/mac/SkCreatePlatformGLContext_mac.cpp', + '<(skia_src_path)/gpu/gl/win/SkCreatePlatformGLContext_win.cpp', + '<(skia_src_path)/gpu/gl/glx/SkCreatePlatformGLContext_glx.cpp', + '<(skia_src_path)/gpu/gl/egl/SkCreatePlatformGLContext_egl.cpp', + '<(skia_src_path)/gpu/gl/iOS/SkCreatePlatformGLContext_iOS.mm', + ], + 'skgpu_mesa_gl_sources': [ + '<(skia_src_path)/gpu/gl/mesa/GrGLCreateMesaInterface.cpp', + + # Sk files + '<(skia_src_path)/gpu/gl/mesa/SkMesaGLContext.cpp', + '<(skia_src_path)/gpu/gl/mesa/SkMesaGLContext.h', + ], + 'skgpu_angle_gl_sources': [ + '<(skia_src_path)/gpu/gl/angle/GrGLCreateANGLEInterface.cpp', + + # Sk files + '<(skia_include_path)/gpu/gl/angle/SkANGLEGLContext.h', + '<(skia_src_path)/gpu/gl/angle/SkANGLEGLContext.cpp', + ], + 'skgpu_command_buffer_gl_sources': [ + # Sk files + '<(skia_include_path)/gpu/gl/command_buffer/SkCommandBufferGLContext.h', + '<(skia_src_path)/gpu/gl/command_buffer/SkCommandBufferGLContext.cpp', + ], + 'skgpu_debug_gl_sources': [ + '<(skia_src_path)/gpu/gl/debug/GrGLCreateDebugInterface.cpp', + '<(skia_src_path)/gpu/gl/debug/GrFakeRefObj.h', + '<(skia_src_path)/gpu/gl/debug/GrBufferObj.h', + '<(skia_src_path)/gpu/gl/debug/GrBufferObj.cpp', + '<(skia_src_path)/gpu/gl/debug/GrFBBindableObj.h', + '<(skia_src_path)/gpu/gl/debug/GrRenderBufferObj.h', + '<(skia_src_path)/gpu/gl/debug/GrTextureObj.h', + '<(skia_src_path)/gpu/gl/debug/GrTextureObj.cpp', + '<(skia_src_path)/gpu/gl/debug/GrTextureUnitObj.h', + '<(skia_src_path)/gpu/gl/debug/GrTextureUnitObj.cpp', + '<(skia_src_path)/gpu/gl/debug/GrFrameBufferObj.h', + '<(skia_src_path)/gpu/gl/debug/GrFrameBufferObj.cpp', + '<(skia_src_path)/gpu/gl/debug/GrShaderObj.h', + '<(skia_src_path)/gpu/gl/debug/GrShaderObj.cpp', + '<(skia_src_path)/gpu/gl/debug/GrProgramObj.h', + '<(skia_src_path)/gpu/gl/debug/GrProgramObj.cpp', + '<(skia_src_path)/gpu/gl/debug/GrVertexArrayObj.h', + + # Sk files + '<(skia_src_path)/gpu/gl/debug/SkDebugGLContext.cpp', + '<(skia_src_path)/gpu/gl/debug/SkDebugGLContext.h', + ], + 'skgpu_null_gl_sources': [ + '<(skia_src_path)/gpu/gl/GrGLCreateNullInterface.cpp', + '<(skia_src_path)/gpu/gl/SkNullGLContext.cpp', + '<(skia_include_path)/gpu/gl/SkNullGLContext.h', ], }, } diff --git a/gyp/gputest.gyp b/gyp/gputest.gyp index af812a1986..36db43403f 100644 --- a/gyp/gputest.gyp +++ b/gyp/gputest.gyp @@ -9,85 +9,28 @@ 'product_name': 'skia_skgputest', 'type': 'static_library', 'standalone_static_library': 1, + 'dependencies': [ + 'skia_lib.gyp:skia_lib', + ], 'include_dirs': [ - '../include/core', - '../include/config', '../include/gpu', '../include/private', '../include/utils', '../src/core', '../src/gpu', - '../src/utils', - '../tools/gpu', + '../../src/gpu', ], - 'all_dependent_settings': { + 'direct_dependent_settings': { 'include_dirs': [ - '../tools/gpu', + '../src/gpu', + '../../src/gpu', ], }, - 'dependencies': [ - 'gpu.gyp:skgpu', - ], 'sources': [ - ' fFenceSync; - SkPlatformGpuFence fFrameFences[kMaxFrameLag - 1]; - int fCurrentFenceIdx; + SkAutoTDelete fFenceSync; + SkPlatformGpuFence fFrameFences[kMaxFrameLag - 1]; + int fCurrentFenceIdx; /** Subclass provides the gl interface object if construction was * successful. */ @@ -126,16 +120,26 @@ private: friend class GLFenceSync; // For onPlatformGetProcAddress. }; - /** Creates platform-dependent GL context object. The shareContext parameter is in an optional - * context with which to share display lists. This should be a pointer to an GLContext created + * context with which to share display lists. This should be a pointer to an SkGLContext created * with SkCreatePlatformGLContext. NULL indicates that no sharing is to take place. Returns a valid * gl context object or NULL if such can not be created. * Note: If Skia embedder needs a custom GL context that sets up the GL interface, this function * should be implemented by the embedder. Otherwise, the default implementation for the platform * should be compiled in the library. */ -GLContext* CreatePlatformGLContext(GrGLStandard forcedGpuAPI, GLContext *shareContext = nullptr); +SK_API SkGLContext* SkCreatePlatformGLContext(GrGLStandard forcedGpuAPI, + SkGLContext* shareContext = nullptr); + +/** + * Helper macros for using the GL context through the GrGLInterface. Example: + * SK_GL(glCtx, GenTextures(1, &texID)); + */ +#define SK_GL(ctx, X) (ctx).gl()->fFunctions.f ## X; \ + SkASSERT(0 == (ctx).gl()->fFunctions.fGetError()) +#define SK_GL_RET(ctx, RET, X) (RET) = (ctx).gl()->fFunctions.f ## X; \ + SkASSERT(0 == (ctx).gl()->fFunctions.fGetError()) +#define SK_GL_NOERRCHECK(ctx, X) (ctx).gl()->fFunctions.f ## X +#define SK_GL_RET_NOERRCHECK(ctx, RET, X) (RET) = (ctx).gl()->fFunctions.f ## X -} // namespace sk_gpu_test #endif diff --git a/include/gpu/gl/SkNullGLContext.h b/include/gpu/gl/SkNullGLContext.h new file mode 100644 index 0000000000..5a2a73fd8f --- /dev/null +++ b/include/gpu/gl/SkNullGLContext.h @@ -0,0 +1,26 @@ + +/* + * Copyright 2011 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ +#ifndef SkNullGLContext_DEFINED +#define SkNullGLContext_DEFINED + +#include "gl/SkGLContext.h" + +class SK_API SkNullGLContext : public SkGLContext { +public: + ~SkNullGLContext() override; + static SkNullGLContext* Create(); + +private: + SkNullGLContext(); + + void onPlatformMakeCurrent() const override {}; + void onPlatformSwapBuffers() const override {} + GrGLFuncPtr onPlatformGetProcAddress(const char*) const override { return nullptr; } +}; + +#endif diff --git a/include/gpu/gl/angle/SkANGLEGLContext.h b/include/gpu/gl/angle/SkANGLEGLContext.h new file mode 100644 index 0000000000..ea5e877ca2 --- /dev/null +++ b/include/gpu/gl/angle/SkANGLEGLContext.h @@ -0,0 +1,61 @@ + +/* + * Copyright 2012 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ +#ifndef SkANGLEGLContext_DEFINED +#define SkANGLEGLContext_DEFINED + +#if SK_ANGLE + +#include "gl/SkGLContext.h" + +class SkANGLEGLContext : public SkGLContext { +public: + ~SkANGLEGLContext() override; +#ifdef SK_BUILD_FOR_WIN + static SkANGLEGLContext* CreateDirectX() { + SkANGLEGLContext* ctx = new SkANGLEGLContext(false); + if (!ctx->isValid()) { + delete ctx; + return NULL; + } + return ctx; + } +#endif + static SkANGLEGLContext* CreateOpenGL() { + SkANGLEGLContext* ctx = new SkANGLEGLContext(true); + if (!ctx->isValid()) { + delete ctx; + return NULL; + } + return ctx; + } + + GrEGLImage texture2DToEGLImage(GrGLuint texID) const override; + void destroyEGLImage(GrEGLImage) const override; + GrGLuint eglImageToExternalTexture(GrEGLImage) const override; + SkGLContext* createNew() const override; + + // The param is an EGLNativeDisplayType and the return is an EGLDispay. + static void* GetD3DEGLDisplay(void* nativeDisplay, bool useGLBackend); + +private: + SkANGLEGLContext(bool preferGLBackend); + void destroyGLContext(); + + void onPlatformMakeCurrent() const override; + void onPlatformSwapBuffers() const override; + GrGLFuncPtr onPlatformGetProcAddress(const char* name) const override; + + void* fContext; + void* fDisplay; + void* fSurface; + bool fIsGLBackend; +}; + +#endif + +#endif diff --git a/include/gpu/gl/command_buffer/SkCommandBufferGLContext.h b/include/gpu/gl/command_buffer/SkCommandBufferGLContext.h new file mode 100644 index 0000000000..47f3fd967a --- /dev/null +++ b/include/gpu/gl/command_buffer/SkCommandBufferGLContext.h @@ -0,0 +1,63 @@ + +/* + * Copyright 2015 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ +#ifndef SKCOMMANDBUFFERGLCONTEXT_DEFINED +#define SKCOMMANDBUFFERGLCONTEXT_DEFINED + +#if SK_COMMAND_BUFFER + +#include "gl/SkGLContext.h" + +class SkCommandBufferGLContext : public SkGLContext { +public: + ~SkCommandBufferGLContext() override; + + static SkCommandBufferGLContext* Create() { + SkCommandBufferGLContext* ctx = new SkCommandBufferGLContext; + if (!ctx->isValid()) { + delete ctx; + return nullptr; + } + return ctx; + } + + static SkCommandBufferGLContext* Create(void* nativeWindow, int msaaSampleCount) { + SkCommandBufferGLContext* ctx = new SkCommandBufferGLContext(nativeWindow, + msaaSampleCount); + if (!ctx->isValid()) { + delete ctx; + return nullptr; + } + return ctx; + } + + void presentCommandBuffer(); + + bool makeCurrent(); + int getStencilBits(); + int getSampleCount(); + +private: + SkCommandBufferGLContext(); + SkCommandBufferGLContext(void* nativeWindow, int msaaSampleCount); + void initializeGLContext(void* nativeWindow, const int* configAttribs, + const int* surfaceAttribs); + void destroyGLContext(); + + void onPlatformMakeCurrent() const override; + void onPlatformSwapBuffers() const override; + GrGLFuncPtr onPlatformGetProcAddress(const char* name) const override; + + void* fContext; + void* fDisplay; + void* fSurface; + void* fConfig; +}; + +#endif // SK_COMMAND_BUFFER + +#endif diff --git a/samplecode/SampleApp.cpp b/samplecode/SampleApp.cpp index 780eabd1e3..e0d152d97b 100644 --- a/samplecode/SampleApp.cpp +++ b/samplecode/SampleApp.cpp @@ -33,14 +33,11 @@ #include "sk_tool_utils.h" #if SK_SUPPORT_GPU -# include "gl/GrGLInterface.h" -# include "gl/GrGLUtil.h" -# include "GrRenderTarget.h" -# include "GrContext.h" -# include "SkGpuDevice.h" -# if SK_ANGLE -# include "gl/angle/GLContext_angle.h" -# endif +#include "gl/GrGLInterface.h" +#include "gl/GrGLUtil.h" +#include "GrRenderTarget.h" +#include "GrContext.h" +#include "SkGpuDevice.h" #else class GrContext; #endif @@ -236,7 +233,7 @@ public: break; #if SK_ANGLE case kANGLE_DeviceType: - glInterface.reset(sk_gpu_test::CreateANGLEGLInterface()); + glInterface.reset(GrGLCreateANGLEInterface()); break; #endif // SK_ANGLE #if SK_COMMAND_BUFFER diff --git a/tools/gpu/GrContextFactory.cpp b/src/gpu/GrContextFactory.cpp similarity index 79% rename from tools/gpu/GrContextFactory.cpp rename to src/gpu/GrContextFactory.cpp index 0cf0cc781a..00ae1226e8 100755 --- a/tools/gpu/GrContextFactory.cpp +++ b/src/gpu/GrContextFactory.cpp @@ -1,4 +1,3 @@ - /* * Copyright 2014 Google Inc. * @@ -7,23 +6,25 @@ */ #include "GrContextFactory.h" -#include "gl/GLContext.h" #if SK_ANGLE - #include "gl/angle/GLContext_angle.h" + #include "gl/angle/SkANGLEGLContext.h" #endif #if SK_COMMAND_BUFFER - #include "gl/command_buffer/GLContext_command_buffer.h" + #include "gl/command_buffer/SkCommandBufferGLContext.h" #endif -#include "gl/debug/DebugGLContext.h" +#include "gl/debug/SkDebugGLContext.h" #if SK_MESA - #include "gl/mesa/GLContext_mesa.h" + #include "gl/mesa/SkMesaGLContext.h" #endif -#include "gl/null/NullGLContext.h" +#if SK_VULKAN +#include "vk/GrVkBackendContext.h" +#endif +#include "gl/SkGLContext.h" +#include "gl/SkNullGLContext.h" #include "gl/GrGLGpu.h" #include "GrCaps.h" -namespace sk_gpu_test { GrContextFactory::GrContextFactory() { } GrContextFactory::GrContextFactory(const GrContextOptions& opts) @@ -73,43 +74,43 @@ GrContextFactory::ContextInfo GrContextFactory::getContextInfo(GLContextType typ return ContextInfo(context.fGrContext, context.fGLContext); } } - SkAutoTDelete glCtx; + SkAutoTDelete glCtx; SkAutoTUnref grCtx; switch (type) { case kNative_GLContextType: - glCtx.reset(CreatePlatformGLContext(kNone_GrGLStandard)); + glCtx.reset(SkCreatePlatformGLContext(kNone_GrGLStandard)); break; case kGL_GLContextType: - glCtx.reset(CreatePlatformGLContext(kGL_GrGLStandard)); + glCtx.reset(SkCreatePlatformGLContext(kGL_GrGLStandard)); break; case kGLES_GLContextType: - glCtx.reset(CreatePlatformGLContext(kGLES_GrGLStandard)); + glCtx.reset(SkCreatePlatformGLContext(kGLES_GrGLStandard)); break; #if SK_ANGLE #ifdef SK_BUILD_FOR_WIN case kANGLE_GLContextType: - glCtx.reset(CreateANGLEDirect3DGLContext()); + glCtx.reset(SkANGLEGLContext::CreateDirectX()); break; #endif case kANGLE_GL_GLContextType: - glCtx.reset(CreateANGLEOpenGLGLContext()); + glCtx.reset(SkANGLEGLContext::CreateOpenGL()); break; #endif #if SK_COMMAND_BUFFER case kCommandBuffer_GLContextType: - glCtx.reset(CommandBufferGLContext::Create()); + glCtx.reset(SkCommandBufferGLContext::Create()); break; #endif #if SK_MESA case kMESA_GLContextType: - glCtx.reset(CreateMesaGLContext()); + glCtx.reset(SkMesaGLContext::Create()); break; #endif case kNull_GLContextType: - glCtx.reset(CreateNullGLContext()); + glCtx.reset(SkNullGLContext::Create()); break; case kDebug_GLContextType: - glCtx.reset(CreateDebugGLContext()); + glCtx.reset(SkDebugGLContext::Create()); break; } if (nullptr == glCtx.get()) { @@ -128,14 +129,15 @@ GrContextFactory::ContextInfo GrContextFactory::getContextInfo(GLContextType typ } glCtx->makeCurrent(); - GrBackendContext p3dctx = reinterpret_cast(glInterface.get()); #ifdef SK_VULKAN if (kEnableNVPR_GLContextOptions & options) { return ContextInfo(); } else { + GrBackendContext p3dctx = reinterpret_cast(GrVkBackendContext::Create()); grCtx.reset(GrContext::Create(kVulkan_GrBackend, p3dctx, fGlobalOptions)); } #else + GrBackendContext p3dctx = reinterpret_cast(glInterface.get()); grCtx.reset(GrContext::Create(kOpenGL_GrBackend, p3dctx, fGlobalOptions)); #endif if (!grCtx.get()) { @@ -154,4 +156,3 @@ GrContextFactory::ContextInfo GrContextFactory::getContextInfo(GLContextType typ context.fOptions = options; return ContextInfo(context.fGrContext, context.fGLContext); } -} // namespace sk_gpu_test diff --git a/tools/gpu/GrContextFactory.h b/src/gpu/GrContextFactory.h similarity index 90% rename from tools/gpu/GrContextFactory.h rename to src/gpu/GrContextFactory.h index 7e5c10e039..7afa3108c6 100644 --- a/tools/gpu/GrContextFactory.h +++ b/src/gpu/GrContextFactory.h @@ -11,10 +11,9 @@ #include "GrContext.h" #include "GrContextOptions.h" -#include "gl/GLContext.h" +#include "gl/SkGLContext.h" #include "SkTArray.h" -namespace sk_gpu_test { /** * This is a simple class that is useful in test apps that use different * GrContexts backed by different types of GL contexts. It manages creating the @@ -110,11 +109,11 @@ public: struct ContextInfo { ContextInfo() : fGrContext(nullptr), fGLContext(nullptr) { } - ContextInfo(GrContext* grContext, GLContext* glContext) + ContextInfo(GrContext* grContext, SkGLContext* glContext) : fGrContext(grContext), fGLContext(glContext) { } GrContext* fGrContext; - GLContext* fGLContext; //! Valid until the factory destroys it via abandonContexts() or - //! destroyContexts(). + SkGLContext* fGLContext; //! Valid until the factory destroys it via abandonContexts() or + //! destroyContexts(). }; /** @@ -133,13 +132,13 @@ public: private: struct Context { - GLContextType fType; - GLContextOptions fOptions; - GLContext* fGLContext; - GrContext* fGrContext; + GLContextType fType; + GLContextOptions fOptions; + SkGLContext* fGLContext; + GrContext* fGrContext; }; SkTArray fContexts; const GrContextOptions fGlobalOptions; }; -} // namespace sk_gpu_test + #endif diff --git a/tools/gpu/GrTest.cpp b/src/gpu/GrTest.cpp similarity index 100% rename from tools/gpu/GrTest.cpp rename to src/gpu/GrTest.cpp diff --git a/tools/gpu/GrTest.h b/src/gpu/GrTest.h similarity index 100% rename from tools/gpu/GrTest.h rename to src/gpu/GrTest.h diff --git a/src/gpu/gl/GrGLTestInterface.h b/src/gpu/gl/GrGLTestInterface.h index 936d9b8a97..c5f91ee195 100644 --- a/src/gpu/gl/GrGLTestInterface.h +++ b/src/gpu/gl/GrGLTestInterface.h @@ -11,10 +11,6 @@ #include "gl/GrGLInterface.h" #include "GrGLDefines.h" -/** - * Base class for interfaces used for Skia testing. We would like to move this to tools/gpu/gl - * when Chromium is no longer using GrGLCreateNullInterface in its unit testing. - */ class GrGLTestInterface : public GrGLInterface { public: virtual GrGLvoid activeTexture(GrGLenum texture) {} diff --git a/tools/gpu/gl/GLContext.cpp b/src/gpu/gl/SkGLContext.cpp similarity index 81% rename from tools/gpu/gl/GLContext.cpp rename to src/gpu/gl/SkGLContext.cpp index ac0e310014..1f9011fbd9 100644 --- a/tools/gpu/gl/GLContext.cpp +++ b/src/gpu/gl/SkGLContext.cpp @@ -1,18 +1,16 @@ - /* * Copyright 2013 Google Inc. * * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. */ -#include "GLContext.h" -#include "gl/GrGLUtil.h" +#include "gl/SkGLContext.h" +#include "GrGLUtil.h" #include "SkGpuFenceSync.h" -namespace sk_gpu_test { -class GLContext::GLFenceSync : public SkGpuFenceSync { +class SkGLContext::GLFenceSync : public SkGpuFenceSync { public: - static GLFenceSync* CreateIfSupported(const GLContext*); + static GLFenceSync* CreateIfSupported(const SkGLContext*); SkPlatformGpuFence SK_WARN_UNUSED_RESULT insertFence() const override; bool waitFence(SkPlatformGpuFence fence, bool flush) const override; @@ -38,12 +36,12 @@ private: typedef SkGpuFenceSync INHERITED; }; -GLContext::GLContext() +SkGLContext::SkGLContext() : fCurrentFenceIdx(0) { memset(fFrameFences, 0, sizeof(fFrameFences)); } -GLContext::~GLContext() { +SkGLContext::~SkGLContext() { // Subclass should call teardown. #ifdef SK_DEBUG for (size_t i = 0; i < SK_ARRAY_COUNT(fFrameFences); i++) { @@ -54,13 +52,13 @@ GLContext::~GLContext() { SkASSERT(nullptr == fFenceSync.get()); } -void GLContext::init(const GrGLInterface* gl, SkGpuFenceSync* fenceSync) { +void SkGLContext::init(const GrGLInterface* gl, SkGpuFenceSync* fenceSync) { SkASSERT(!fGL.get()); fGL.reset(gl); fFenceSync.reset(fenceSync ? fenceSync : GLFenceSync::CreateIfSupported(this)); } -void GLContext::teardown() { +void SkGLContext::teardown() { if (fFenceSync) { for (size_t i = 0; i < SK_ARRAY_COUNT(fFrameFences); i++) { if (fFrameFences[i]) { @@ -74,15 +72,15 @@ void GLContext::teardown() { fGL.reset(nullptr); } -void GLContext::makeCurrent() const { +void SkGLContext::makeCurrent() const { this->onPlatformMakeCurrent(); } -void GLContext::swapBuffers() { +void SkGLContext::swapBuffers() { this->onPlatformSwapBuffers(); } -void GLContext::waitOnSyncOrSwap() { +void SkGLContext::waitOnSyncOrSwap() { if (!fFenceSync) { // Fallback on the platform SwapBuffers method for synchronization. This may have no effect. this->swapBuffers(); @@ -100,7 +98,7 @@ void GLContext::waitOnSyncOrSwap() { fCurrentFenceIdx = (fCurrentFenceIdx + 1) % SK_ARRAY_COUNT(fFrameFences); } -void GLContext::testAbandon() { +void SkGLContext::testAbandon() { if (fGL) { fGL->abandon(); } @@ -109,12 +107,12 @@ void GLContext::testAbandon() { } } -GLContext::GLFenceSync* GLContext::GLFenceSync::CreateIfSupported(const GLContext* ctx) { +SkGLContext::GLFenceSync* SkGLContext::GLFenceSync::CreateIfSupported(const SkGLContext* ctx) { SkAutoTDelete ret(new GLFenceSync); if (kGL_GrGLStandard == ctx->gl()->fStandard) { const GrGLubyte* versionStr; - GR_GL_CALL_RET(ctx->gl(), versionStr, GetString(GR_GL_VERSION)); + SK_GL_RET(*ctx, versionStr, GetString(GR_GL_VERSION)); GrGLVersion version = GrGLGetVersionFromString(reinterpret_cast(versionStr)); if (version < GR_GL_VER(3,2) && !ctx->gl()->hasExtension("GL_ARB_sync")) { return nullptr; @@ -144,23 +142,23 @@ GLContext::GLFenceSync* GLContext::GLFenceSync::CreateIfSupported(const GLContex return ret.release(); } -SkPlatformGpuFence GLContext::GLFenceSync::insertFence() const { +SkPlatformGpuFence SkGLContext::GLFenceSync::insertFence() const { return fGLFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0); } -bool GLContext::GLFenceSync::waitFence(SkPlatformGpuFence fence, bool flush) const { +bool SkGLContext::GLFenceSync::waitFence(SkPlatformGpuFence fence, bool flush) const { GLsync glsync = static_cast(fence); return GL_WAIT_FAILED != fGLClientWaitSync(glsync, flush ? GL_SYNC_FLUSH_COMMANDS_BIT : 0, -1); } -void GLContext::GLFenceSync::deleteFence(SkPlatformGpuFence fence) const { +void SkGLContext::GLFenceSync::deleteFence(SkPlatformGpuFence fence) const { GLsync glsync = static_cast(fence); fGLDeleteSync(glsync); } -GrGLint GLContext::createTextureRectangle(int width, int height, GrGLenum internalFormat, - GrGLenum externalFormat, GrGLenum externalType, - GrGLvoid* data) { +GrGLint SkGLContext::createTextureRectangle(int width, int height, GrGLenum internalFormat, + GrGLenum externalFormat, GrGLenum externalType, + GrGLvoid* data) { if (!(kGL_GrGLStandard == fGL->fStandard && GrGLGetVersion(fGL) >= GR_GL_VER(3, 1)) && !fGL->fExtensions.has("GL_ARB_texture_rectangle")) { return 0; @@ -178,11 +176,10 @@ GrGLint GLContext::createTextureRectangle(int width, int height, GrGLenum intern GR_GL_CALL(fGL, TexParameteri(GR_GL_TEXTURE_RECTANGLE, GR_GL_TEXTURE_MIN_FILTER, GR_GL_NEAREST)); GR_GL_CALL(fGL, TexParameteri(GR_GL_TEXTURE_RECTANGLE, GR_GL_TEXTURE_WRAP_S, - GR_GL_CLAMP_TO_EDGE)); + GR_GL_CLAMP_TO_EDGE)); GR_GL_CALL(fGL, TexParameteri(GR_GL_TEXTURE_RECTANGLE, GR_GL_TEXTURE_WRAP_T, GR_GL_CLAMP_TO_EDGE)); GR_GL_CALL(fGL, TexImage2D(GR_GL_TEXTURE_RECTANGLE, 0, internalFormat, width, height, 0, externalFormat, externalType, data)); return id; } -} // namespace sk_gpu_test diff --git a/src/gpu/gl/SkNullGLContext.cpp b/src/gpu/gl/SkNullGLContext.cpp new file mode 100644 index 0000000000..a2c5066273 --- /dev/null +++ b/src/gpu/gl/SkNullGLContext.cpp @@ -0,0 +1,26 @@ +/* + * Copyright 2011 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "gl/SkNullGLContext.h" +#include "gl/GrGLInterface.h" + +SkNullGLContext* SkNullGLContext::Create() { + SkNullGLContext* ctx = new SkNullGLContext; + if (!ctx->isValid()) { + delete ctx; + return nullptr; + } + return ctx; +} + +SkNullGLContext::SkNullGLContext() { + this->init(GrGLCreateNullInterface()); +} + +SkNullGLContext::~SkNullGLContext() { + this->teardown(); +} diff --git a/src/gpu/gl/angle/GrGLCreateANGLEInterface.cpp b/src/gpu/gl/angle/GrGLCreateANGLEInterface.cpp new file mode 100644 index 0000000000..48f9d8c8ff --- /dev/null +++ b/src/gpu/gl/angle/GrGLCreateANGLEInterface.cpp @@ -0,0 +1,57 @@ +/* + * Copyright 2012 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "gl/GrGLInterface.h" +#include "gl/GrGLAssembleInterface.h" +#include "../ports/SkOSLibrary.h" + +#include + +namespace { +struct Libs { + void* fGLLib; + void* fEGLLib; +}; +} + +static GrGLFuncPtr angle_get_gl_proc(void* ctx, const char name[]) { + const Libs* libs = reinterpret_cast(ctx); + GrGLFuncPtr proc = (GrGLFuncPtr) GetProcedureAddress(libs->fGLLib, name); + if (proc) { + return proc; + } + proc = (GrGLFuncPtr) GetProcedureAddress(libs->fEGLLib, name); + if (proc) { + return proc; + } + return eglGetProcAddress(name); +} + +const GrGLInterface* GrGLCreateANGLEInterface() { + static Libs gLibs = { nullptr, nullptr }; + + if (nullptr == gLibs.fGLLib) { + // We load the ANGLE library and never let it go +#if defined _WIN32 + gLibs.fGLLib = DynamicLoadLibrary("libGLESv2.dll"); + gLibs.fEGLLib = DynamicLoadLibrary("libEGL.dll"); +#elif defined SK_BUILD_FOR_MAC + gLibs.fGLLib = DynamicLoadLibrary("libGLESv2.dylib"); + gLibs.fEGLLib = DynamicLoadLibrary("libEGL.dylib"); +#else + gLibs.fGLLib = DynamicLoadLibrary("libGLESv2.so"); + gLibs.fEGLLib = DynamicLoadLibrary("libEGL.so"); +#endif + } + + if (nullptr == gLibs.fGLLib || nullptr == gLibs.fEGLLib) { + // We can't setup the interface correctly w/o the so + return nullptr; + } + + return GrGLAssembleGLESInterface(&gLibs, angle_get_gl_proc); +} diff --git a/tools/gpu/gl/angle/GLContext_angle.cpp b/src/gpu/gl/angle/SkANGLEGLContext.cpp similarity index 58% rename from tools/gpu/gl/angle/GLContext_angle.cpp rename to src/gpu/gl/angle/SkANGLEGLContext.cpp index 0d7dfdb389..c6ea44381f 100644 --- a/tools/gpu/gl/angle/GLContext_angle.cpp +++ b/src/gpu/gl/angle/SkANGLEGLContext.cpp @@ -1,4 +1,3 @@ - /* * Copyright 2012 Google Inc. * @@ -6,7 +5,7 @@ * found in the LICENSE file. */ -#include "GLContext_angle.h" +#include "gl/angle/SkANGLEGLContext.h" #include #include @@ -14,57 +13,32 @@ #include "gl/GrGLDefines.h" #include "gl/GrGLUtil.h" -#include "gl/GrGLInterface.h" -#include "gl/GrGLAssembleInterface.h" -#include "../ports/SkOSLibrary.h" - -#include - #define EGL_PLATFORM_ANGLE_ANGLE 0x3202 #define EGL_PLATFORM_ANGLE_TYPE_ANGLE 0x3203 #define EGL_PLATFORM_ANGLE_TYPE_D3D9_ANGLE 0x3207 #define EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE 0x3208 #define EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE 0x320D -namespace { -struct Libs { - void* fGLLib; - void* fEGLLib; -}; - -static GrGLFuncPtr angle_get_gl_proc(void* ctx, const char name[]) { - const Libs* libs = reinterpret_cast(ctx); - GrGLFuncPtr proc = (GrGLFuncPtr) GetProcedureAddress(libs->fGLLib, name); - if (proc) { - return proc; - } - proc = (GrGLFuncPtr) GetProcedureAddress(libs->fEGLLib, name); - if (proc) { - return proc; - } - return eglGetProcAddress(name); -} - -void* get_angle_egl_display(void* nativeDisplay, bool useGLBackend) { +void* SkANGLEGLContext::GetD3DEGLDisplay(void* nativeDisplay, bool useGLBackend) { PFNEGLGETPLATFORMDISPLAYEXTPROC eglGetPlatformDisplayEXT; eglGetPlatformDisplayEXT = (PFNEGLGETPLATFORMDISPLAYEXTPROC)eglGetProcAddress("eglGetPlatformDisplayEXT"); - // We expect ANGLE to support this extension if (!eglGetPlatformDisplayEXT) { - return EGL_NO_DISPLAY; + return eglGetDisplay(static_cast(nativeDisplay)); } EGLDisplay display = EGL_NO_DISPLAY; if (useGLBackend) { + // Try for an ANGLE D3D11 context, fall back to D3D9. EGLint attribs[3] = { - EGL_PLATFORM_ANGLE_TYPE_ANGLE, - EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE, - EGL_NONE + EGL_PLATFORM_ANGLE_TYPE_ANGLE, + EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE, + EGL_NONE }; display = eglGetPlatformDisplayEXT(EGL_PLATFORM_ANGLE_ANGLE, nativeDisplay, attribs); } else { - // Try for an ANGLE D3D11 context, fall back to D3D9. + // Try for an ANGLE D3D11 context, fall back to D3D9, and finally GL. EGLint attribs[3][3] = { { EGL_PLATFORM_ANGLE_TYPE_ANGLE, @@ -76,6 +50,11 @@ void* get_angle_egl_display(void* nativeDisplay, bool useGLBackend) { EGL_PLATFORM_ANGLE_TYPE_D3D9_ANGLE, EGL_NONE }, + { + EGL_PLATFORM_ANGLE_TYPE_ANGLE, + EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE, + EGL_NONE + } }; for (int i = 0; i < 3 && display == EGL_NO_DISPLAY; ++i) { display = eglGetPlatformDisplayEXT(EGL_PLATFORM_ANGLE_ANGLE,nativeDisplay, attribs[i]); @@ -84,30 +63,7 @@ void* get_angle_egl_display(void* nativeDisplay, bool useGLBackend) { return display; } -class ANGLEGLContext : public sk_gpu_test::GLContext { -public: - ANGLEGLContext(bool preferGLBackend); - ~ANGLEGLContext() override; - - GrEGLImage texture2DToEGLImage(GrGLuint texID) const override; - void destroyEGLImage(GrEGLImage) const override; - GrGLuint eglImageToExternalTexture(GrEGLImage) const override; - sk_gpu_test::GLContext* createNew() const override; - -private: - void destroyGLContext(); - - void onPlatformMakeCurrent() const override; - void onPlatformSwapBuffers() const override; - GrGLFuncPtr onPlatformGetProcAddress(const char* name) const override; - - void* fContext; - void* fDisplay; - void* fSurface; - bool fIsGLBackend; -}; - -ANGLEGLContext::ANGLEGLContext(bool useGLBackend) +SkANGLEGLContext::SkANGLEGLContext(bool useGLBackend) : fContext(EGL_NO_CONTEXT) , fDisplay(EGL_NO_DISPLAY) , fSurface(EGL_NO_SURFACE) { @@ -124,7 +80,7 @@ ANGLEGLContext::ANGLEGLContext(bool useGLBackend) }; fIsGLBackend = useGLBackend; - fDisplay = get_angle_egl_display(EGL_DEFAULT_DISPLAY, useGLBackend); + fDisplay = GetD3DEGLDisplay(EGL_DEFAULT_DISPLAY, useGLBackend); if (EGL_NO_DISPLAY == fDisplay) { SkDebugf("Could not create EGL display!"); return; @@ -154,7 +110,7 @@ ANGLEGLContext::ANGLEGLContext(bool useGLBackend) eglMakeCurrent(fDisplay, fSurface, fSurface, fContext); - SkAutoTUnref gl(sk_gpu_test::CreateANGLEGLInterface()); + SkAutoTUnref gl(GrGLCreateANGLEInterface()); if (nullptr == gl.get()) { SkDebugf("Could not create ANGLE GL interface!\n"); this->destroyGLContext(); @@ -169,12 +125,12 @@ ANGLEGLContext::ANGLEGLContext(bool useGLBackend) this->init(gl.release()); } -ANGLEGLContext::~ANGLEGLContext() { +SkANGLEGLContext::~SkANGLEGLContext() { this->teardown(); this->destroyGLContext(); } -GrEGLImage ANGLEGLContext::texture2DToEGLImage(GrGLuint texID) const { +GrEGLImage SkANGLEGLContext::texture2DToEGLImage(GrGLuint texID) const { if (!this->gl()->hasExtension("EGL_KHR_gl_texture_2D_image")) { return GR_EGL_NO_IMAGE; } @@ -190,16 +146,17 @@ GrEGLImage ANGLEGLContext::texture2DToEGLImage(GrGLuint texID) const { return img; } -void ANGLEGLContext::destroyEGLImage(GrEGLImage image) const { +void SkANGLEGLContext::destroyEGLImage(GrEGLImage image) const { GR_GL_CALL(this->gl(), EGLDestroyImage(fDisplay, image)); } -GrGLuint ANGLEGLContext::eglImageToExternalTexture(GrEGLImage image) const { +GrGLuint SkANGLEGLContext::eglImageToExternalTexture(GrEGLImage image) const { GrGLClearErr(this->gl()); if (!this->gl()->hasExtension("GL_OES_EGL_image_external")) { return 0; } typedef GrGLvoid (*EGLImageTargetTexture2DProc)(GrGLenum, GrGLeglImage); + EGLImageTargetTexture2DProc glEGLImageTargetTexture2D = (EGLImageTargetTexture2DProc)eglGetProcAddress("glEGLImageTargetTexture2DOES"); if (!glEGLImageTargetTexture2D) { @@ -223,12 +180,12 @@ GrGLuint ANGLEGLContext::eglImageToExternalTexture(GrEGLImage image) const { return texID; } -sk_gpu_test::GLContext* ANGLEGLContext::createNew() const { +SkGLContext* SkANGLEGLContext::createNew() const { #ifdef SK_BUILD_FOR_WIN - sk_gpu_test::GLContext* ctx = fIsGLBackend ? sk_gpu_test::CreateANGLEOpenGLGLContext() - : sk_gpu_test::CreateANGLEDirect3DGLContext(); + SkGLContext* ctx = fIsGLBackend ? SkANGLEGLContext::CreateOpenGL() + : SkANGLEGLContext::CreateDirectX(); #else - sk_gpu_test::GLContext* ctx = sk_gpu_test::CreateANGLEOpenGLGLContext(); + SkGLContext* ctx = SkANGLEGLContext::CreateOpenGL(); #endif if (ctx) { ctx->makeCurrent(); @@ -236,7 +193,7 @@ sk_gpu_test::GLContext* ANGLEGLContext::createNew() const { return ctx; } -void ANGLEGLContext::destroyGLContext() { +void SkANGLEGLContext::destroyGLContext() { if (fDisplay) { eglMakeCurrent(fDisplay, 0, 0, 0); @@ -255,66 +212,18 @@ void ANGLEGLContext::destroyGLContext() { } } -void ANGLEGLContext::onPlatformMakeCurrent() const { +void SkANGLEGLContext::onPlatformMakeCurrent() const { if (!eglMakeCurrent(fDisplay, fSurface, fSurface, fContext)) { SkDebugf("Could not set the context.\n"); } } -void ANGLEGLContext::onPlatformSwapBuffers() const { +void SkANGLEGLContext::onPlatformSwapBuffers() const { if (!eglSwapBuffers(fDisplay, fSurface)) { SkDebugf("Could not complete eglSwapBuffers.\n"); } } -GrGLFuncPtr ANGLEGLContext::onPlatformGetProcAddress(const char* name) const { +GrGLFuncPtr SkANGLEGLContext::onPlatformGetProcAddress(const char* name) const { return eglGetProcAddress(name); } -} // anonymous namespace - -namespace sk_gpu_test { -const GrGLInterface* CreateANGLEGLInterface() { - static Libs gLibs = { nullptr, nullptr }; - - if (nullptr == gLibs.fGLLib) { - // We load the ANGLE library and never let it go -#if defined _WIN32 - gLibs.fGLLib = DynamicLoadLibrary("libGLESv2.dll"); - gLibs.fEGLLib = DynamicLoadLibrary("libEGL.dll"); -#elif defined SK_BUILD_FOR_MAC - gLibs.fGLLib = DynamicLoadLibrary("libGLESv2.dylib"); - gLibs.fEGLLib = DynamicLoadLibrary("libEGL.dylib"); -#else - gLibs.fGLLib = DynamicLoadLibrary("libGLESv2.so"); - gLibs.fEGLLib = DynamicLoadLibrary("libEGL.so"); -#endif - } - - if (nullptr == gLibs.fGLLib || nullptr == gLibs.fEGLLib) { - // We can't setup the interface correctly w/o the so - return nullptr; - } - - return GrGLAssembleGLESInterface(&gLibs, angle_get_gl_proc); -} - -#ifdef SK_BUILD_FOR_WIN -GLContext* CreateANGLEDirect3DGLContext() { - SkANGLEGLContext* ctx = new SkANGLEGLContext(false); - if (!ctx->isValid()) { - delete ctx; - return NULL; - } - return ctx; - } -#endif - -GLContext* CreateANGLEOpenGLGLContext() { - ANGLEGLContext* ctx = new ANGLEGLContext(true); - if (!ctx->isValid()) { - delete ctx; - return NULL; - } - return ctx; -} -} // namespace sk_gpu_test diff --git a/tools/gpu/gl/command_buffer/GLContext_command_buffer.cpp b/src/gpu/gl/command_buffer/SkCommandBufferGLContext.cpp similarity index 86% rename from tools/gpu/gl/command_buffer/GLContext_command_buffer.cpp rename to src/gpu/gl/command_buffer/SkCommandBufferGLContext.cpp index b878cb4aa9..516c155fcc 100644 --- a/tools/gpu/gl/command_buffer/GLContext_command_buffer.cpp +++ b/src/gpu/gl/command_buffer/SkCommandBufferGLContext.cpp @@ -1,15 +1,13 @@ - /* * Copyright 2015 Google Inc. * * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. */ - #include "SkOnce.h" #include "gl/GrGLInterface.h" #include "gl/GrGLAssembleInterface.h" -#include "gl/command_buffer/GLContext_command_buffer.h" +#include "gl/command_buffer/SkCommandBufferGLContext.h" #include "../ports/SkOSEnvironment.h" #include "../ports/SkOSLibrary.h" @@ -84,7 +82,6 @@ static GetProcAddressProc gfGetProcAddress = nullptr; static void* gLibrary = nullptr; static bool gfFunctionsLoadedSuccessfully = false; -namespace { static void load_command_buffer_functions() { if (!gLibrary) { #if defined _WIN32 @@ -127,24 +124,22 @@ static GrGLFuncPtr command_buffer_get_gl_proc(void* ctx, const char name[]) { } SK_DECLARE_STATIC_ONCE(loadCommandBufferOnce); -static void load_command_buffer_once() { +void LoadCommandBufferOnce() { SkOnce(&loadCommandBufferOnce, load_command_buffer_functions); } -static const GrGLInterface* create_command_buffer_interface() { - load_command_buffer_once(); +const GrGLInterface* GrGLCreateCommandBufferInterface() { + LoadCommandBufferOnce(); if (!gfFunctionsLoadedSuccessfully) { return nullptr; } return GrGLAssembleGLESInterface(gLibrary, command_buffer_get_gl_proc); } -} // anonymous namespace - -namespace sk_gpu_test { - -CommandBufferGLContext::CommandBufferGLContext() - : fContext(EGL_NO_CONTEXT), fDisplay(EGL_NO_DISPLAY), fSurface(EGL_NO_SURFACE) { +SkCommandBufferGLContext::SkCommandBufferGLContext() + : fContext(EGL_NO_CONTEXT) + , fDisplay(EGL_NO_DISPLAY) + , fSurface(EGL_NO_SURFACE) { static const EGLint configAttribs[] = { EGL_SURFACE_TYPE, EGL_PBUFFER_BIT, @@ -165,18 +160,18 @@ CommandBufferGLContext::CommandBufferGLContext() initializeGLContext(nullptr, configAttribs, surfaceAttribs); } -CommandBufferGLContext::CommandBufferGLContext(void *nativeWindow, int msaaSampleCount) { - static const EGLint surfaceAttribs[] = {EGL_NONE}; +SkCommandBufferGLContext::SkCommandBufferGLContext(void* nativeWindow, int msaaSampleCount) { + static const EGLint surfaceAttribs[] = { EGL_NONE }; EGLint configAttribs[] = { - EGL_RED_SIZE, 8, - EGL_GREEN_SIZE, 8, - EGL_BLUE_SIZE, 8, - EGL_ALPHA_SIZE, 8, - EGL_DEPTH_SIZE, 8, - EGL_STENCIL_SIZE, 8, + EGL_RED_SIZE, 8, + EGL_GREEN_SIZE, 8, + EGL_BLUE_SIZE, 8, + EGL_ALPHA_SIZE, 8, + EGL_DEPTH_SIZE, 8, + EGL_STENCIL_SIZE, 8, EGL_SAMPLE_BUFFERS, 1, - EGL_SAMPLES, msaaSampleCount, + EGL_SAMPLES, msaaSampleCount, EGL_NONE }; if (msaaSampleCount == 0) { @@ -186,9 +181,9 @@ CommandBufferGLContext::CommandBufferGLContext(void *nativeWindow, int msaaSampl initializeGLContext(nativeWindow, configAttribs, surfaceAttribs); } -void CommandBufferGLContext::initializeGLContext(void *nativeWindow, const int *configAttribs, - const int *surfaceAttribs) { - load_command_buffer_once(); +void SkCommandBufferGLContext::initializeGLContext(void* nativeWindow, const int* configAttribs, + const int* surfaceAttribs) { + LoadCommandBufferOnce(); if (!gfFunctionsLoadedSuccessfully) { SkDebugf("Command Buffer: Could not load EGL functions.\n"); return; @@ -211,7 +206,7 @@ void CommandBufferGLContext::initializeGLContext(void *nativeWindow, const int * } EGLint numConfigs; - if (!gfChooseConfig(fDisplay, configAttribs, static_cast(&fConfig), 1, + if (!gfChooseConfig(fDisplay, configAttribs, static_cast(&fConfig), 1, &numConfigs) || numConfigs != 1) { SkDebugf("Command Buffer: Could not choose EGL config.\n"); this->destroyGLContext(); @@ -221,7 +216,7 @@ void CommandBufferGLContext::initializeGLContext(void *nativeWindow, const int * if (nativeWindow) { fSurface = gfCreateWindowSurface(fDisplay, static_cast(fConfig), - (EGLNativeWindowType) nativeWindow, + (EGLNativeWindowType)nativeWindow, surfaceAttribs); } else { fSurface = gfCreatePbufferSurface(fDisplay, @@ -251,7 +246,7 @@ void CommandBufferGLContext::initializeGLContext(void *nativeWindow, const int * return; } - SkAutoTUnref gl(create_command_buffer_interface()); + SkAutoTUnref gl(GrGLCreateCommandBufferInterface()); if (nullptr == gl.get()) { SkDebugf("Command Buffer: Could not create CommandBuffer GL interface.\n"); this->destroyGLContext(); @@ -266,12 +261,12 @@ void CommandBufferGLContext::initializeGLContext(void *nativeWindow, const int * this->init(gl.release()); } -CommandBufferGLContext::~CommandBufferGLContext() { +SkCommandBufferGLContext::~SkCommandBufferGLContext() { this->teardown(); this->destroyGLContext(); } -void CommandBufferGLContext::destroyGLContext() { +void SkCommandBufferGLContext::destroyGLContext() { if (!gfFunctionsLoadedSuccessfully) { return; } @@ -293,7 +288,7 @@ void CommandBufferGLContext::destroyGLContext() { } } -void CommandBufferGLContext::onPlatformMakeCurrent() const { +void SkCommandBufferGLContext::onPlatformMakeCurrent() const { if (!gfFunctionsLoadedSuccessfully) { return; } @@ -302,7 +297,7 @@ void CommandBufferGLContext::onPlatformMakeCurrent() const { } } -void CommandBufferGLContext::onPlatformSwapBuffers() const { +void SkCommandBufferGLContext::onPlatformSwapBuffers() const { if (!gfFunctionsLoadedSuccessfully) { return; } @@ -311,14 +306,14 @@ void CommandBufferGLContext::onPlatformSwapBuffers() const { } } -GrGLFuncPtr CommandBufferGLContext::onPlatformGetProcAddress(const char *name) const { +GrGLFuncPtr SkCommandBufferGLContext::onPlatformGetProcAddress(const char* name) const { if (!gfFunctionsLoadedSuccessfully) { return nullptr; } return gfGetProcAddress(name); } -void CommandBufferGLContext::presentCommandBuffer() { +void SkCommandBufferGLContext::presentCommandBuffer() { if (this->gl()) { this->gl()->fFunctions.fFlush(); } @@ -326,20 +321,18 @@ void CommandBufferGLContext::presentCommandBuffer() { this->onPlatformSwapBuffers(); } -bool CommandBufferGLContext::makeCurrent() { +bool SkCommandBufferGLContext::makeCurrent() { return gfMakeCurrent(fDisplay, fSurface, fSurface, fContext) != EGL_FALSE; } -int CommandBufferGLContext::getStencilBits() { +int SkCommandBufferGLContext::getStencilBits() { EGLint result = 0; gfGetConfigAttrib(fDisplay, static_cast(fConfig), EGL_STENCIL_SIZE, &result); return result; } -int CommandBufferGLContext::getSampleCount() { +int SkCommandBufferGLContext::getSampleCount() { EGLint result = 0; gfGetConfigAttrib(fDisplay, static_cast(fConfig), EGL_SAMPLES, &result); return result; } - -} // namespace sk_gpu_test diff --git a/tools/gpu/gl/debug/GrBufferObj.cpp b/src/gpu/gl/debug/GrBufferObj.cpp similarity index 99% rename from tools/gpu/gl/debug/GrBufferObj.cpp rename to src/gpu/gl/debug/GrBufferObj.cpp index 37d4438ef6..ee0993d6da 100644 --- a/tools/gpu/gl/debug/GrBufferObj.cpp +++ b/src/gpu/gl/debug/GrBufferObj.cpp @@ -1,4 +1,3 @@ - /* * Copyright 2012 Google Inc. * diff --git a/tools/gpu/gl/debug/GrBufferObj.h b/src/gpu/gl/debug/GrBufferObj.h similarity index 98% rename from tools/gpu/gl/debug/GrBufferObj.h rename to src/gpu/gl/debug/GrBufferObj.h index 96aef6ed0a..5b5015be96 100644 --- a/tools/gpu/gl/debug/GrBufferObj.h +++ b/src/gpu/gl/debug/GrBufferObj.h @@ -1,4 +1,3 @@ - /* * Copyright 2012 Google Inc. * @@ -10,7 +9,7 @@ #define GrBufferObj_DEFINED #include "GrFakeRefObj.h" -#include "gl/GrGLDefines.h" +#include "../GrGLDefines.h" //////////////////////////////////////////////////////////////////////////////// class GrBufferObj : public GrFakeRefObj { diff --git a/tools/gpu/gl/debug/GrFBBindableObj.h b/src/gpu/gl/debug/GrFBBindableObj.h similarity index 99% rename from tools/gpu/gl/debug/GrFBBindableObj.h rename to src/gpu/gl/debug/GrFBBindableObj.h index e2b43a6a1b..2d490ef08b 100644 --- a/tools/gpu/gl/debug/GrFBBindableObj.h +++ b/src/gpu/gl/debug/GrFBBindableObj.h @@ -1,4 +1,3 @@ - /* * Copyright 2012 Google Inc. * diff --git a/tools/gpu/gl/debug/GrFakeRefObj.h b/src/gpu/gl/debug/GrFakeRefObj.h similarity index 100% rename from tools/gpu/gl/debug/GrFakeRefObj.h rename to src/gpu/gl/debug/GrFakeRefObj.h diff --git a/tools/gpu/gl/debug/GrFrameBufferObj.cpp b/src/gpu/gl/debug/GrFrameBufferObj.cpp similarity index 99% rename from tools/gpu/gl/debug/GrFrameBufferObj.cpp rename to src/gpu/gl/debug/GrFrameBufferObj.cpp index 7dc12acafb..a8acc3de23 100644 --- a/tools/gpu/gl/debug/GrFrameBufferObj.cpp +++ b/src/gpu/gl/debug/GrFrameBufferObj.cpp @@ -1,4 +1,3 @@ - /* * Copyright 2012 Google Inc. * diff --git a/tools/gpu/gl/debug/GrFrameBufferObj.h b/src/gpu/gl/debug/GrFrameBufferObj.h similarity index 99% rename from tools/gpu/gl/debug/GrFrameBufferObj.h rename to src/gpu/gl/debug/GrFrameBufferObj.h index 42a0effe07..40e123e49f 100644 --- a/tools/gpu/gl/debug/GrFrameBufferObj.h +++ b/src/gpu/gl/debug/GrFrameBufferObj.h @@ -1,4 +1,3 @@ - /* * Copyright 2012 Google Inc. * diff --git a/tools/gpu/gl/debug/DebugGLContext.cpp b/src/gpu/gl/debug/GrGLCreateDebugInterface.cpp similarity index 76% rename from tools/gpu/gl/debug/DebugGLContext.cpp rename to src/gpu/gl/debug/GrGLCreateDebugInterface.cpp index f4cbbea680..02b5cf704d 100644 --- a/tools/gpu/gl/debug/DebugGLContext.cpp +++ b/src/gpu/gl/debug/GrGLCreateDebugInterface.cpp @@ -1,4 +1,3 @@ - /* * Copyright 2012 Google Inc. * @@ -6,7 +5,8 @@ * found in the LICENSE file. */ -#include "DebugGLContext.h" + +#include "gl/GrGLInterface.h" #include "GrBufferObj.h" #include "GrFrameBufferObj.h" @@ -217,254 +217,254 @@ public: } } - GrGLvoid useProgram(GrGLuint programID) override { + GrGLvoid useProgram(GrGLuint programID) override { - // A programID of 0 is legal - GrProgramObj *program = FIND(programID, GrProgramObj, kProgram_ObjTypes); + // A programID of 0 is legal + GrProgramObj *program = FIND(programID, GrProgramObj, kProgram_ObjTypes); - this->useProgram(program); - } + this->useProgram(program); + } - GrGLvoid bindFramebuffer(GrGLenum target, GrGLuint frameBufferID) override { + GrGLvoid bindFramebuffer(GrGLenum target, GrGLuint frameBufferID) override { - GrAlwaysAssert(GR_GL_FRAMEBUFFER == target || - GR_GL_READ_FRAMEBUFFER == target || - GR_GL_DRAW_FRAMEBUFFER); + GrAlwaysAssert(GR_GL_FRAMEBUFFER == target || + GR_GL_READ_FRAMEBUFFER == target || + GR_GL_DRAW_FRAMEBUFFER); - // a frameBufferID of 0 is acceptable - it binds to the default - // frame buffer - GrFrameBufferObj *frameBuffer = FIND(frameBufferID, GrFrameBufferObj, + // a frameBufferID of 0 is acceptable - it binds to the default + // frame buffer + GrFrameBufferObj *frameBuffer = FIND(frameBufferID, GrFrameBufferObj, + kFrameBuffer_ObjTypes); + + this->setFrameBuffer(frameBuffer); + } + + GrGLvoid bindRenderbuffer(GrGLenum target, GrGLuint renderBufferID) override { + + GrAlwaysAssert(GR_GL_RENDERBUFFER == target); + + // a renderBufferID of 0 is acceptable - it unbinds the bound render buffer + GrRenderBufferObj *renderBuffer = FIND(renderBufferID, GrRenderBufferObj, + kRenderBuffer_ObjTypes); + + this->setRenderBuffer(renderBuffer); + } + + GrGLvoid deleteTextures(GrGLsizei n, const GrGLuint* textures) override { + // first potentially unbind the texture + for (unsigned int i = 0; i < kDefaultMaxTextureUnits; ++i) { + GrTextureUnitObj *pTU = this->getTextureUnit(i); + + if (pTU->getTexture()) { + for (int j = 0; j < n; ++j) { + + if (textures[j] == pTU->getTexture()->getID()) { + // this ID is the current texture - revert the binding to 0 + pTU->setTexture(nullptr); + } + } + } + } + + // TODO: fuse the following block with DeleteRenderBuffers? + // Open GL will remove a deleted render buffer from the active + // frame buffer but not from any other frame buffer + if (this->getFrameBuffer()) { + + GrFrameBufferObj *frameBuffer = this->getFrameBuffer(); + + for (int i = 0; i < n; ++i) { + + if (frameBuffer->getColor() && + textures[i] == frameBuffer->getColor()->getID()) { + frameBuffer->setColor(nullptr); + } + if (frameBuffer->getDepth() && + textures[i] == frameBuffer->getDepth()->getID()) { + frameBuffer->setDepth(nullptr); + } + if (frameBuffer->getStencil() && + textures[i] == frameBuffer->getStencil()->getID()) { + frameBuffer->setStencil(nullptr); + } + } + } + + // then actually "delete" the buffers + for (int i = 0; i < n; ++i) { + GrTextureObj *buffer = FIND(textures[i], GrTextureObj, kTexture_ObjTypes); + GrAlwaysAssert(buffer); + + // OpenGL gives no guarantees if a texture is deleted while attached to + // something other than the currently bound frame buffer + GrAlwaysAssert(!buffer->getBound()); + + GrAlwaysAssert(!buffer->getDeleted()); + buffer->deleteAction(); + } + + } + + GrGLvoid deleteFramebuffers(GrGLsizei n, const GrGLuint *frameBuffers) override { + + // first potentially unbind the buffers + if (this->getFrameBuffer()) { + for (int i = 0; i < n; ++i) { + + if (frameBuffers[i] == + this->getFrameBuffer()->getID()) { + // this ID is the current frame buffer - rebind to the default + this->setFrameBuffer(nullptr); + } + } + } + + // then actually "delete" the buffers + for (int i = 0; i < n; ++i) { + GrFrameBufferObj *buffer = FIND(frameBuffers[i], GrFrameBufferObj, kFrameBuffer_ObjTypes); + GrAlwaysAssert(buffer); - this->setFrameBuffer(frameBuffer); - } + GrAlwaysAssert(!buffer->getDeleted()); + buffer->deleteAction(); + } + } - GrGLvoid bindRenderbuffer(GrGLenum target, GrGLuint renderBufferID) override { + GrGLvoid deleteRenderbuffers(GrGLsizei n,const GrGLuint *renderBuffers) override { - GrAlwaysAssert(GR_GL_RENDERBUFFER == target); + // first potentially unbind the buffers + if (this->getRenderBuffer()) { + for (int i = 0; i < n; ++i) { - // a renderBufferID of 0 is acceptable - it unbinds the bound render buffer - GrRenderBufferObj *renderBuffer = FIND(renderBufferID, GrRenderBufferObj, - kRenderBuffer_ObjTypes); + if (renderBuffers[i] == + this->getRenderBuffer()->getID()) { + // this ID is the current render buffer - make no + // render buffer be bound + this->setRenderBuffer(nullptr); + } + } + } - this->setRenderBuffer(renderBuffer); - } + // TODO: fuse the following block with DeleteTextures? + // Open GL will remove a deleted render buffer from the active frame + // buffer but not from any other frame buffer + if (this->getFrameBuffer()) { - GrGLvoid deleteTextures(GrGLsizei n, const GrGLuint* textures) override { - // first potentially unbind the texture - for (unsigned int i = 0; i < kDefaultMaxTextureUnits; ++i) { - GrTextureUnitObj *pTU = this->getTextureUnit(i); + GrFrameBufferObj *frameBuffer = this->getFrameBuffer(); - if (pTU->getTexture()) { - for (int j = 0; j < n; ++j) { + for (int i = 0; i < n; ++i) { - if (textures[j] == pTU->getTexture()->getID()) { - // this ID is the current texture - revert the binding to 0 - pTU->setTexture(nullptr); - } - } - } - } + if (frameBuffer->getColor() && + renderBuffers[i] == frameBuffer->getColor()->getID()) { + frameBuffer->setColor(nullptr); + } + if (frameBuffer->getDepth() && + renderBuffers[i] == frameBuffer->getDepth()->getID()) { + frameBuffer->setDepth(nullptr); + } + if (frameBuffer->getStencil() && + renderBuffers[i] == frameBuffer->getStencil()->getID()) { + frameBuffer->setStencil(nullptr); + } + } + } - // TODO: fuse the following block with DeleteRenderBuffers? - // Open GL will remove a deleted render buffer from the active - // frame buffer but not from any other frame buffer - if (this->getFrameBuffer()) { + // then actually "delete" the buffers + for (int i = 0; i < n; ++i) { + GrRenderBufferObj *buffer = FIND(renderBuffers[i], GrRenderBufferObj, + kRenderBuffer_ObjTypes); + GrAlwaysAssert(buffer); - GrFrameBufferObj *frameBuffer = this->getFrameBuffer(); + // OpenGL gives no guarantees if a render buffer is deleted + // while attached to something other than the currently + // bound frame buffer + GrAlwaysAssert(!buffer->getColorBound()); + GrAlwaysAssert(!buffer->getDepthBound()); + // However, at GrContext destroy time we release all GrRsources and so stencil buffers + // may get deleted before FBOs that refer to them. + //GrAlwaysAssert(!buffer->getStencilBound()); - for (int i = 0; i < n; ++i) { + GrAlwaysAssert(!buffer->getDeleted()); + buffer->deleteAction(); + } + } - if (frameBuffer->getColor() && - textures[i] == frameBuffer->getColor()->getID()) { - frameBuffer->setColor(nullptr); - } - if (frameBuffer->getDepth() && - textures[i] == frameBuffer->getDepth()->getID()) { - frameBuffer->setDepth(nullptr); - } - if (frameBuffer->getStencil() && - textures[i] == frameBuffer->getStencil()->getID()) { - frameBuffer->setStencil(nullptr); - } - } - } + GrGLvoid framebufferRenderbuffer(GrGLenum target, + GrGLenum attachment, + GrGLenum renderbuffertarget, + GrGLuint renderBufferID) override { - // then actually "delete" the buffers - for (int i = 0; i < n; ++i) { - GrTextureObj *buffer = FIND(textures[i], GrTextureObj, kTexture_ObjTypes); - GrAlwaysAssert(buffer); + GrAlwaysAssert(GR_GL_FRAMEBUFFER == target); + GrAlwaysAssert(GR_GL_COLOR_ATTACHMENT0 == attachment || + GR_GL_DEPTH_ATTACHMENT == attachment || + GR_GL_STENCIL_ATTACHMENT == attachment); + GrAlwaysAssert(GR_GL_RENDERBUFFER == renderbuffertarget); - // OpenGL gives no guarantees if a texture is deleted while attached to - // something other than the currently bound frame buffer - GrAlwaysAssert(!buffer->getBound()); + GrFrameBufferObj *framebuffer = this->getFrameBuffer(); + // A render buffer cannot be attached to the default framebuffer + GrAlwaysAssert(framebuffer); - GrAlwaysAssert(!buffer->getDeleted()); - buffer->deleteAction(); - } + // a renderBufferID of 0 is acceptable - it unbinds the current + // render buffer + GrRenderBufferObj *renderbuffer = FIND(renderBufferID, GrRenderBufferObj, + kRenderBuffer_ObjTypes); - } + switch (attachment) { + case GR_GL_COLOR_ATTACHMENT0: + framebuffer->setColor(renderbuffer); + break; + case GR_GL_DEPTH_ATTACHMENT: + framebuffer->setDepth(renderbuffer); + break; + case GR_GL_STENCIL_ATTACHMENT: + framebuffer->setStencil(renderbuffer); + break; + default: + GrAlwaysAssert(false); + break; + }; - GrGLvoid deleteFramebuffers(GrGLsizei n, const GrGLuint *frameBuffers) override { + } - // first potentially unbind the buffers - if (this->getFrameBuffer()) { - for (int i = 0; i < n; ++i) { + //////////////////////////////////////////////////////////////////////////////// + GrGLvoid framebufferTexture2D(GrGLenum target, GrGLenum attachment, GrGLenum textarget, + GrGLuint textureID, GrGLint level) override { - if (frameBuffers[i] == - this->getFrameBuffer()->getID()) { - // this ID is the current frame buffer - rebind to the default - this->setFrameBuffer(nullptr); - } - } - } + GrAlwaysAssert(GR_GL_FRAMEBUFFER == target); + GrAlwaysAssert(GR_GL_COLOR_ATTACHMENT0 == attachment || + GR_GL_DEPTH_ATTACHMENT == attachment || + GR_GL_STENCIL_ATTACHMENT == attachment); + GrAlwaysAssert(GR_GL_TEXTURE_2D == textarget); - // then actually "delete" the buffers - for (int i = 0; i < n; ++i) { - GrFrameBufferObj *buffer = FIND(frameBuffers[i], GrFrameBufferObj, - kFrameBuffer_ObjTypes); - GrAlwaysAssert(buffer); + GrFrameBufferObj *framebuffer = this->getFrameBuffer(); + // A texture cannot be attached to the default framebuffer + GrAlwaysAssert(framebuffer); - GrAlwaysAssert(!buffer->getDeleted()); - buffer->deleteAction(); - } - } + // A textureID of 0 is allowed - it unbinds the currently bound texture + GrTextureObj *texture = FIND(textureID, GrTextureObj, kTexture_ObjTypes); + if (texture) { + // The texture shouldn't be bound to a texture unit - this + // could lead to a feedback loop + GrAlwaysAssert(!texture->getBound()); + } - GrGLvoid deleteRenderbuffers(GrGLsizei n,const GrGLuint *renderBuffers) override { + GrAlwaysAssert(0 == level); - // first potentially unbind the buffers - if (this->getRenderBuffer()) { - for (int i = 0; i < n; ++i) { - - if (renderBuffers[i] == - this->getRenderBuffer()->getID()) { - // this ID is the current render buffer - make no - // render buffer be bound - this->setRenderBuffer(nullptr); - } - } - } - - // TODO: fuse the following block with DeleteTextures? - // Open GL will remove a deleted render buffer from the active frame - // buffer but not from any other frame buffer - if (this->getFrameBuffer()) { - - GrFrameBufferObj *frameBuffer = this->getFrameBuffer(); - - for (int i = 0; i < n; ++i) { - - if (frameBuffer->getColor() && - renderBuffers[i] == frameBuffer->getColor()->getID()) { - frameBuffer->setColor(nullptr); - } - if (frameBuffer->getDepth() && - renderBuffers[i] == frameBuffer->getDepth()->getID()) { - frameBuffer->setDepth(nullptr); - } - if (frameBuffer->getStencil() && - renderBuffers[i] == frameBuffer->getStencil()->getID()) { - frameBuffer->setStencil(nullptr); - } - } - } - - // then actually "delete" the buffers - for (int i = 0; i < n; ++i) { - GrRenderBufferObj *buffer = FIND(renderBuffers[i], GrRenderBufferObj, - kRenderBuffer_ObjTypes); - GrAlwaysAssert(buffer); - - // OpenGL gives no guarantees if a render buffer is deleted - // while attached to something other than the currently - // bound frame buffer - GrAlwaysAssert(!buffer->getColorBound()); - GrAlwaysAssert(!buffer->getDepthBound()); - // However, at GrContext destroy time we release all GrRsources and so stencil buffers - // may get deleted before FBOs that refer to them. - //GrAlwaysAssert(!buffer->getStencilBound()); - - GrAlwaysAssert(!buffer->getDeleted()); - buffer->deleteAction(); - } - } - - GrGLvoid framebufferRenderbuffer(GrGLenum target, - GrGLenum attachment, - GrGLenum renderbuffertarget, - GrGLuint renderBufferID) override { - - GrAlwaysAssert(GR_GL_FRAMEBUFFER == target); - GrAlwaysAssert(GR_GL_COLOR_ATTACHMENT0 == attachment || - GR_GL_DEPTH_ATTACHMENT == attachment || - GR_GL_STENCIL_ATTACHMENT == attachment); - GrAlwaysAssert(GR_GL_RENDERBUFFER == renderbuffertarget); - - GrFrameBufferObj *framebuffer = this->getFrameBuffer(); - // A render buffer cannot be attached to the default framebuffer - GrAlwaysAssert(framebuffer); - - // a renderBufferID of 0 is acceptable - it unbinds the current - // render buffer - GrRenderBufferObj *renderbuffer = FIND(renderBufferID, GrRenderBufferObj, - kRenderBuffer_ObjTypes); - - switch (attachment) { - case GR_GL_COLOR_ATTACHMENT0: - framebuffer->setColor(renderbuffer); - break; - case GR_GL_DEPTH_ATTACHMENT: - framebuffer->setDepth(renderbuffer); - break; - case GR_GL_STENCIL_ATTACHMENT: - framebuffer->setStencil(renderbuffer); - break; - default: - GrAlwaysAssert(false); - break; - }; - - } - - //////////////////////////////////////////////////////////////////////////////// - GrGLvoid framebufferTexture2D(GrGLenum target, GrGLenum attachment, GrGLenum textarget, - GrGLuint textureID, GrGLint level) override { - - GrAlwaysAssert(GR_GL_FRAMEBUFFER == target); - GrAlwaysAssert(GR_GL_COLOR_ATTACHMENT0 == attachment || - GR_GL_DEPTH_ATTACHMENT == attachment || - GR_GL_STENCIL_ATTACHMENT == attachment); - GrAlwaysAssert(GR_GL_TEXTURE_2D == textarget); - - GrFrameBufferObj *framebuffer = this->getFrameBuffer(); - // A texture cannot be attached to the default framebuffer - GrAlwaysAssert(framebuffer); - - // A textureID of 0 is allowed - it unbinds the currently bound texture - GrTextureObj *texture = FIND(textureID, GrTextureObj, kTexture_ObjTypes); - if (texture) { - // The texture shouldn't be bound to a texture unit - this - // could lead to a feedback loop - GrAlwaysAssert(!texture->getBound()); - } - - GrAlwaysAssert(0 == level); - - switch (attachment) { - case GR_GL_COLOR_ATTACHMENT0: - framebuffer->setColor(texture); - break; - case GR_GL_DEPTH_ATTACHMENT: - framebuffer->setDepth(texture); - break; - case GR_GL_STENCIL_ATTACHMENT: - framebuffer->setStencil(texture); - break; - default: - GrAlwaysAssert(false); - break; - }; - } + switch (attachment) { + case GR_GL_COLOR_ATTACHMENT0: + framebuffer->setColor(texture); + break; + case GR_GL_DEPTH_ATTACHMENT: + framebuffer->setDepth(texture); + break; + case GR_GL_STENCIL_ATTACHMENT: + framebuffer->setStencil(texture); + break; + default: + GrAlwaysAssert(false); + break; + }; + } GrGLuint createProgram() override { @@ -1229,28 +1229,8 @@ const char* DebugInterface::kExtensions[] = { nullptr, // signifies the end of the array. }; -class DebugGLContext : public sk_gpu_test::GLContext { -public: - DebugGLContext() { - this->init(new DebugInterface()); - } - - ~DebugGLContext() override { this->teardown(); } - -private: - void onPlatformMakeCurrent() const override {} - void onPlatformSwapBuffers() const override {} - GrGLFuncPtr onPlatformGetProcAddress(const char*) const override { return nullptr; } -}; } // anonymous namespace -namespace sk_gpu_test { -GLContext* CreateDebugGLContext() { - GLContext* ctx = new DebugGLContext(); - if (ctx->isValid()) { - return ctx; - } - delete ctx; - return nullptr; -} -} +//////////////////////////////////////////////////////////////////////////////// + +const GrGLInterface* GrGLCreateDebugInterface() { return new DebugInterface; } diff --git a/tools/gpu/gl/debug/GrProgramObj.cpp b/src/gpu/gl/debug/GrProgramObj.cpp similarity index 99% rename from tools/gpu/gl/debug/GrProgramObj.cpp rename to src/gpu/gl/debug/GrProgramObj.cpp index d6cc36bd74..d45bd1c113 100644 --- a/tools/gpu/gl/debug/GrProgramObj.cpp +++ b/src/gpu/gl/debug/GrProgramObj.cpp @@ -1,4 +1,3 @@ - /* * Copyright 2012 Google Inc. * diff --git a/tools/gpu/gl/debug/GrProgramObj.h b/src/gpu/gl/debug/GrProgramObj.h similarity index 99% rename from tools/gpu/gl/debug/GrProgramObj.h rename to src/gpu/gl/debug/GrProgramObj.h index a25341a215..6e5ec65d9d 100644 --- a/tools/gpu/gl/debug/GrProgramObj.h +++ b/src/gpu/gl/debug/GrProgramObj.h @@ -1,4 +1,3 @@ - /* * Copyright 2012 Google Inc. * diff --git a/tools/gpu/gl/debug/GrRenderBufferObj.h b/src/gpu/gl/debug/GrRenderBufferObj.h similarity index 99% rename from tools/gpu/gl/debug/GrRenderBufferObj.h rename to src/gpu/gl/debug/GrRenderBufferObj.h index 8231ef58df..dae08f5c78 100644 --- a/tools/gpu/gl/debug/GrRenderBufferObj.h +++ b/src/gpu/gl/debug/GrRenderBufferObj.h @@ -1,4 +1,3 @@ - /* * Copyright 2012 Google Inc. * diff --git a/tools/gpu/gl/debug/GrShaderObj.cpp b/src/gpu/gl/debug/GrShaderObj.cpp similarity index 99% rename from tools/gpu/gl/debug/GrShaderObj.cpp rename to src/gpu/gl/debug/GrShaderObj.cpp index 8d3caa1e3f..67cca3ed72 100644 --- a/tools/gpu/gl/debug/GrShaderObj.cpp +++ b/src/gpu/gl/debug/GrShaderObj.cpp @@ -1,4 +1,3 @@ - /* * Copyright 2012 Google Inc. * diff --git a/tools/gpu/gl/debug/GrShaderObj.h b/src/gpu/gl/debug/GrShaderObj.h similarity index 96% rename from tools/gpu/gl/debug/GrShaderObj.h rename to src/gpu/gl/debug/GrShaderObj.h index 327bd7f084..871494ac8d 100644 --- a/tools/gpu/gl/debug/GrShaderObj.h +++ b/src/gpu/gl/debug/GrShaderObj.h @@ -1,4 +1,3 @@ - /* * Copyright 2012 Google Inc. * @@ -10,7 +9,7 @@ #define GrShaderObj_DEFINED #include "GrFakeRefObj.h" -#include "gl/GrGLDefines.h" +#include "../GrGLDefines.h" //////////////////////////////////////////////////////////////////////////////// class GrShaderObj : public GrFakeRefObj { diff --git a/tools/gpu/gl/debug/GrTextureObj.cpp b/src/gpu/gl/debug/GrTextureObj.cpp similarity index 99% rename from tools/gpu/gl/debug/GrTextureObj.cpp rename to src/gpu/gl/debug/GrTextureObj.cpp index 86063fbc99..62cb399245 100644 --- a/tools/gpu/gl/debug/GrTextureObj.cpp +++ b/src/gpu/gl/debug/GrTextureObj.cpp @@ -1,4 +1,3 @@ - /* * Copyright 2012 Google Inc. * diff --git a/tools/gpu/gl/debug/GrTextureObj.h b/src/gpu/gl/debug/GrTextureObj.h similarity index 99% rename from tools/gpu/gl/debug/GrTextureObj.h rename to src/gpu/gl/debug/GrTextureObj.h index fcf851db86..bc649f3b38 100644 --- a/tools/gpu/gl/debug/GrTextureObj.h +++ b/src/gpu/gl/debug/GrTextureObj.h @@ -1,4 +1,3 @@ - /* * Copyright 2012 Google Inc. * diff --git a/tools/gpu/gl/debug/GrTextureUnitObj.cpp b/src/gpu/gl/debug/GrTextureUnitObj.cpp similarity index 99% rename from tools/gpu/gl/debug/GrTextureUnitObj.cpp rename to src/gpu/gl/debug/GrTextureUnitObj.cpp index 316dcecd93..8de0b092cd 100644 --- a/tools/gpu/gl/debug/GrTextureUnitObj.cpp +++ b/src/gpu/gl/debug/GrTextureUnitObj.cpp @@ -1,4 +1,3 @@ - /* * Copyright 2012 Google Inc. * diff --git a/tools/gpu/gl/debug/GrTextureUnitObj.h b/src/gpu/gl/debug/GrTextureUnitObj.h similarity index 100% rename from tools/gpu/gl/debug/GrTextureUnitObj.h rename to src/gpu/gl/debug/GrTextureUnitObj.h diff --git a/tools/gpu/gl/debug/GrVertexArrayObj.h b/src/gpu/gl/debug/GrVertexArrayObj.h similarity index 100% rename from tools/gpu/gl/debug/GrVertexArrayObj.h rename to src/gpu/gl/debug/GrVertexArrayObj.h diff --git a/src/gpu/gl/debug/SkDebugGLContext.cpp b/src/gpu/gl/debug/SkDebugGLContext.cpp new file mode 100644 index 0000000000..ecb27db95d --- /dev/null +++ b/src/gpu/gl/debug/SkDebugGLContext.cpp @@ -0,0 +1,16 @@ +/* + * Copyright 2012 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "gl/debug/SkDebugGLContext.h" + +SkDebugGLContext::SkDebugGLContext() { + this->init(GrGLCreateDebugInterface()); +} + +SkDebugGLContext::~SkDebugGLContext() { + this->teardown(); +} diff --git a/src/gpu/gl/debug/SkDebugGLContext.h b/src/gpu/gl/debug/SkDebugGLContext.h new file mode 100644 index 0000000000..1ea7b62931 --- /dev/null +++ b/src/gpu/gl/debug/SkDebugGLContext.h @@ -0,0 +1,27 @@ +/* + * Copyright 2012 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ +#ifndef SkDebugGLContext_DEFINED +#define SkDebugGLContext_DEFINED + +#include "gl/SkGLContext.h" + +class SkDebugGLContext : public SkGLContext { +public: + ~SkDebugGLContext() override; + + static SkDebugGLContext* Create() { + return new SkDebugGLContext; + } +private: + void onPlatformMakeCurrent() const override {} + void onPlatformSwapBuffers() const override {} + GrGLFuncPtr onPlatformGetProcAddress(const char*) const override { return nullptr; } + + SkDebugGLContext(); +}; + +#endif diff --git a/tools/gpu/gl/egl/CreatePlatformGLContext_egl.cpp b/src/gpu/gl/egl/SkCreatePlatformGLContext_egl.cpp similarity index 95% rename from tools/gpu/gl/egl/CreatePlatformGLContext_egl.cpp rename to src/gpu/gl/egl/SkCreatePlatformGLContext_egl.cpp index ac2e7ca7cf..1644254c09 100644 --- a/tools/gpu/gl/egl/CreatePlatformGLContext_egl.cpp +++ b/src/gpu/gl/egl/SkCreatePlatformGLContext_egl.cpp @@ -1,11 +1,10 @@ - /* * Copyright 2011 Google Inc. * * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. */ -#include "gl/GLContext.h" +#include "gl/SkGLContext.h" #include @@ -35,7 +34,7 @@ private: typedef SkGpuFenceSync INHERITED; }; -class EGLGLContext : public sk_gpu_test::GLContext { +class EGLGLContext : public SkGLContext { public: EGLGLContext(GrGLStandard forcedGpuAPI); ~EGLGLContext() override; @@ -43,7 +42,7 @@ public: GrEGLImage texture2DToEGLImage(GrGLuint texID) const override; void destroyEGLImage(GrEGLImage) const override; GrGLuint eglImageToExternalTexture(GrEGLImage) const override; - sk_gpu_test::GLContext* createNew() const override; + SkGLContext* createNew() const override; private: void destroyGLContext(); @@ -254,8 +253,8 @@ GrGLuint EGLGLContext::eglImageToExternalTexture(GrEGLImage image) const { return texID; } -sk_gpu_test::GLContext* EGLGLContext::createNew() const { - sk_gpu_test::GLContext* ctx = new EGLGLContext(this->gl()->fStandard); +SkGLContext* EGLGLContext::createNew() const { + SkGLContext* ctx = SkCreatePlatformGLContext(this->gl()->fStandard); if (ctx) { ctx->makeCurrent(); } @@ -318,20 +317,17 @@ void SkEGLFenceSync::deleteFence(SkPlatformGpuFence platformFence) const { eglDestroySyncKHR(fDisplay, eglsync); } -} // anonymous namespace +} // anonymous namespace -namespace sk_gpu_test { -GLContext *CreatePlatformGLContext(GrGLStandard forcedGpuAPI, GLContext *shareContext) { +SkGLContext* SkCreatePlatformGLContext(GrGLStandard forcedGpuAPI, SkGLContext* shareContext) { SkASSERT(!shareContext); if (shareContext) { return nullptr; } - EGLGLContext *ctx = new EGLGLContext(forcedGpuAPI); + EGLGLContext* ctx = new EGLGLContext(forcedGpuAPI); if (!ctx->isValid()) { delete ctx; return nullptr; } return ctx; } -} // namespace sk_gpu_test - diff --git a/tools/gpu/gl/glx/CreatePlatformGLContext_glx.cpp b/src/gpu/gl/glx/SkCreatePlatformGLContext_glx.cpp similarity index 97% rename from tools/gpu/gl/glx/CreatePlatformGLContext_glx.cpp rename to src/gpu/gl/glx/SkCreatePlatformGLContext_glx.cpp index b2168e3c5a..d0bd1de428 100644 --- a/tools/gpu/gl/glx/CreatePlatformGLContext_glx.cpp +++ b/src/gpu/gl/glx/SkCreatePlatformGLContext_glx.cpp @@ -1,11 +1,10 @@ - /* * Copyright 2011 Google Inc. * * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. */ -#include "gl/GLContext.h" +#include "gl/SkGLContext.h" #include #include @@ -44,7 +43,7 @@ static int ctxErrorHandler(Display *dpy, XErrorEvent *ev) { return 0; } -class GLXGLContext : public sk_gpu_test::GLContext { +class GLXGLContext : public SkGLContext { public: GLXGLContext(GrGLStandard forcedGpuAPI, GLXGLContext* shareList); ~GLXGLContext() override; @@ -331,11 +330,10 @@ GrGLFuncPtr GLXGLContext::onPlatformGetProcAddress(const char* procName) const { return glXGetProcAddress(reinterpret_cast(procName)); } -} // anonymous namespace +} // anonymous namespace -namespace sk_gpu_test { -GLContext *CreatePlatformGLContext(GrGLStandard forcedGpuAPI, GLContext *shareContext) { - GLXGLContext *glxShareContext = reinterpret_cast(shareContext); +SkGLContext* SkCreatePlatformGLContext(GrGLStandard forcedGpuAPI, SkGLContext* shareContext) { + GLXGLContext* glxShareContext = reinterpret_cast(shareContext); GLXGLContext *ctx = new GLXGLContext(forcedGpuAPI, glxShareContext); if (!ctx->isValid()) { delete ctx; @@ -343,4 +341,3 @@ GLContext *CreatePlatformGLContext(GrGLStandard forcedGpuAPI, GLContext *shareCo } return ctx; } -} // namespace sk_gpu_test diff --git a/tools/gpu/gl/iOS/CreatePlatformGLContext_iOS.mm b/src/gpu/gl/iOS/SkCreatePlatformGLContext_iOS.mm similarity index 89% rename from tools/gpu/gl/iOS/CreatePlatformGLContext_iOS.mm rename to src/gpu/gl/iOS/SkCreatePlatformGLContext_iOS.mm index d6507f280f..54dc59af03 100644 --- a/tools/gpu/gl/iOS/CreatePlatformGLContext_iOS.mm +++ b/src/gpu/gl/iOS/SkCreatePlatformGLContext_iOS.mm @@ -6,7 +6,7 @@ * found in the LICENSE file. */ -#include "GLContext.h" +#include "gl/SkGLContext.h" #import #include @@ -14,7 +14,7 @@ namespace { -class IOSGLContext : public sk_gpu_test::GLContext { +class IOSGLContext : public SkGLContext { public: IOSGLContext(); ~IOSGLContext() override; @@ -87,10 +87,9 @@ GrGLFuncPtr IOSGLContext::onPlatformGetProcAddress(const char* procName) const { return reinterpret_cast(dlsym(fGLLibrary, procName)); } -} // anonymous namespace +} // anonymous namespace -namespace sk_gpu_test { -GLContext *CreatePlatformGLContext(GrGLStandard forcedGpuAPI, GLContext *shareContext) { +SkGLContext* SkCreatePlatformGLContext(GrGLStandard forcedGpuAPI, SkGLContext* shareContext) { SkASSERT(!shareContext); if (shareContext) { return NULL; @@ -98,11 +97,10 @@ GLContext *CreatePlatformGLContext(GrGLStandard forcedGpuAPI, GLContext *shareCo if (kGL_GrGLStandard == forcedGpuAPI) { return NULL; } - IOSGLContext *ctx = new IOSGLContext; + IOSGLContext* ctx = new IOSGLContext; if (!ctx->isValid()) { delete ctx; return NULL; } return ctx; } -} diff --git a/tools/gpu/gl/mac/CreatePlatformGLContext_mac.cpp b/src/gpu/gl/mac/SkCreatePlatformGLContext_mac.cpp similarity index 91% rename from tools/gpu/gl/mac/CreatePlatformGLContext_mac.cpp rename to src/gpu/gl/mac/SkCreatePlatformGLContext_mac.cpp index 7da99d7eb5..0ca62ad1cc 100644 --- a/tools/gpu/gl/mac/CreatePlatformGLContext_mac.cpp +++ b/src/gpu/gl/mac/SkCreatePlatformGLContext_mac.cpp @@ -1,4 +1,3 @@ - /* * Copyright 2011 Google Inc. * @@ -6,15 +5,16 @@ * found in the LICENSE file. */ #include "SkTypes.h" +#if defined(SK_BUILD_FOR_MAC) -#include "gl/GLContext.h" +#include "gl/SkGLContext.h" #include "AvailabilityMacros.h" #include #include namespace { -class MacGLContext : public sk_gpu_test::GLContext { +class MacGLContext : public SkGLContext { public: MacGLContext(); ~MacGLContext() override; @@ -106,10 +106,9 @@ GrGLFuncPtr MacGLContext::onPlatformGetProcAddress(const char* procName) const { return reinterpret_cast(dlsym(fGLLibrary, procName)); } -} // anonymous namespace +} // anonymous namespace -namespace sk_gpu_test { -GLContext* CreatePlatformGLContext(GrGLStandard forcedGpuAPI, GLContext* shareContext) { +SkGLContext* SkCreatePlatformGLContext(GrGLStandard forcedGpuAPI, SkGLContext* shareContext) { SkASSERT(!shareContext); if (shareContext) { return nullptr; @@ -125,4 +124,5 @@ GLContext* CreatePlatformGLContext(GrGLStandard forcedGpuAPI, GLContext* shareCo } return ctx; } -} // namespace sk_gpu_test + +#endif//defined(SK_BUILD_FOR_MAC) diff --git a/src/gpu/gl/mesa/GrGLCreateMesaInterface.cpp b/src/gpu/gl/mesa/GrGLCreateMesaInterface.cpp new file mode 100644 index 0000000000..6a04d4f387 --- /dev/null +++ b/src/gpu/gl/mesa/GrGLCreateMesaInterface.cpp @@ -0,0 +1,24 @@ +/* + * Copyright 2011 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "gl/GrGLAssembleInterface.h" +#include "../GrGLUtil.h" + +#include "osmesa_wrapper.h" + +static GrGLFuncPtr osmesa_get(void* ctx, const char name[]) { + SkASSERT(nullptr == ctx); + SkASSERT(OSMesaGetCurrentContext()); + return OSMesaGetProcAddress(name); +} + +const GrGLInterface* GrGLCreateMesaInterface() { + if (nullptr == OSMesaGetCurrentContext()) { + return nullptr; + } + return GrGLAssembleInterface(nullptr, osmesa_get); +} diff --git a/tools/gpu/gl/mesa/GLContext_mesa.cpp b/src/gpu/gl/mesa/SkMesaGLContext.cpp similarity index 52% rename from tools/gpu/gl/mesa/GLContext_mesa.cpp rename to src/gpu/gl/mesa/SkMesaGLContext.cpp index e6cc7c7f4b..eeccbd64ae 100644 --- a/tools/gpu/gl/mesa/GLContext_mesa.cpp +++ b/src/gpu/gl/mesa/SkMesaGLContext.cpp @@ -1,4 +1,3 @@ - /* * Copyright 2011 Google Inc. * @@ -8,52 +7,14 @@ #include -#include "gl/mesa/GLContext_mesa.h" +#include "gl/mesa/SkMesaGLContext.h" #include "gl/GrGLDefines.h" -#include "gl/GrGLAssembleInterface.h" -#include "gl/GrGLUtil.h" -#include "osmesa_wrapper.h" - -namespace { - -static GrGLFuncPtr osmesa_get(void* ctx, const char name[]) { - SkASSERT(nullptr == ctx); - SkASSERT(OSMesaGetCurrentContext()); - return OSMesaGetProcAddress(name); -} - -static const GrGLInterface* create_mesa_interface() { - if (nullptr == OSMesaGetCurrentContext()) { - return nullptr; - } - return GrGLAssembleInterface(nullptr, osmesa_get); -} - static const GrGLint gBOGUS_SIZE = 16; -class MesaGLContext : public sk_gpu_test::GLContext { -private: - typedef intptr_t Context; - -public: - MesaGLContext(); - ~MesaGLContext() override; - -private: - void destroyGLContext(); - - void onPlatformMakeCurrent() const override; - - void onPlatformSwapBuffers() const override; - - GrGLFuncPtr onPlatformGetProcAddress(const char *) const override; - - Context fContext; - GrGLubyte *fImage; -}; - -MesaGLContext::MesaGLContext() : fContext(static_cast(0)), fImage(nullptr) { +SkMesaGLContext::SkMesaGLContext() + : fContext(static_cast(0)) + , fImage(nullptr) { GR_STATIC_ASSERT(sizeof(Context) == sizeof(OSMesaContext)); /* Create an RGBA-mode context */ @@ -61,7 +22,7 @@ MesaGLContext::MesaGLContext() : fContext(static_cast(0)), fImage(nullp /* specify Z, stencil, accum sizes */ fContext = (Context)OSMesaCreateContextExt(OSMESA_BGRA, 0, 0, 0, nullptr); #else - fContext = (Context) OSMesaCreateContext(OSMESA_BGRA, nullptr); + fContext = (Context)OSMesaCreateContext(OSMESA_BGRA, nullptr); #endif if (!fContext) { SkDebugf("OSMesaCreateContext failed!\n"); @@ -78,7 +39,7 @@ MesaGLContext::MesaGLContext() : fContext(static_cast(0)), fImage(nullp } // Bind the buffer to the context and make it current - if (!OSMesaMakeCurrent((OSMesaContext) fContext, + if (!OSMesaMakeCurrent((OSMesaContext)fContext, fImage, GR_GL_UNSIGNED_BYTE, gBOGUS_SIZE, @@ -88,7 +49,7 @@ MesaGLContext::MesaGLContext() : fContext(static_cast(0)), fImage(nullp return; } - SkAutoTUnref gl(create_mesa_interface()); + SkAutoTUnref gl(GrGLCreateMesaInterface()); if (nullptr == gl.get()) { SkDebugf("Could not create GL interface!\n"); this->destroyGLContext(); @@ -104,48 +65,36 @@ MesaGLContext::MesaGLContext() : fContext(static_cast(0)), fImage(nullp this->init(gl.release()); } -MesaGLContext::~MesaGLContext() { +SkMesaGLContext::~SkMesaGLContext() { this->teardown(); this->destroyGLContext(); } -void MesaGLContext::destroyGLContext() { +void SkMesaGLContext::destroyGLContext() { if (fImage) { sk_free(fImage); fImage = nullptr; } if (fContext) { - OSMesaDestroyContext((OSMesaContext) fContext); + OSMesaDestroyContext((OSMesaContext)fContext); fContext = static_cast(0); } } -void MesaGLContext::onPlatformMakeCurrent() const { + +void SkMesaGLContext::onPlatformMakeCurrent() const { if (fContext) { - if (!OSMesaMakeCurrent((OSMesaContext) fContext, fImage, + if (!OSMesaMakeCurrent((OSMesaContext)fContext, fImage, GR_GL_UNSIGNED_BYTE, gBOGUS_SIZE, gBOGUS_SIZE)) { SkDebugf("Could not make MESA context current."); } } } -void MesaGLContext::onPlatformSwapBuffers() const { } +void SkMesaGLContext::onPlatformSwapBuffers() const { } -GrGLFuncPtr MesaGLContext::onPlatformGetProcAddress(const char *procName) const { +GrGLFuncPtr SkMesaGLContext::onPlatformGetProcAddress(const char* procName) const { return OSMesaGetProcAddress(procName); } -} // anonymous namespace - - -namespace sk_gpu_test { -GLContext *CreateMesaGLContext() { - MesaGLContext *ctx = new MesaGLContext; - if (!ctx->isValid()) { - delete ctx; - return nullptr; - } - return ctx; -} -} // sk_gpu_test diff --git a/src/gpu/gl/mesa/SkMesaGLContext.h b/src/gpu/gl/mesa/SkMesaGLContext.h new file mode 100644 index 0000000000..7f700b6536 --- /dev/null +++ b/src/gpu/gl/mesa/SkMesaGLContext.h @@ -0,0 +1,44 @@ +/* + * Copyright 2011 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ +#ifndef SkMesaGLContext_DEFINED +#define SkMesaGLContext_DEFINED + +#include "gl/SkGLContext.h" + +#if SK_MESA + +class SkMesaGLContext : public SkGLContext { +private: + typedef intptr_t Context; + +public: + ~SkMesaGLContext() override; + + static SkMesaGLContext* Create() { + SkMesaGLContext* ctx = new SkMesaGLContext; + if (!ctx->isValid()) { + delete ctx; + return nullptr; + } + return ctx; + } + +private: + SkMesaGLContext(); + void destroyGLContext(); + + void onPlatformMakeCurrent() const override; + void onPlatformSwapBuffers() const override; + GrGLFuncPtr onPlatformGetProcAddress(const char*) const override; + + Context fContext; + GrGLubyte *fImage; +}; + +#endif + +#endif diff --git a/src/gpu/gl/nacl/SkCreatePlatformGLContext_nacl.cpp b/src/gpu/gl/nacl/SkCreatePlatformGLContext_nacl.cpp new file mode 100644 index 0000000000..855f0dc124 --- /dev/null +++ b/src/gpu/gl/nacl/SkCreatePlatformGLContext_nacl.cpp @@ -0,0 +1,12 @@ +/* + * Copyright 2012 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ +#include "gl/SkGLContext.h" + +SkGLContext* SkCreatePlatformGLContext(GrGLStandard forcedGpuAPI, SkGLContext* shareContext) { + SkASSERT(!shareContext); + return nullptr; +} diff --git a/tools/gpu/gl/win/CreatePlatformGLContext_win.cpp b/src/gpu/gl/win/SkCreatePlatformGLContext_win.cpp similarity index 94% rename from tools/gpu/gl/win/CreatePlatformGLContext_win.cpp rename to src/gpu/gl/win/SkCreatePlatformGLContext_win.cpp index efee28b74b..e99aa15eb7 100644 --- a/tools/gpu/gl/win/CreatePlatformGLContext_win.cpp +++ b/src/gpu/gl/win/SkCreatePlatformGLContext_win.cpp @@ -1,4 +1,3 @@ - /* * Copyright 2011 Google Inc. * @@ -6,7 +5,7 @@ * found in the LICENSE file. */ -#include "gl/GLContext.h" +#include "gl/SkGLContext.h" #include #include @@ -17,7 +16,7 @@ namespace { -class WinGLContext : public sk_gpu_test::GLContext { +class WinGLContext : public SkGLContext { public: WinGLContext(GrGLStandard forcedGpuAPI); ~WinGLContext() override; @@ -187,18 +186,15 @@ GrGLFuncPtr WinGLContext::onPlatformGetProcAddress(const char* name) const { } // anonymous namespace -namespace sk_gpu_test { -GLContext* CreatePlatformGLContext(GrGLStandard forcedGpuAPI, GLContext *shareContext) { +SkGLContext* SkCreatePlatformGLContext(GrGLStandard forcedGpuAPI, SkGLContext* shareContext) { SkASSERT(!shareContext); if (shareContext) { return nullptr; } - WinGLContext *ctx = new WinGLContext(forcedGpuAPI); + WinGLContext* ctx = new WinGLContext(forcedGpuAPI); if (!ctx->isValid()) { delete ctx; return nullptr; } return ctx; } -} // namespace sk_gpu_test - diff --git a/src/views/win/SkOSWindow_win.cpp b/src/views/win/SkOSWindow_win.cpp index eba3a77e4d..8b0211d64b 100644 --- a/src/views/win/SkOSWindow_win.cpp +++ b/src/views/win/SkOSWindow_win.cpp @@ -395,36 +395,6 @@ void SkOSWindow::presentGL() { #if SK_ANGLE -void* get_angle_egl_display(void* nativeDisplay) { - PFNEGLGETPLATFORMDISPLAYEXTPROC eglGetPlatformDisplayEXT; - eglGetPlatformDisplayEXT = - (PFNEGLGETPLATFORMDISPLAYEXTPROC)eglGetProcAddress("eglGetPlatformDisplayEXT"); - - // We expect ANGLE to support this extension - if (!eglGetPlatformDisplayEXT) { - return EGL_NO_DISPLAY; - } - - EGLDisplay display = EGL_NO_DISPLAY; - // Try for an ANGLE D3D11 context, fall back to D3D9, and finally GL. - EGLint attribs[3][3] = { - { - EGL_PLATFORM_ANGLE_TYPE_ANGLE, - EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE, - EGL_NONE - }, - { - EGL_PLATFORM_ANGLE_TYPE_ANGLE, - EGL_PLATFORM_ANGLE_TYPE_D3D9_ANGLE, - EGL_NONE - }, - }; - for (int i = 0; i < 3 && display == EGL_NO_DISPLAY; ++i) { - display = eglGetPlatformDisplayEXT(EGL_PLATFORM_ANGLE_ANGLE,nativeDisplay, attribs[i]); - } - return display; -} - bool create_ANGLE(EGLNativeWindowType hWnd, int msaaSampleCount, EGLDisplay* eglDisplay, @@ -448,7 +418,7 @@ bool create_ANGLE(EGLNativeWindowType hWnd, EGL_NONE, EGL_NONE }; - EGLDisplay display = get_angle_egl_display(GetDC(hWnd), false); + EGLDisplay display = SkANGLEGLContext::GetD3DEGLDisplay(GetDC(hWnd), false); if (EGL_NO_DISPLAY == display) { SkDebugf("Could not create ANGLE egl display!\n"); diff --git a/tests/EGLImageTest.cpp b/tests/EGLImageTest.cpp index 7f0d7ea376..f19592c530 100644 --- a/tests/EGLImageTest.cpp +++ b/tests/EGLImageTest.cpp @@ -11,11 +11,9 @@ #include "GrContextFactory.h" #include "gl/GrGLGpu.h" #include "gl/GrGLUtil.h" -#include "gl/GLContext.h" +#include "gl/SkGLContext.h" -using sk_gpu_test::GLContext; - -static void cleanup(GLContext* glctx0, GrGLuint texID0, GLContext* glctx1, GrContext* grctx1, +static void cleanup(SkGLContext* glctx0, GrGLuint texID0, SkGLContext* glctx1, GrContext* grctx1, const GrGLTextureInfo* grbackendtex1, GrEGLImage image1) { if (glctx1) { glctx1->makeCurrent(); @@ -93,7 +91,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(EGLImageTest, reporter, context0, glCtx0) { return; } - SkAutoTDelete glCtx1 = glCtx0->createNew(); + SkAutoTDelete glCtx1 = glCtx0->createNew(); if (!glCtx1) { return; } diff --git a/tests/GLProgramsTest.cpp b/tests/GLProgramsTest.cpp index 57274e0678..03938fbb93 100644 --- a/tests/GLProgramsTest.cpp +++ b/tests/GLProgramsTest.cpp @@ -455,7 +455,7 @@ DEF_GPUTEST(GLPrograms, reporter, /*factory*/) { // We suppress prints to avoid spew GrContextOptions opts; opts.fSuppressPrints = true; - sk_gpu_test::GrContextFactory debugFactory(opts); + GrContextFactory debugFactory(opts); skiatest::RunWithGPUTestContexts(test_glprograms_native, skiatest::kNative_GPUTestContexts, reporter, &debugFactory); skiatest::RunWithGPUTestContexts(test_glprograms_other_contexts, diff --git a/tests/GrContextFactoryTest.cpp b/tests/GrContextFactoryTest.cpp index 0ba809524b..7dc02a56e6 100644 --- a/tests/GrContextFactoryTest.cpp +++ b/tests/GrContextFactoryTest.cpp @@ -13,8 +13,6 @@ #include "GrCaps.h" #include "Test.h" -using sk_gpu_test::GrContextFactory; - DEF_GPUTEST(GrContextFactory_NVPRContextOptionHasPathRenderingSupport, reporter, /*factory*/) { // Test that if NVPR is requested, the context always has path rendering // or the context creation fails. diff --git a/tests/GrPorterDuffTest.cpp b/tests/GrPorterDuffTest.cpp index 566ec12f5d..54fcfc1d42 100644 --- a/tests/GrPorterDuffTest.cpp +++ b/tests/GrPorterDuffTest.cpp @@ -1147,8 +1147,8 @@ static void test_lcd_coverage_fallback_case(skiatest::Reporter* reporter, const DEF_GPUTEST(PorterDuffNoDualSourceBlending, reporter, /*factory*/) { GrContextOptions opts; opts.fSuppressDualSourceBlending = true; - sk_gpu_test::GrContextFactory mockFactory(opts); - GrContext* ctx = mockFactory.get(sk_gpu_test::GrContextFactory::kNull_GLContextType); + GrContextFactory mockFactory(opts); + GrContext* ctx = mockFactory.get(GrContextFactory::kNull_GLContextType); if (!ctx) { SkFAIL("Failed to create null context without ARB_blend_func_extended."); return; diff --git a/tests/ImageTest.cpp b/tests/ImageTest.cpp index 8485fdad68..15ee54c000 100644 --- a/tests/ImageTest.cpp +++ b/tests/ImageTest.cpp @@ -26,8 +26,6 @@ #include "SkUtils.h" #include "Test.h" -using sk_gpu_test::GrContextFactory; - static void assert_equal(skiatest::Reporter* reporter, SkImage* a, const SkIRect* subsetA, SkImage* b) { const int widthA = subsetA ? subsetA->width() : a->width(); diff --git a/tests/RectangleTextureTest.cpp b/tests/RectangleTextureTest.cpp index fc9e65e12d..114207d2fe 100644 --- a/tests/RectangleTextureTest.cpp +++ b/tests/RectangleTextureTest.cpp @@ -11,7 +11,7 @@ #include "GrDrawContext.h" #include "gl/GrGLGpu.h" #include "gl/GrGLUtil.h" -#include "gl/GLContext.h" +#include "gl/SkGLContext.h" static void test_read_pixels(skiatest::Reporter* reporter, GrContext* context, GrTexture* rectangleTexture, uint32_t expectedPixelValues[]) { diff --git a/tests/Test.h b/tests/Test.h index 119976f3ee..4b19a85c1d 100644 --- a/tests/Test.h +++ b/tests/Test.h @@ -11,11 +11,9 @@ #include "SkTRegistry.h" #include "SkTypes.h" -namespace sk_gpu_test { class GrContextFactory; -class GLContext; -} // namespace sk_gpu_test class GrContext; +class SkGLContext; namespace skiatest { @@ -43,7 +41,7 @@ public: #define REPORT_FAILURE(reporter, cond, message) \ reporter->reportFailed(skiatest::Failure(__FILE__, __LINE__, cond, message)) -typedef void (*TestProc)(skiatest::Reporter*, sk_gpu_test::GrContextFactory*); +typedef void (*TestProc)(skiatest::Reporter*, GrContextFactory*); struct Test { Test(const char* n, bool g, TestProc p) : name(n), needsGpu(g), proc(p) {} @@ -85,7 +83,7 @@ enum GPUTestContexts { }; template void RunWithGPUTestContexts(T testFunction, GPUTestContexts contexts, Reporter* reporter, - sk_gpu_test::GrContextFactory* factory); + GrContextFactory* factory); /** Timer provides wall-clock duration since its creation. */ class Timer { @@ -135,32 +133,32 @@ private: } \ } while (0) -#define DEF_TEST(name, reporter) \ - static void test_##name(skiatest::Reporter*, sk_gpu_test::GrContextFactory*); \ - skiatest::TestRegistry name##TestRegistry( \ - skiatest::Test(#name, false, test_##name)); \ - void test_##name(skiatest::Reporter* reporter, sk_gpu_test::GrContextFactory*) +#define DEF_TEST(name, reporter) \ + static void test_##name(skiatest::Reporter*, GrContextFactory*); \ + skiatest::TestRegistry name##TestRegistry( \ + skiatest::Test(#name, false, test_##name)); \ + void test_##name(skiatest::Reporter* reporter, GrContextFactory*) #define GPUTEST_EXPAND_MSVC(x) x #define GPUTEST_APPLY(C, ...) GPUTEST_EXPAND_MSVC(C(__VA_ARGS__)) #define GPUTEST_SELECT(a1, a2, N, ...) N #define GPUTEST_CONTEXT_ARGS1(a1) GrContext* a1 -#define GPUTEST_CONTEXT_ARGS2(a1, a2) GrContext* a1, sk_gpu_test::GLContext* a2 +#define GPUTEST_CONTEXT_ARGS2(a1, a2) GrContext* a1, SkGLContext* a2 #define GPUTEST_CONTEXT_ARGS(...) \ GPUTEST_APPLY(GPUTEST_SELECT(__VA_ARGS__, GPUTEST_CONTEXT_ARGS2, GPUTEST_CONTEXT_ARGS1), \ __VA_ARGS__) -#define DEF_GPUTEST(name, reporter, factory) \ - static void test_##name(skiatest::Reporter*, sk_gpu_test::GrContextFactory*); \ - skiatest::TestRegistry name##TestRegistry( \ - skiatest::Test(#name, true, test_##name)); \ - void test_##name(skiatest::Reporter* reporter, sk_gpu_test::GrContextFactory* factory) +#define DEF_GPUTEST(name, reporter, factory) \ + static void test_##name(skiatest::Reporter*, GrContextFactory*); \ + skiatest::TestRegistry name##TestRegistry( \ + skiatest::Test(#name, true, test_##name)); \ + void test_##name(skiatest::Reporter* reporter, GrContextFactory* factory) #define DEF_GPUTEST_FOR_CONTEXTS(name, contexts, reporter, ...) \ static void test_##name(skiatest::Reporter*, GPUTEST_CONTEXT_ARGS(__VA_ARGS__)); \ static void test_gpu_contexts_##name(skiatest::Reporter* reporter, \ - sk_gpu_test::GrContextFactory* factory) { \ + GrContextFactory* factory) { \ skiatest::RunWithGPUTestContexts(test_##name, contexts, reporter, factory); \ } \ skiatest::TestRegistry name##TestRegistry( \ diff --git a/tests/TestConfigParsing.cpp b/tests/TestConfigParsing.cpp index 4057a37bb0..9c030ed9ec 100644 --- a/tests/TestConfigParsing.cpp +++ b/tests/TestConfigParsing.cpp @@ -9,8 +9,6 @@ #include "Test.h" #include -using sk_gpu_test::GrContextFactory; - namespace { // The code // SkCommandLineFlags::StringArray FLAGS_config1 = make_string_array({"a", "b"}) diff --git a/tests/TestTest.cpp b/tests/TestTest.cpp index 05ab9ff697..890042e19d 100644 --- a/tests/TestTest.cpp +++ b/tests/TestTest.cpp @@ -9,7 +9,7 @@ #if SK_SUPPORT_GPU #include "GrContext.h" -#include "gl/GLContext.h" +#include "gl/SkGLContext.h" #endif @@ -64,7 +64,7 @@ DEF_GPUTEST_FOR_NULL_CONTEXT(TestGpuNullContext, reporter, context) { #endif // This is an example of a GPU test that tests a property that should work for all GPU contexts. -// It uses the additional GLContext* glContext to implement the test. +// It uses the additional SkGLContext* glContext to implement the test. #if SK_SUPPORT_GPU DEF_GPUTEST_FOR_ALL_CONTEXTS(TestGpuGrContextAndGLContext, reporter, context, glContext) { REPORTER_ASSERT(reporter, reporter); diff --git a/tests/TextureStorageAllocator.cpp b/tests/TextureStorageAllocator.cpp index dd08354136..1d226861e2 100644 --- a/tests/TextureStorageAllocator.cpp +++ b/tests/TextureStorageAllocator.cpp @@ -8,9 +8,9 @@ #include "Test.h" #if SK_SUPPORT_GPU #include "gl/GrGLGpu.h" -#include "gl/GLContext.h" #include "GrContext.h" #include "SkSurface_Gpu.h" +#include "../include/gpu/gl/SkGLContext.h" #include "../include/gpu/GrTypes.h" #include "../include/private/SkTemplates.h" diff --git a/tests/skia_test.cpp b/tests/skia_test.cpp index 9783db83a0..5d21d1ec15 100644 --- a/tests/skia_test.cpp +++ b/tests/skia_test.cpp @@ -24,7 +24,6 @@ #endif using namespace skiatest; -using namespace sk_gpu_test; DEFINE_bool2(extendedTest, x, false, "run extended tests for pathOps."); diff --git a/tools/VisualBench/VisualBench.h b/tools/VisualBench/VisualBench.h index e9fbdfb8ae..1920a52b2b 100644 --- a/tools/VisualBench/VisualBench.h +++ b/tools/VisualBench/VisualBench.h @@ -16,7 +16,7 @@ #include "SkSurface.h" #include "VisualFlags.h" #include "VisualModule.h" -#include "gl/GLContext.h" +#include "gl/SkGLContext.h" class GrContext; struct GrGLInterface; diff --git a/tools/flags/SkCommonFlagsConfig.cpp b/tools/flags/SkCommonFlagsConfig.cpp index 1ee3130bd7..9e0fd60b39 100644 --- a/tools/flags/SkCommonFlagsConfig.cpp +++ b/tools/flags/SkCommonFlagsConfig.cpp @@ -9,10 +9,6 @@ #include -#if SK_SUPPORT_GPU -using sk_gpu_test::GrContextFactory; -#endif - static const char defaultConfigs[] = "565 8888 gpu nonrendering" #if SK_ANGLE diff --git a/tools/flags/SkCommonFlagsConfig.h b/tools/flags/SkCommonFlagsConfig.h index abf5946847..39f1f9788b 100644 --- a/tools/flags/SkCommonFlagsConfig.h +++ b/tools/flags/SkCommonFlagsConfig.h @@ -50,7 +50,7 @@ class SkCommandLineConfig { // * backends that represent a shorthand of above (such as "msaa16" representing "gpu(samples=16)") class SkCommandLineConfigGpu : public SkCommandLineConfig { public: - typedef sk_gpu_test::GrContextFactory::GLContextType ContextType; + typedef GrContextFactory::GLContextType ContextType; SkCommandLineConfigGpu(const SkString& tag, const SkTArray& viaParts, ContextType contextType, bool useNVPR, bool useDIText, int samples, SkColorType colorType, SkColorProfileType profileType); diff --git a/tools/gpu/gl/angle/GLContext_angle.h b/tools/gpu/gl/angle/GLContext_angle.h deleted file mode 100644 index 519ea6b5a3..0000000000 --- a/tools/gpu/gl/angle/GLContext_angle.h +++ /dev/null @@ -1,30 +0,0 @@ - -/* - * Copyright 2012 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ -#ifndef GLContext_angle_DEFINED -#define GLContext_angle_DEFINED - -#include "gl/GLContext.h" - -namespace sk_gpu_test { - -/** - * Creates a GrGLInterface for the currently ANGLE GL context currently bound in ANGLE's EGL - * implementation. - */ -const GrGLInterface* CreateANGLEGLInterface(); - -#ifdef SK_BUILD_FOR_WIN -/** Creates a GLContext backed by ANGLE's Direct3D backend. */ -GLContext* CreateANGLEDirect3DGLContext(); -#endif - -/** Creates a GLContext backed by ANGLE's OpenGL backend. */ -GLContext* CreateANGLEOpenGLGLContext(); - -} // namespace sk_gpu_test -#endif diff --git a/tools/gpu/gl/command_buffer/GLContext_command_buffer.h b/tools/gpu/gl/command_buffer/GLContext_command_buffer.h deleted file mode 100644 index 73f02e2c78..0000000000 --- a/tools/gpu/gl/command_buffer/GLContext_command_buffer.h +++ /dev/null @@ -1,68 +0,0 @@ - -/* - * Copyright 2015 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef GLContext_command_buffer_DEFINED -#define GLContext_command_buffer_DEFINED - -#include "gl/GLContext.h" - -namespace sk_gpu_test { -class CommandBufferGLContext : public GLContext { -public: - ~CommandBufferGLContext() override; - - static CommandBufferGLContext *Create() { - CommandBufferGLContext *ctx = new CommandBufferGLContext; - if (!ctx->isValid()) { - delete ctx; - return nullptr; - } - return ctx; - } - - static CommandBufferGLContext *Create(void *nativeWindow, int msaaSampleCount) { - CommandBufferGLContext *ctx = new CommandBufferGLContext(nativeWindow, msaaSampleCount); - if (!ctx->isValid()) { - delete ctx; - return nullptr; - } - return ctx; - } - - void presentCommandBuffer(); - - bool makeCurrent(); - - int getStencilBits(); - - int getSampleCount(); - -private: - CommandBufferGLContext(); - - CommandBufferGLContext(void *nativeWindow, int msaaSampleCount); - - void initializeGLContext(void *nativeWindow, const int *configAttribs, - const int *surfaceAttribs); - - void destroyGLContext(); - - void onPlatformMakeCurrent() const override; - - void onPlatformSwapBuffers() const override; - - GrGLFuncPtr onPlatformGetProcAddress(const char *name) const override; - - void *fContext; - void *fDisplay; - void *fSurface; - void *fConfig; -}; -} // namespace sk_gpu_test - -#endif diff --git a/tools/gpu/gl/debug/DebugGLContext.h b/tools/gpu/gl/debug/DebugGLContext.h deleted file mode 100644 index 0ac505b632..0000000000 --- a/tools/gpu/gl/debug/DebugGLContext.h +++ /dev/null @@ -1,17 +0,0 @@ - -/* - * Copyright 2012 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ -#ifndef DebugGLContext_DEFINED -#define DebugGLContext_DEFINED - -#include "gl/GLContext.h" - -namespace sk_gpu_test { -GLContext* CreateDebugGLContext(); -} // namespace sk_gpu_test - -#endif diff --git a/tools/gpu/gl/mesa/GLContext_mesa.h b/tools/gpu/gl/mesa/GLContext_mesa.h deleted file mode 100644 index 0d6ee4dc10..0000000000 --- a/tools/gpu/gl/mesa/GLContext_mesa.h +++ /dev/null @@ -1,17 +0,0 @@ - -/* - * Copyright 2011 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ -#ifndef GLContext_mesa_DEFINED -#define GLContext_mesa_DEFINED - -#include "gl/GLContext.h" - -namespace sk_gpu_test { -GLContext* CreateMesaGLContext(); -} // namespace sk_gpu_test - -#endif diff --git a/tools/gpu/gl/mesa/osmesa_wrapper.h b/tools/gpu/gl/mesa/osmesa_wrapper.h deleted file mode 100644 index 70de99376d..0000000000 --- a/tools/gpu/gl/mesa/osmesa_wrapper.h +++ /dev/null @@ -1,16 +0,0 @@ - -/* - * Copyright 2013 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -// Older versions of XQuartz have a bug where a header included by osmesa.h -// defines GL_GLEXT_PROTOTYPES. This will cause a redefinition warning if -// the file that includes osmesa.h already defined it. XCode 3 uses a version -// of gcc (4.2.1) that does not support the diagnostic pragma to disable a -// warning (added in 4.2.4). So we use the system_header pragma to shut GCC -// up about warnings in osmesa.h -#pragma GCC system_header -#include diff --git a/tools/gpu/gl/null/NullGLContext.cpp b/tools/gpu/gl/null/NullGLContext.cpp deleted file mode 100644 index 4781c90e4f..0000000000 --- a/tools/gpu/gl/null/NullGLContext.cpp +++ /dev/null @@ -1,630 +0,0 @@ - -/* - * Copyright 2011 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#include "NullGLContext.h" -#include "gl/GrGLTestInterface.h" -#include "gl/GrGLDefines.h" -#include "gl/GrGLInterface.h" -#include "gl/GrGLTypes.h" -#include "SkMutex.h" -#include "SkTDArray.h" - -namespace { - -class BufferObj { -public: - BufferObj(GrGLuint id) : fID(id), fDataPtr(nullptr), fSize(0), fMapped(false) {} - ~BufferObj() { delete[] fDataPtr; } - - void allocate(GrGLsizeiptr size, const GrGLchar* dataPtr) { - if (fDataPtr) { - SkASSERT(0 != fSize); - delete[] fDataPtr; - } - - fSize = size; - fDataPtr = new char[size]; - } - - GrGLuint id() const { return fID; } - GrGLchar* dataPtr() { return fDataPtr; } - GrGLsizeiptr size() const { return fSize; } - - void setMapped(bool mapped) { fMapped = mapped; } - bool mapped() const { return fMapped; } - -private: - GrGLuint fID; - GrGLchar* fDataPtr; - GrGLsizeiptr fSize; // size in bytes - bool fMapped; -}; - -// This class maintains a sparsely populated array of buffer pointers. -class BufferManager { -public: - BufferManager() : fFreeListHead(kFreeListEnd) {} - - ~BufferManager() { - // nullptr out the entries that are really free list links rather than ptrs before deleting. - intptr_t curr = fFreeListHead; - while (kFreeListEnd != curr) { - intptr_t next = reinterpret_cast(fBuffers[SkToS32(curr)]); - fBuffers[SkToS32(curr)] = nullptr; - curr = next; - } - - fBuffers.deleteAll(); - } - - BufferObj* lookUp(GrGLuint id) { - BufferObj* buffer = fBuffers[id]; - SkASSERT(buffer && buffer->id() == id); - return buffer; - } - - BufferObj* create() { - GrGLuint id; - BufferObj* buffer; - - if (kFreeListEnd == fFreeListHead) { - // no free slots - create a new one - id = fBuffers.count(); - buffer = new BufferObj(id); - *fBuffers.append() = buffer; - } else { - // grab the head of the free list and advance the head to the next free slot. - id = static_cast(fFreeListHead); - fFreeListHead = reinterpret_cast(fBuffers[id]); - - buffer = new BufferObj(id); - fBuffers[id] = buffer; - } - - return buffer; - } - - void free(BufferObj* buffer) { - SkASSERT(fBuffers.count() > 0); - - GrGLuint id = buffer->id(); - delete buffer; - - fBuffers[id] = reinterpret_cast(fFreeListHead); - fFreeListHead = id; - } - -private: - static const intptr_t kFreeListEnd = -1; - // Index of the first entry of fBuffers in the free list. Free slots in fBuffers are indices to - // the next free slot. The last free slot has a value of kFreeListEnd. - intptr_t fFreeListHead; - SkTDArray fBuffers; -}; - -/** Null interface implementation */ -class NullInterface : public GrGLTestInterface { -public: - NullInterface() - : fCurrArrayBuffer(0) - , fCurrElementArrayBuffer(0) - , fCurrPixelPackBuffer(0) - , fCurrPixelUnpackBuffer(0) - , fCurrShaderID(0) - , fCurrGenericID(0) - , fCurrUniformLocation(0) { - this->init(kGL_GrGLStandard); - } - - GrGLenum checkFramebufferStatus(GrGLenum target) override { - return GR_GL_FRAMEBUFFER_COMPLETE; - } - - GrGLvoid genBuffers(GrGLsizei n, GrGLuint* ids) override { - for (int i = 0; i < n; ++i) { - BufferObj* buffer = fBufferManager.create(); - ids[i] = buffer->id(); - } - } - - GrGLvoid bufferData(GrGLenum target, GrGLsizeiptr size, const GrGLvoid* data, - GrGLenum usage) override { - GrGLuint id = 0; - - switch (target) { - case GR_GL_ARRAY_BUFFER: - id = fCurrArrayBuffer; - break; - case GR_GL_ELEMENT_ARRAY_BUFFER: - id = fCurrElementArrayBuffer; - break; - case GR_GL_PIXEL_PACK_BUFFER: - id = fCurrPixelPackBuffer; - break; - case GR_GL_PIXEL_UNPACK_BUFFER: - id = fCurrPixelUnpackBuffer; - break; - default: - SkFAIL("Unexpected target to nullGLBufferData"); - break; - } - - if (id > 0) { - BufferObj* buffer = fBufferManager.lookUp(id); - buffer->allocate(size, (const GrGLchar*) data); - } - } - - GrGLuint createProgram() override { - return ++fCurrProgramID; - } - - GrGLuint createShader(GrGLenum type) override { - return ++fCurrShaderID; - } - - GrGLvoid bindBuffer(GrGLenum target, GrGLuint buffer) override { - switch (target) { - case GR_GL_ARRAY_BUFFER: - fCurrArrayBuffer = buffer; - break; - case GR_GL_ELEMENT_ARRAY_BUFFER: - fCurrElementArrayBuffer = buffer; - break; - case GR_GL_PIXEL_PACK_BUFFER: - fCurrPixelPackBuffer = buffer; - break; - case GR_GL_PIXEL_UNPACK_BUFFER: - fCurrPixelUnpackBuffer = buffer; - break; - } - } - - // deleting a bound buffer has the side effect of binding 0 - GrGLvoid deleteBuffers(GrGLsizei n, const GrGLuint* ids) override { - for (int i = 0; i < n; ++i) { - if (ids[i] == fCurrArrayBuffer) { - fCurrArrayBuffer = 0; - } - if (ids[i] == fCurrElementArrayBuffer) { - fCurrElementArrayBuffer = 0; - } - if (ids[i] == fCurrPixelPackBuffer) { - fCurrPixelPackBuffer = 0; - } - if (ids[i] == fCurrPixelUnpackBuffer) { - fCurrPixelUnpackBuffer = 0; - } - - BufferObj* buffer = fBufferManager.lookUp(ids[i]); - fBufferManager.free(buffer); - } - } - - GrGLvoid genFramebuffers(GrGLsizei n, GrGLuint *framebuffers) override { - this->genGenericIds(n, framebuffers); - } - - GrGLvoid genQueries(GrGLsizei n, GrGLuint *ids) override { this->genGenericIds(n, ids); } - - GrGLvoid genRenderbuffers(GrGLsizei n, GrGLuint *renderbuffers) override { - this->genGenericIds(n, renderbuffers); - } - - GrGLvoid genTextures(GrGLsizei n, GrGLuint *textures) override { - this->genGenericIds(n, textures); - } - - GrGLvoid genVertexArrays(GrGLsizei n, GrGLuint *arrays) override { - this->genGenericIds(n, arrays); - } - - GrGLenum getError() override { return GR_GL_NO_ERROR; } - - GrGLvoid getIntegerv(GrGLenum pname, GrGLint* params) override { - // TODO: remove from Ganesh the #defines for gets we don't use. - // We would like to minimize gets overall due to performance issues - switch (pname) { - case GR_GL_CONTEXT_PROFILE_MASK: - *params = GR_GL_CONTEXT_COMPATIBILITY_PROFILE_BIT; - break; - case GR_GL_STENCIL_BITS: - *params = 8; - break; - case GR_GL_SAMPLES: - *params = 1; - break; - case GR_GL_FRAMEBUFFER_BINDING: - *params = 0; - break; - case GR_GL_VIEWPORT: - params[0] = 0; - params[1] = 0; - params[2] = 800; - params[3] = 600; - break; - case GR_GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS: - case GR_GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS: - case GR_GL_MAX_TEXTURE_IMAGE_UNITS: - case GR_GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS: - *params = 8; - break; - case GR_GL_MAX_TEXTURE_COORDS: - *params = 8; - break; - case GR_GL_MAX_VERTEX_UNIFORM_VECTORS: - *params = kDefaultMaxVertexUniformVectors; - break; - case GR_GL_MAX_FRAGMENT_UNIFORM_VECTORS: - *params = kDefaultMaxFragmentUniformVectors; - break; - case GR_GL_MAX_FRAGMENT_UNIFORM_COMPONENTS: - *params = 16 * 4; - break; - case GR_GL_NUM_COMPRESSED_TEXTURE_FORMATS: - *params = 0; - break; - case GR_GL_COMPRESSED_TEXTURE_FORMATS: - break; - case GR_GL_MAX_TEXTURE_SIZE: - *params = 8192; - break; - case GR_GL_MAX_RENDERBUFFER_SIZE: - *params = 8192; - break; - case GR_GL_MAX_SAMPLES: - *params = 32; - break; - case GR_GL_MAX_VERTEX_ATTRIBS: - *params = kDefaultMaxVertexAttribs; - break; - case GR_GL_MAX_VARYING_VECTORS: - *params = kDefaultMaxVaryingVectors; - break; - case GR_GL_NUM_EXTENSIONS: { - GrGLint i = 0; - while (kExtensions[i++]); - *params = i; - break; - } - default: - SkFAIL("Unexpected pname to GetIntegerv"); - } - } - - GrGLvoid getProgramiv(GrGLuint program, GrGLenum pname, GrGLint* params) override { - this->getShaderOrProgramiv(program, pname, params); - } - - GrGLvoid getProgramInfoLog(GrGLuint program, GrGLsizei bufsize, GrGLsizei* length, - char* infolog) override { - this->getInfoLog(program, bufsize, length, infolog); - } - - GrGLvoid getMultisamplefv(GrGLenum pname, GrGLuint index, GrGLfloat* val) override { - val[0] = val[1] = 0.5f; - } - - GrGLvoid getQueryiv(GrGLenum GLtarget, GrGLenum pname, GrGLint *params) override { - switch (pname) { - case GR_GL_CURRENT_QUERY: - *params = 0; - break; - case GR_GL_QUERY_COUNTER_BITS: - *params = 32; - break; - default: - SkFAIL("Unexpected pname passed GetQueryiv."); - } - } - - GrGLvoid getQueryObjecti64v(GrGLuint id, GrGLenum pname, GrGLint64 *params) override { - this->queryResult(id, pname, params); - } - - GrGLvoid getQueryObjectiv(GrGLuint id, GrGLenum pname, GrGLint *params) override { - this->queryResult(id, pname, params); - } - - GrGLvoid getQueryObjectui64v(GrGLuint id, GrGLenum pname, GrGLuint64 *params) override { - this->queryResult(id, pname, params); - } - - GrGLvoid getQueryObjectuiv(GrGLuint id, GrGLenum pname, GrGLuint *params) override { - this->queryResult(id, pname, params); - } - - GrGLvoid getShaderiv(GrGLuint shader, GrGLenum pname, GrGLint* params) override { - this->getShaderOrProgramiv(shader, pname, params); - } - - GrGLvoid getShaderInfoLog(GrGLuint shader, GrGLsizei bufsize, GrGLsizei* length, - char* infolog) override { - this->getInfoLog(shader, bufsize, length, infolog); - } - - const GrGLubyte* getString(GrGLenum name) override { - switch (name) { - case GR_GL_EXTENSIONS: - return CombinedExtensionString(); - case GR_GL_VERSION: - return (const GrGLubyte*)"4.0 Null GL"; - case GR_GL_SHADING_LANGUAGE_VERSION: - return (const GrGLubyte*)"4.20.8 Null GLSL"; - case GR_GL_VENDOR: - return (const GrGLubyte*)"Null Vendor"; - case GR_GL_RENDERER: - return (const GrGLubyte*)"The Null (Non-)Renderer"; - default: - SkFAIL("Unexpected name passed to GetString"); - return nullptr; - } - } - - const GrGLubyte* getStringi(GrGLenum name, GrGLuint i) override { - switch (name) { - case GR_GL_EXTENSIONS: { - GrGLint count; - this->getIntegerv(GR_GL_NUM_EXTENSIONS, &count); - if ((GrGLint)i <= count) { - return (const GrGLubyte*) kExtensions[i]; - } else { - return nullptr; - } - } - default: - SkFAIL("Unexpected name passed to GetStringi"); - return nullptr; - } - } - - GrGLint getUniformLocation(GrGLuint program, const char* name) override { - return ++fCurrUniformLocation; - } - - GrGLvoid* mapBufferRange(GrGLenum target, GrGLintptr offset, GrGLsizeiptr length, - GrGLbitfield access) override { - GrGLuint id = 0; - switch (target) { - case GR_GL_ARRAY_BUFFER: - id = fCurrArrayBuffer; - break; - case GR_GL_ELEMENT_ARRAY_BUFFER: - id = fCurrElementArrayBuffer; - break; - case GR_GL_PIXEL_PACK_BUFFER: - id = fCurrPixelPackBuffer; - break; - case GR_GL_PIXEL_UNPACK_BUFFER: - id = fCurrPixelUnpackBuffer; - break; - } - - if (id > 0) { - // We just ignore the offset and length here. - BufferObj* buffer = fBufferManager.lookUp(id); - SkASSERT(!buffer->mapped()); - buffer->setMapped(true); - return buffer->dataPtr(); - } - return nullptr; - } - - GrGLvoid* mapBuffer(GrGLenum target, GrGLenum access) override { - GrGLuint id = 0; - switch (target) { - case GR_GL_ARRAY_BUFFER: - id = fCurrArrayBuffer; - break; - case GR_GL_ELEMENT_ARRAY_BUFFER: - id = fCurrElementArrayBuffer; - break; - case GR_GL_PIXEL_PACK_BUFFER: - id = fCurrPixelPackBuffer; - break; - case GR_GL_PIXEL_UNPACK_BUFFER: - id = fCurrPixelUnpackBuffer; - break; - } - - if (id > 0) { - BufferObj* buffer = fBufferManager.lookUp(id); - SkASSERT(!buffer->mapped()); - buffer->setMapped(true); - return buffer->dataPtr(); - } - - SkASSERT(false); - return nullptr; // no buffer bound to target - } - - GrGLboolean unmapBuffer(GrGLenum target) override { - GrGLuint id = 0; - switch (target) { - case GR_GL_ARRAY_BUFFER: - id = fCurrArrayBuffer; - break; - case GR_GL_ELEMENT_ARRAY_BUFFER: - id = fCurrElementArrayBuffer; - break; - case GR_GL_PIXEL_PACK_BUFFER: - id = fCurrPixelPackBuffer; - break; - case GR_GL_PIXEL_UNPACK_BUFFER: - id = fCurrPixelUnpackBuffer; - break; - } - if (id > 0) { - BufferObj* buffer = fBufferManager.lookUp(id); - SkASSERT(buffer->mapped()); - buffer->setMapped(false); - return GR_GL_TRUE; - } - - GrAlwaysAssert(false); - return GR_GL_FALSE; // GR_GL_INVALID_OPERATION; - } - - GrGLvoid getBufferParameteriv(GrGLenum target, GrGLenum pname, GrGLint* params) override { - switch (pname) { - case GR_GL_BUFFER_MAPPED: { - *params = GR_GL_FALSE; - GrGLuint id = 0; - switch (target) { - case GR_GL_ARRAY_BUFFER: - id = fCurrArrayBuffer; - break; - case GR_GL_ELEMENT_ARRAY_BUFFER: - id = fCurrElementArrayBuffer; - break; - case GR_GL_PIXEL_PACK_BUFFER: - id = fCurrPixelPackBuffer; - break; - case GR_GL_PIXEL_UNPACK_BUFFER: - id = fCurrPixelUnpackBuffer; - break; - } - if (id > 0) { - BufferObj* buffer = fBufferManager.lookUp(id); - if (buffer->mapped()) { - *params = GR_GL_TRUE; - } - } - break; } - default: - SkFAIL("Unexpected pname to GetBufferParamateriv"); - break; - } - }; - -private: - BufferManager fBufferManager; - GrGLuint fCurrArrayBuffer; - GrGLuint fCurrElementArrayBuffer; - GrGLuint fCurrPixelPackBuffer; - GrGLuint fCurrPixelUnpackBuffer; - GrGLuint fCurrProgramID; - GrGLuint fCurrShaderID; - GrGLuint fCurrGenericID; - GrGLuint fCurrUniformLocation; - - // the OpenGLES 2.0 spec says this must be >= 128 - static const GrGLint kDefaultMaxVertexUniformVectors = 128; - - // the OpenGLES 2.0 spec says this must be >=16 - static const GrGLint kDefaultMaxFragmentUniformVectors = 16; - - // the OpenGLES 2.0 spec says this must be >= 8 - static const GrGLint kDefaultMaxVertexAttribs = 8; - - // the OpenGLES 2.0 spec says this must be >= 8 - static const GrGLint kDefaultMaxVaryingVectors = 8; - - static const char* kExtensions[]; - - static const GrGLubyte* CombinedExtensionString() { - static SkString gExtString; - static SkMutex gMutex; - gMutex.acquire(); - if (0 == gExtString.size()) { - int i = 0; - while (kExtensions[i]) { - if (i > 0) { - gExtString.append(" "); - } - gExtString.append(kExtensions[i]); - ++i; - } - } - gMutex.release(); - return (const GrGLubyte*) gExtString.c_str(); - } - - GrGLvoid genGenericIds(GrGLsizei n, GrGLuint* ids) { - for (int i = 0; i < n; ++i) { - ids[i] = ++fCurrGenericID; - } - } - - GrGLvoid getInfoLog(GrGLuint object, GrGLsizei bufsize, GrGLsizei* length, - char* infolog) { - if (length) { - *length = 0; - } - if (bufsize > 0) { - *infolog = 0; - } - } - - GrGLvoid getShaderOrProgramiv(GrGLuint object, GrGLenum pname, GrGLint* params) { - switch (pname) { - case GR_GL_LINK_STATUS: // fallthru - case GR_GL_COMPILE_STATUS: - *params = GR_GL_TRUE; - break; - case GR_GL_INFO_LOG_LENGTH: - *params = 0; - break; - // we don't expect any other pnames - default: - SkFAIL("Unexpected pname to GetProgramiv"); - break; - } - } - - template - void queryResult(GrGLenum GLtarget, GrGLenum pname, T *params) { - switch (pname) { - case GR_GL_QUERY_RESULT_AVAILABLE: - *params = GR_GL_TRUE; - break; - case GR_GL_QUERY_RESULT: - *params = 0; - break; - default: - SkFAIL("Unexpected pname passed to GetQueryObject."); - break; - } - } - - typedef GrGLTestInterface INHERITED; -}; - -const char* NullInterface::kExtensions[] = { - "GL_ARB_framebuffer_object", - "GL_ARB_blend_func_extended", - "GL_ARB_timer_query", - "GL_ARB_draw_buffers", - "GL_ARB_occlusion_query", - "GL_EXT_stencil_wrap", - nullptr, // signifies the end of the array. -}; - -class NullGLContext : public sk_gpu_test::GLContext { -public: - NullGLContext() { this->init(new NullInterface); } - ~NullGLContext() override { this->teardown(); } - -private: - void onPlatformMakeCurrent() const override {}; - void onPlatformSwapBuffers() const override {} - GrGLFuncPtr onPlatformGetProcAddress(const char*) const override { return nullptr; } -}; -} // anonymous namespace - -namespace sk_gpu_test { -GLContext* CreateNullGLContext() { - GLContext* ctx = new NullGLContext(); - if (ctx->isValid()) { - return ctx; - } - delete ctx; - return nullptr; -} -} // namespace sk_gpu_test - diff --git a/tools/gpu/gl/null/NullGLContext.h b/tools/gpu/gl/null/NullGLContext.h deleted file mode 100644 index 16fb9fd1df..0000000000 --- a/tools/gpu/gl/null/NullGLContext.h +++ /dev/null @@ -1,17 +0,0 @@ - -/* - * Copyright 2011 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ -#ifndef NullGLContext_DEFINED -#define NullGLContext_DEFINED - -#include "gl/GLContext.h" - -namespace sk_gpu_test { -GLContext* CreateNullGLContext(); -} // namespace sk_gpu_test - -#endif diff --git a/tools/kilobench/kilobench.cpp b/tools/kilobench/kilobench.cpp index 81238353e2..c0422d81eb 100644 --- a/tools/kilobench/kilobench.cpp +++ b/tools/kilobench/kilobench.cpp @@ -20,7 +20,6 @@ #include "Timer.h" #include "VisualSKPBench.h" #include "gl/GrGLDefines.h" -#include "gl/GrGLUtil.h" #include "../private/SkMutex.h" #include "../private/SkSemaphore.h" #include "../private/SkGpuFenceSync.h" @@ -30,8 +29,6 @@ #include #include -using namespace sk_gpu_test; - /* * This is an experimental GPU only benchmarking program. The initial implementation will only * support SKPs. @@ -147,14 +144,14 @@ struct GPUTarget { void setup() { fGL->makeCurrent(); // Make sure we're done with whatever came before. - GR_GL_CALL(fGL->gl(), Finish()); + SK_GL(*fGL, Finish()); } SkCanvas* beginTiming(SkCanvas* canvas) { return canvas; } void endTiming(bool usePlatformSwapBuffers) { if (fGL) { - GR_GL_CALL(fGL->gl(), Flush()); + SK_GL(*fGL, Flush()); if (usePlatformSwapBuffers) { fGL->swapBuffers(); } else { @@ -163,7 +160,7 @@ struct GPUTarget { } } void finish() { - GR_GL_CALL(fGL->gl(), Finish()); + SK_GL(*fGL, Finish()); } bool needsFrameTiming(int* maxFrameLag) const { @@ -218,10 +215,10 @@ struct GPUTarget { return true; } - GLContext* gl() { return fGL; } + SkGLContext* gl() { return fGL; } private: - GLContext* fGL; + SkGLContext* fGL; SkAutoTDelete fSurface; }; @@ -282,7 +279,7 @@ static int clamp_loops(int loops) { static double now_ms() { return SkTime::GetNSecs() * 1e-6; } struct TimingThread { - TimingThread(GLContext* mainContext) + TimingThread(SkGLContext* mainContext) : fFenceSync(mainContext->fenceSync()) , fMainContext(mainContext) , fDone(false) {} @@ -308,8 +305,8 @@ struct TimingThread { void timingLoop() { // Create a context which shares display lists with the main thread - SkAutoTDelete glContext(CreatePlatformGLContext(kNone_GrGLStandard, - fMainContext)); + SkAutoTDelete glContext(SkCreatePlatformGLContext(kNone_GrGLStandard, + fMainContext)); glContext->makeCurrent(); // Basic timing methodology is: @@ -405,7 +402,7 @@ private: SyncQueue fFrameEndSyncs; SkTArray fTimings; SkMutex fDoneMutex; - GLContext* fMainContext; + SkGLContext* fMainContext; bool fDone; }; diff --git a/tools/skiaserve/Request.cpp b/tools/skiaserve/Request.cpp index d9e1bdaa33..1d946abaa0 100644 --- a/tools/skiaserve/Request.cpp +++ b/tools/skiaserve/Request.cpp @@ -10,8 +10,6 @@ #include "SkPictureRecorder.h" #include "SkPixelSerializer.h" -using namespace sk_gpu_test; - static int kDefaultWidth = 1920; static int kDefaultHeight = 1080; @@ -65,8 +63,8 @@ SkData* Request::writeCanvasToPng(SkCanvas* canvas) { SkCanvas* Request::getCanvas() { #if SK_SUPPORT_GPU GrContextFactory* factory = fContextFactory; - GLContext* gl = factory->getContextInfo(GrContextFactory::kNative_GLContextType, - GrContextFactory::kNone_GLContextOptions).fGLContext; + SkGLContext* gl = factory->getContextInfo(GrContextFactory::kNative_GLContextType, + GrContextFactory::kNone_GLContextOptions).fGLContext; gl->makeCurrent(); #endif SkASSERT(fDebugCanvas); diff --git a/tools/skiaserve/Request.h b/tools/skiaserve/Request.h index d19c2ba801..e3bc373841 100644 --- a/tools/skiaserve/Request.h +++ b/tools/skiaserve/Request.h @@ -19,9 +19,7 @@ #include "UrlDataManager.h" -namespace sk_gpu_test { class GrContextFactory; -} struct MHD_Connection; struct MHD_PostProcessor; @@ -71,7 +69,7 @@ private: GrContext* getContext(); sk_sp fPicture; - sk_gpu_test::GrContextFactory* fContextFactory; + GrContextFactory* fContextFactory; SkAutoTUnref fSurface; bool fGPUEnabled; };