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

Review URL: https://codereview.chromium.org/1815823002
diff --git a/bench/nanobench.cpp b/bench/nanobench.cpp
index c0f674f..235de02 100644
--- a/bench/nanobench.cpp
+++ b/bench/nanobench.cpp
@@ -56,6 +56,9 @@
     #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<GrContextFactory> gGrFactory;
 #endif
 
@@ -155,21 +158,21 @@
 #if SK_SUPPORT_GPU
 struct GPUTarget : public Target {
     explicit GPUTarget(const Config& c) : Target(c), gl(nullptr) { }
-    SkGLContext* gl;
+    GLContext* gl;
 
     void setup() override {
         this->gl->makeCurrent();
         // Make sure we're done with whatever came before.
-        SK_GL(*this->gl, Finish());
+        GR_GL_CALL(this->gl->gl(), Finish());
     }
     void endTiming() override {
         if (this->gl) {
-            SK_GL(*this->gl, Flush());
+            GR_GL_CALL(this->gl->gl(), Flush());
             this->gl->waitOnSyncOrSwap();
         }
     }
     void fence() override {
-        SK_GL(*this->gl, Finish());
+        GR_GL_CALL(this->gl->gl(), Finish());
     }
 
     bool needsFrameTiming(int* maxFrameLag) const override {
@@ -200,16 +203,16 @@
     }
     void fillOptions(ResultsWriter* log) override {
         const GrGLubyte* version;
-        SK_GL_RET(*this->gl, version, GetString(GR_GL_VERSION));
+        GR_GL_CALL_RET(this->gl->gl(), version, GetString(GR_GL_VERSION));
         log->configOption("GL_VERSION", (const char*)(version));
 
-        SK_GL_RET(*this->gl, version, GetString(GR_GL_RENDERER));
+        GR_GL_CALL_RET(this->gl->gl(), version, GetString(GR_GL_RENDERER));
         log->configOption("GL_RENDERER", (const char*) version);
 
-        SK_GL_RET(*this->gl, version, GetString(GR_GL_VENDOR));
+        GR_GL_CALL_RET(this->gl->gl(), version, GetString(GR_GL_VENDOR));
         log->configOption("GL_VENDOR", (const char*) version);
 
-        SK_GL_RET(*this->gl, version, GetString(GR_GL_SHADING_LANGUAGE_VERSION));
+        GR_GL_CALL_RET(this->gl->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 5e4efbf..844811e 100644
--- a/bench/nanobench.h
+++ b/bench/nanobench.h
@@ -29,8 +29,8 @@
     SkColorProfileType profile;
     int samples;
 #if SK_SUPPORT_GPU
-    GrContextFactory::GLContextType ctxType;
-    GrContextFactory::GLContextOptions ctxOptions;
+    sk_gpu_test::GrContextFactory::GLContextType ctxType;
+    sk_gpu_test::GrContextFactory::GLContextOptions ctxOptions;
     bool useDFText;
 #else
     int bogusInt;
diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt
index d3ffa35..67cdb1d 100644
--- a/cmake/CMakeLists.txt
+++ b/cmake/CMakeLists.txt
@@ -90,7 +90,6 @@
     ../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/*
@@ -121,8 +120,6 @@
     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 d93cd29..79b9e8d 100644
--- a/dm/DM.cpp
+++ b/dm/DM.cpp
@@ -70,6 +70,8 @@
 DEFINE_bool(simpleCodec, false, "Only decode images to native scale");
 
 using namespace DM;
+using sk_gpu_test::GrContextFactory;
+using sk_gpu_test::GLContext;
 
 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
 
@@ -1416,7 +1418,7 @@
 namespace skiatest {
 namespace {
 typedef void(*TestWithGrContext)(skiatest::Reporter*, GrContext*);
-typedef void(*TestWithGrContextAndGLContext)(skiatest::Reporter*, GrContext*, SkGLContext*);
+typedef void(*TestWithGrContextAndGLContext)(skiatest::Reporter*, GrContext*, GLContext*);
 #if SK_SUPPORT_GPU
 template<typename T>
 void call_test(T test, skiatest::Reporter* reporter, const GrContextFactory::ContextInfo& context);
diff --git a/dm/DMGpuSupport.h b/dm/DMGpuSupport.h
index 73adeb0..c713244 100644
--- a/dm/DMGpuSupport.h
+++ b/dm/DMGpuSupport.h
@@ -28,12 +28,13 @@
 
 static const bool kGPUDisabled = false;
 
-static inline sk_sp<SkSurface> NewGpuSurface(GrContextFactory* grFactory,
-                                             GrContextFactory::GLContextType type,
-                                             GrContextFactory::GLContextOptions options,
-                                             SkImageInfo info,
-                                             int samples,
-                                             bool useDIText) {
+static inline sk_sp<SkSurface> NewGpuSurface(
+        sk_gpu_test::GrContextFactory* grFactory,
+        sk_gpu_test::GrContextFactory::GLContextType type,
+        sk_gpu_test::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,
@@ -59,6 +60,7 @@
     void dumpGpuStats(SkString*) const {}
 };
 
+namespace sk_gpu_test {
 class GrContextFactory {
 public:
     GrContextFactory() {};
@@ -83,14 +85,15 @@
 
     void abandonContexts() {}
 };
+}  // namespace sk_gpu_test
 
 namespace DM {
 
 static const bool kGPUDisabled = true;
 
-static inline SkSurface* NewGpuSurface(GrContextFactory*,
-                                       GrContextFactory::GLContextType,
-                                       GrContextFactory::GLContextOptions,
+static inline SkSurface* NewGpuSurface(sk_gpu_test::GrContextFactory*,
+                                       sk_gpu_test::GrContextFactory::GLContextType,
+                                       sk_gpu_test::GrContextFactory::GLContextOptions,
                                        SkImageInfo,
                                        int,
                                        bool) {
diff --git a/dm/DMSrcSink.cpp b/dm/DMSrcSink.cpp
index 9e9ba9e..e704f74 100644
--- a/dm/DMSrcSink.cpp
+++ b/dm/DMSrcSink.cpp
@@ -45,6 +45,8 @@
             " 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 1a56e81..3a35acf 100644
--- a/dm/DMSrcSink.h
+++ b/dm/DMSrcSink.h
@@ -232,7 +232,8 @@
 
 class GPUSink : public Sink {
 public:
-    GPUSink(GrContextFactory::GLContextType, GrContextFactory::GLContextOptions,
+    GPUSink(sk_gpu_test::GrContextFactory::GLContextType,
+            sk_gpu_test::GrContextFactory::GLContextOptions,
             int samples, bool diText, SkColorType colorType, SkColorProfileType profileType,
             bool threaded);
 
@@ -241,13 +242,13 @@
     const char* fileExtension() const override { return "png"; }
     SinkFlags flags() const override { return SinkFlags{ SinkFlags::kGPU, SinkFlags::kDirect }; }
 private:
-    GrContextFactory::GLContextType    fContextType;
-    GrContextFactory::GLContextOptions fContextOptions;
-    int                                fSampleCount;
-    bool                               fUseDIText;
-    SkColorType                        fColorType;
-    SkColorProfileType                 fProfileType;
-    bool                               fThreaded;
+    sk_gpu_test::GrContextFactory::GLContextType    fContextType;
+    sk_gpu_test::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 5333b17..a84e19b 100644
--- a/gm/image.cpp
+++ b/gm/image.cpp
@@ -433,7 +433,7 @@
     GrContext* context = nullptr;
 #if SK_SUPPORT_GPU
     context = canvas->getGrContext();
-    GrContextFactory factory;
+    sk_gpu_test::GrContextFactory factory;
 #endif
     if (!context) {
         skiagm::GM::DrawGpuOnlyMessage(canvas);
diff --git a/gyp/SampleApp.gyp b/gyp/SampleApp.gyp
index 47a2e90..52061f2 100644
--- a/gyp/SampleApp.gyp
+++ b/gyp/SampleApp.gyp
@@ -153,6 +153,7 @@
         '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/angle.gyp b/gyp/angle.gyp
index d555cb9..4c1cd1d 100644
--- a/gyp/angle.gyp
+++ b/gyp/angle.gyp
@@ -11,7 +11,7 @@
       'type': 'none',
       'conditions': [
         [ 'skia_angle', {
-          'direct_dependent_settings': {
+          'all_dependent_settings': {
             'include_dirs': [
               '../third_party/externals/angle2/include',
             ],
diff --git a/gyp/flags.gyp b/gyp/flags.gyp
index 258ca40..166e24b 100644
--- a/gyp/flags.gyp
+++ b/gyp/flags.gyp
@@ -24,7 +24,14 @@
         '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 80fc932..2fedbed 100644
--- a/gyp/gpu.gyp
+++ b/gyp/gpu.gyp
@@ -102,11 +102,6 @@
       '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).
       ],
@@ -151,23 +146,6 @@
             ],
           },
         }],
-        [ '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': [
@@ -179,46 +157,12 @@
             '../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 9e1f911..37a7d31 100644
--- a/gyp/gpu.gypi
+++ b/gyp/gpu.gypi
@@ -318,6 +318,7 @@
       '<(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',
@@ -408,8 +409,6 @@
       '<(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',
@@ -422,8 +421,6 @@
       '<(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',
@@ -501,60 +498,8 @@
       '<(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 36db434..d50e00c 100644
--- a/gyp/gputest.gyp
+++ b/gyp/gputest.gyp
@@ -9,28 +9,96 @@
       '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/gpu',
+        '../src/utils',
+        '../tools/gpu',
       ],
-      'direct_dependent_settings': {
+      'all_dependent_settings': {
         'include_dirs': [
-          '../src/gpu',
-          '../../src/gpu',
+          '../tools/gpu',
         ],
       },
+      'dependencies': [
+        'skia_lib.gyp:skia_lib',
+      ],
       'sources': [
-        '<(skia_src_path)/gpu/GrContextFactory.cpp',
-        '<(skia_src_path)/gpu/GrContextFactory.h',
-        '<(skia_src_path)/gpu/GrTest.cpp',
-        '<(skia_src_path)/gpu/GrTest.h',
+        '<!@(python find.py ../tools/gpu "*")'
+      ],
+      'conditions': [
+        [ 'skia_mesa and skia_os == "linux"', {
+          'link_settings': {
+            'libraries': [
+              '-lOSMesa',
+            ],
+          },
+        }],
+        [ 'skia_mesa and skia_os == "mac"', {
+          'link_settings': {
+            'libraries': [
+              '/opt/X11/lib/libOSMesa.dylib',
+            ],
+          },
+          'include_dirs': [
+             '/opt/X11/include/',
+          ],
+        }],
+        [ 'skia_angle', {
+          'dependencies': [
+            'angle.gyp:*',
+          ],
+          'export_dependent_settings': [
+            'angle.gyp:*',
+          ],
+        }],
+        [ 'skia_os == "android"', {
+          'defines': [
+            'GR_GL_USE_NEW_SHADER_SOURCE_SIGNATURE=1',
+          ],
+          'link_settings': {
+            'libraries': [
+              '-lGLESv2',
+              '-lEGL',
+            ],
+          },
+        }],
+        ['skia_os != "win"', {
+          'sources/': [ ['exclude', '_win\.(h|cpp)$'],],
+        }],
+        ['skia_os != "mac"', {
+          'sources/': [ ['exclude', '_mac\.(h|cpp|m|mm)$'],],
+        }],
+        ['skia_os != "linux" and skia_os != "chromeos"', {
+          'sources/': [ ['exclude', '_glx\.(h|cpp)$'],],
+        }],
+        ['skia_os != "ios"', {
+          'sources/': [ ['exclude', '_iOS\.(h|cpp|m|mm)$'],],
+        }],
+        ['skia_os != "android"', {
+          'sources/': [ ['exclude', '_android\.(h|cpp)$'],],
+        }],
+        ['skia_egl == 0', {
+          'sources/': [ ['exclude', '_egl\.(h|cpp)$'],],
+        }],
+        [ 'skia_mesa == 0', {
+          'sources/': [
+            ['exclude', '_mesa\.(h|cpp)$'],
+          ],
+        }],
+        [ 'skia_angle == 0', {
+          'sources/': [
+            ['exclude', '_angle\.(h|cpp)$'],
+          ],
+        }],
+        [ 'skia_command_buffer == 0', {
+          'sources/': [ ['exclude', '_command_buffer\.(h|cpp)$'], ],
+        }],
       ],
     },
   ],
diff --git a/gyp/kilobench.gyp b/gyp/kilobench.gyp
index 2d0ae22..8223547 100644
--- a/gyp/kilobench.gyp
+++ b/gyp/kilobench.gyp
@@ -17,6 +17,7 @@
         '../gm',
         '../include/private',
         '../src/core',
+        '../src/gpu',
         '../tools/VisualBench',
       ],
       'sources': [ 
@@ -26,6 +27,7 @@
       ],
       'dependencies': [
         'flags.gyp:flags',
+        'gpu.gyp:skgpu',
         'gputest.gyp:skgputest',
         'jsoncpp.gyp:jsoncpp',
         'skia_lib.gyp:skia_lib',
diff --git a/gyp/pathops_unittest.gyp b/gyp/pathops_unittest.gyp
index 14b231c..a95d54c 100644
--- a/gyp/pathops_unittest.gyp
+++ b/gyp/pathops_unittest.gyp
@@ -37,15 +37,6 @@
             '-llog',
           ],
         }],
-        [ 'skia_gpu == 1', {
-          'include_dirs': [
-            '../src/gpu',
-          ],
-	  'sources': [
-            '../src/gpu/GrContextFactory.cpp',
-            '../src/gpu/GrContextFactory.h',
-          ]
-        }],
       ],
     },
   ],
diff --git a/gyp/skiaserve.gyp b/gyp/skiaserve.gyp
index 2cd13b5..32b73f7 100644
--- a/gyp/skiaserve.gyp
+++ b/gyp/skiaserve.gyp
@@ -14,6 +14,7 @@
       'type': 'executable',
       'include_dirs': [
         '../src/core',
+        '../src/gpu',
         '../src/ports',
         '../tools/debugger',
         '../tools/json',
diff --git a/gyp/views.gyp b/gyp/views.gyp
index 3db7e40..7b5eb78 100644
--- a/gyp/views.gyp
+++ b/gyp/views.gyp
@@ -125,6 +125,11 @@
             '../include/gpu',
           ],
         }],
+        [ 'skia_angle', {
+          'dependencies': [
+            'angle.gyp:*',
+          ],
+        }],
         [ 'skia_use_sdl == 1', {
           'defines': [
             'SK_USE_SDL',
diff --git a/gyp/visualbench.gyp b/gyp/visualbench.gyp
index 3ce9f17..371b665 100644
--- a/gyp/visualbench.gyp
+++ b/gyp/visualbench.gyp
@@ -20,6 +20,7 @@
         '../include/private',
         '../src/core',
         '../src/effects',
+        '../src/gpu',
         '../src/images',
         '../src/image',
         '../src/pdf',
diff --git a/include/gpu/gl/GrGLInterface.h b/include/gpu/gl/GrGLInterface.h
index cbf9b1a..4ba5166 100644
--- a/include/gpu/gl/GrGLInterface.h
+++ b/include/gpu/gl/GrGLInterface.h
@@ -43,39 +43,18 @@
  */
 SK_API const GrGLInterface* GrGLCreateNativeInterface();
 
-#if SK_MESA
-/**
- * Creates a GrGLInterface for an OSMesa context.
- */
-SK_API const GrGLInterface* GrGLCreateMesaInterface();
-#endif
-
-#if SK_ANGLE
-/**
- * Creates a GrGLInterface for an ANGLE context.
- */
-SK_API const GrGLInterface* GrGLCreateANGLEInterface();
-#endif
-
-#if SK_COMMAND_BUFFER
-/**
- * Creates a GrGLInterface for a Command Buffer context.
- */
-SK_API const GrGLInterface* GrGLCreateCommandBufferInterface();
+#if GR_GL_PER_GL_FUNC_CALLBACK
+typedef void (*GrGLInterfaceCallbackProc)(const GrGLInterface*);
+typedef intptr_t GrGLInterfaceCallbackData;
 #endif
 
 /**
  * Creates a null GrGLInterface that doesn't draw anything. Used for measuring
- * CPU overhead.
+ * CPU overhead. TODO: We would like to move this to tools/gpu/gl/null but currently
+ * Chromium is using it in its unit tests.
  */
 const SK_API GrGLInterface* GrGLCreateNullInterface();
 
-/**
- * Creates a debugging GrGLInterface that doesn't draw anything. Used for
- * finding memory leaks and invalid memory accesses.
- */
-const GrGLInterface* GrGLCreateDebugInterface();
-
 /** Function that returns a new interface identical to "interface" but without support for
     GL_NV_path_rendering. */
 const GrGLInterface* GrGLInterfaceRemoveNVPR(const GrGLInterface*);
diff --git a/include/gpu/gl/SkNullGLContext.h b/include/gpu/gl/SkNullGLContext.h
deleted file mode 100644
index 5a2a73f..0000000
--- a/include/gpu/gl/SkNullGLContext.h
+++ /dev/null
@@ -1,26 +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 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
deleted file mode 100644
index ea5e877..0000000
--- a/include/gpu/gl/angle/SkANGLEGLContext.h
+++ /dev/null
@@ -1,61 +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 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
deleted file mode 100644
index 47f3fd9..0000000
--- a/include/gpu/gl/command_buffer/SkCommandBufferGLContext.h
+++ /dev/null
@@ -1,63 +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 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/include/views/SkOSWindow_Win.h b/include/views/SkOSWindow_Win.h
index a1b222d..eb8b1fc 100644
--- a/include/views/SkOSWindow_Win.h
+++ b/include/views/SkOSWindow_Win.h
@@ -98,10 +98,11 @@
 #if SK_SUPPORT_GPU
     void*               fHGLRC;
 #if SK_ANGLE
-    EGLDisplay          fDisplay;
-    EGLContext          fContext;
-    EGLSurface          fSurface;
-    EGLConfig           fConfig;
+    EGLDisplay                        fDisplay;
+    EGLContext                        fContext;
+    EGLSurface                        fSurface;
+    EGLConfig                         fConfig;
+    SkAutoTUnref<const GrGLInterface> fANGLEInterface;
 #endif // SK_ANGLE
 #if SK_COMMAND_BUFFER
     SkCommandBufferGLContext* fCommandBuffer;
diff --git a/samplecode/SampleApp.cpp b/samplecode/SampleApp.cpp
index e0d152d..780eabd 100644
--- a/samplecode/SampleApp.cpp
+++ b/samplecode/SampleApp.cpp
@@ -33,11 +33,14 @@
 #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"
+#   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
 #else
 class GrContext;
 #endif
@@ -233,7 +236,7 @@
                 break;
 #if SK_ANGLE
             case kANGLE_DeviceType:
-                glInterface.reset(GrGLCreateANGLEInterface());
+                glInterface.reset(sk_gpu_test::CreateANGLEGLInterface());
                 break;
 #endif // SK_ANGLE
 #if SK_COMMAND_BUFFER
diff --git a/src/gpu/gl/GrGLTestInterface.h b/src/gpu/gl/GrGLTestInterface.h
index c5f91ee..936d9b8 100644
--- a/src/gpu/gl/GrGLTestInterface.h
+++ b/src/gpu/gl/GrGLTestInterface.h
@@ -11,6 +11,10 @@
 #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/src/gpu/gl/SkNullGLContext.cpp b/src/gpu/gl/SkNullGLContext.cpp
deleted file mode 100644
index a2c5066..0000000
--- a/src/gpu/gl/SkNullGLContext.cpp
+++ /dev/null
@@ -1,26 +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 "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
deleted file mode 100644
index 48f9d8c..0000000
--- a/src/gpu/gl/angle/GrGLCreateANGLEInterface.cpp
+++ /dev/null
@@ -1,57 +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.
- */
-
-#include "gl/GrGLInterface.h"
-#include "gl/GrGLAssembleInterface.h"
-#include "../ports/SkOSLibrary.h"
-
-#include <EGL/egl.h>
-
-namespace {
-struct Libs {
-    void* fGLLib;
-    void* fEGLLib;
-};
-}
-
-static GrGLFuncPtr angle_get_gl_proc(void* ctx, const char name[]) {
-    const Libs* libs = reinterpret_cast<const Libs*>(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/src/gpu/gl/angle/SkANGLEGLContext.cpp b/src/gpu/gl/angle/SkANGLEGLContext.cpp
deleted file mode 100644
index c6ea443..0000000
--- a/src/gpu/gl/angle/SkANGLEGLContext.cpp
+++ /dev/null
@@ -1,229 +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.
- */
-
-#include "gl/angle/SkANGLEGLContext.h"
-
-#include <EGL/egl.h>
-#include <EGL/eglext.h>
-
-#include "gl/GrGLDefines.h"
-#include "gl/GrGLUtil.h"
-
-#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
-
-void* SkANGLEGLContext::GetD3DEGLDisplay(void* nativeDisplay, bool useGLBackend) {
-    PFNEGLGETPLATFORMDISPLAYEXTPROC eglGetPlatformDisplayEXT;
-    eglGetPlatformDisplayEXT =
-        (PFNEGLGETPLATFORMDISPLAYEXTPROC)eglGetProcAddress("eglGetPlatformDisplayEXT");
-
-    if (!eglGetPlatformDisplayEXT) {
-        return eglGetDisplay(static_cast<EGLNativeDisplayType>(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
-        };
-        display = eglGetPlatformDisplayEXT(EGL_PLATFORM_ANGLE_ANGLE, nativeDisplay, attribs);
-    } else {
-        // 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
-            },
-            {
-                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]);
-        }
-    }
-    return display;
-}
-
-SkANGLEGLContext::SkANGLEGLContext(bool useGLBackend)
-    : fContext(EGL_NO_CONTEXT)
-    , fDisplay(EGL_NO_DISPLAY)
-    , fSurface(EGL_NO_SURFACE) {
-
-    EGLint numConfigs;
-    static const EGLint configAttribs[] = {
-        EGL_SURFACE_TYPE, EGL_PBUFFER_BIT,
-        EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
-        EGL_RED_SIZE, 8,
-        EGL_GREEN_SIZE, 8,
-        EGL_BLUE_SIZE, 8,
-        EGL_ALPHA_SIZE, 8,
-        EGL_NONE
-    };
-
-    fIsGLBackend = useGLBackend;
-    fDisplay = GetD3DEGLDisplay(EGL_DEFAULT_DISPLAY, useGLBackend);
-    if (EGL_NO_DISPLAY == fDisplay) {
-        SkDebugf("Could not create EGL display!");
-        return;
-    }
-
-    EGLint majorVersion;
-    EGLint minorVersion;
-    eglInitialize(fDisplay, &majorVersion, &minorVersion);
-
-    EGLConfig surfaceConfig;
-    eglChooseConfig(fDisplay, configAttribs, &surfaceConfig, 1, &numConfigs);
-
-    static const EGLint contextAttribs[] = {
-        EGL_CONTEXT_CLIENT_VERSION, 2,
-        EGL_NONE
-    };
-    fContext = eglCreateContext(fDisplay, surfaceConfig, nullptr, contextAttribs);
-
-
-    static const EGLint surfaceAttribs[] = {
-        EGL_WIDTH, 1,
-        EGL_HEIGHT, 1,
-        EGL_NONE
-    };
-
-    fSurface = eglCreatePbufferSurface(fDisplay, surfaceConfig, surfaceAttribs);
-
-    eglMakeCurrent(fDisplay, fSurface, fSurface, fContext);
-
-    SkAutoTUnref<const GrGLInterface> gl(GrGLCreateANGLEInterface());
-    if (nullptr == gl.get()) {
-        SkDebugf("Could not create ANGLE GL interface!\n");
-        this->destroyGLContext();
-        return;
-    }
-    if (!gl->validate()) {
-        SkDebugf("Could not validate ANGLE GL interface!\n");
-        this->destroyGLContext();
-        return;
-    }
-
-    this->init(gl.release());
-}
-
-SkANGLEGLContext::~SkANGLEGLContext() {
-    this->teardown();
-    this->destroyGLContext();
-}
-
-GrEGLImage SkANGLEGLContext::texture2DToEGLImage(GrGLuint texID) const {
-    if (!this->gl()->hasExtension("EGL_KHR_gl_texture_2D_image")) {
-        return GR_EGL_NO_IMAGE;
-    }
-    GrEGLImage img;
-    GrEGLint attribs[] = { GR_EGL_GL_TEXTURE_LEVEL, 0,
-                           GR_EGL_IMAGE_PRESERVED, GR_EGL_TRUE,
-                           GR_EGL_NONE };
-    // 64 bit cast is to shut Visual C++ up about casting 32 bit value to a pointer.
-    GrEGLClientBuffer clientBuffer = reinterpret_cast<GrEGLClientBuffer>((uint64_t)texID);
-    GR_GL_CALL_RET(this->gl(), img,
-                   EGLCreateImage(fDisplay, fContext, GR_EGL_GL_TEXTURE_2D, clientBuffer,
-                                  attribs));
-    return img;
-}
-
-void SkANGLEGLContext::destroyEGLImage(GrEGLImage image) const {
-    GR_GL_CALL(this->gl(), EGLDestroyImage(fDisplay, image));
-}
-
-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) {
-        return 0;
-    }
-    GrGLuint texID;
-    GR_GL_CALL(this->gl(), GenTextures(1, &texID));
-    if (!texID) {
-        return 0;
-    }
-    GR_GL_CALL(this->gl(), BindTexture(GR_GL_TEXTURE_EXTERNAL, texID));
-    if (GR_GL_GET_ERROR(this->gl()) != GR_GL_NO_ERROR) {
-        GR_GL_CALL(this->gl(), DeleteTextures(1, &texID));
-        return 0;
-    }
-    glEGLImageTargetTexture2D(GR_GL_TEXTURE_EXTERNAL, image);
-    if (GR_GL_GET_ERROR(this->gl()) != GR_GL_NO_ERROR) {
-        GR_GL_CALL(this->gl(), DeleteTextures(1, &texID));
-        return 0;
-    }
-    return texID;
-}
-
-SkGLContext* SkANGLEGLContext::createNew() const {
-#ifdef SK_BUILD_FOR_WIN
-    SkGLContext* ctx = fIsGLBackend ? SkANGLEGLContext::CreateOpenGL()
-                                    : SkANGLEGLContext::CreateDirectX();
-#else
-    SkGLContext* ctx = SkANGLEGLContext::CreateOpenGL();
-#endif
-    if (ctx) {
-        ctx->makeCurrent();
-    }
-    return ctx;
-}
-
-void SkANGLEGLContext::destroyGLContext() {
-    if (fDisplay) {
-        eglMakeCurrent(fDisplay, 0, 0, 0);
-
-        if (fContext) {
-            eglDestroyContext(fDisplay, fContext);
-            fContext = EGL_NO_CONTEXT;
-        }
-
-        if (fSurface) {
-            eglDestroySurface(fDisplay, fSurface);
-            fSurface = EGL_NO_SURFACE;
-        }
-
-        //TODO should we close the display?
-        fDisplay = EGL_NO_DISPLAY;
-    }
-}
-
-void SkANGLEGLContext::onPlatformMakeCurrent() const {
-    if (!eglMakeCurrent(fDisplay, fSurface, fSurface, fContext)) {
-        SkDebugf("Could not set the context.\n");
-    }
-}
-
-void SkANGLEGLContext::onPlatformSwapBuffers() const {
-    if (!eglSwapBuffers(fDisplay, fSurface)) {
-        SkDebugf("Could not complete eglSwapBuffers.\n");
-    }
-}
-
-GrGLFuncPtr SkANGLEGLContext::onPlatformGetProcAddress(const char* name) const {
-    return eglGetProcAddress(name);
-}
diff --git a/src/gpu/gl/debug/SkDebugGLContext.cpp b/src/gpu/gl/debug/SkDebugGLContext.cpp
deleted file mode 100644
index ecb27db..0000000
--- a/src/gpu/gl/debug/SkDebugGLContext.cpp
+++ /dev/null
@@ -1,16 +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.
- */
-
-#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
deleted file mode 100644
index 1ea7b62..0000000
--- a/src/gpu/gl/debug/SkDebugGLContext.h
+++ /dev/null
@@ -1,27 +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 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/src/gpu/gl/mesa/GrGLCreateMesaInterface.cpp b/src/gpu/gl/mesa/GrGLCreateMesaInterface.cpp
deleted file mode 100644
index 6a04d4f..0000000
--- a/src/gpu/gl/mesa/GrGLCreateMesaInterface.cpp
+++ /dev/null
@@ -1,24 +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 "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/src/gpu/gl/mesa/SkMesaGLContext.cpp b/src/gpu/gl/mesa/SkMesaGLContext.cpp
deleted file mode 100644
index eeccbd6..0000000
--- a/src/gpu/gl/mesa/SkMesaGLContext.cpp
+++ /dev/null
@@ -1,100 +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 <GL/osmesa.h>
-
-#include "gl/mesa/SkMesaGLContext.h"
-#include "gl/GrGLDefines.h"
-
-static const GrGLint gBOGUS_SIZE = 16;
-
-SkMesaGLContext::SkMesaGLContext()
-    : fContext(static_cast<Context>(0))
-    , fImage(nullptr) {
-    GR_STATIC_ASSERT(sizeof(Context) == sizeof(OSMesaContext));
-
-    /* Create an RGBA-mode context */
-#if OSMESA_MAJOR_VERSION * 100 + OSMESA_MINOR_VERSION >= 305
-    /* specify Z, stencil, accum sizes */
-    fContext = (Context)OSMesaCreateContextExt(OSMESA_BGRA, 0, 0, 0, nullptr);
-#else
-    fContext = (Context)OSMesaCreateContext(OSMESA_BGRA, nullptr);
-#endif
-    if (!fContext) {
-        SkDebugf("OSMesaCreateContext failed!\n");
-        this->destroyGLContext();
-        return;
-    }
-    // Allocate the image buffer
-    fImage = (GrGLubyte *) sk_malloc_throw(gBOGUS_SIZE * gBOGUS_SIZE *
-                                           4 * sizeof(GrGLubyte));
-    if (!fImage) {
-        SkDebugf("Alloc image buffer failed!\n");
-        this->destroyGLContext();
-        return;
-    }
-
-    // Bind the buffer to the context and make it current
-    if (!OSMesaMakeCurrent((OSMesaContext)fContext,
-                           fImage,
-                           GR_GL_UNSIGNED_BYTE,
-                           gBOGUS_SIZE,
-                           gBOGUS_SIZE)) {
-        SkDebugf("OSMesaMakeCurrent failed!\n");
-        this->destroyGLContext();
-        return;
-    }
-
-    SkAutoTUnref<const GrGLInterface> gl(GrGLCreateMesaInterface());
-    if (nullptr == gl.get()) {
-        SkDebugf("Could not create GL interface!\n");
-        this->destroyGLContext();
-        return;
-    }
-
-    if (!gl->validate()) {
-        SkDebugf("Could not validate GL interface!\n");
-        this->destroyGLContext();
-        return;
-    }
-
-    this->init(gl.release());
-}
-
-SkMesaGLContext::~SkMesaGLContext() {
-    this->teardown();
-    this->destroyGLContext();
-}
-
-void SkMesaGLContext::destroyGLContext() {
-    if (fImage) {
-        sk_free(fImage);
-        fImage = nullptr;
-    }
-
-    if (fContext) {
-        OSMesaDestroyContext((OSMesaContext)fContext);
-        fContext = static_cast<Context>(0);
-    }
-}
-
-
-
-void SkMesaGLContext::onPlatformMakeCurrent() const {
-    if (fContext) {
-        if (!OSMesaMakeCurrent((OSMesaContext)fContext, fImage,
-                               GR_GL_UNSIGNED_BYTE, gBOGUS_SIZE, gBOGUS_SIZE)) {
-            SkDebugf("Could not make MESA context current.");
-        }
-    }
-}
-
-void SkMesaGLContext::onPlatformSwapBuffers() const { }
-
-GrGLFuncPtr SkMesaGLContext::onPlatformGetProcAddress(const char* procName) const {
-    return OSMesaGetProcAddress(procName);
-}
diff --git a/src/gpu/gl/mesa/SkMesaGLContext.h b/src/gpu/gl/mesa/SkMesaGLContext.h
deleted file mode 100644
index 7f700b6..0000000
--- a/src/gpu/gl/mesa/SkMesaGLContext.h
+++ /dev/null
@@ -1,44 +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 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
deleted file mode 100644
index 855f0dc..0000000
--- a/src/gpu/gl/nacl/SkCreatePlatformGLContext_nacl.cpp
+++ /dev/null
@@ -1,12 +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.
- */
-#include "gl/SkGLContext.h"
-
-SkGLContext* SkCreatePlatformGLContext(GrGLStandard forcedGpuAPI, SkGLContext* shareContext) {
-    SkASSERT(!shareContext);
-    return nullptr;
-}
diff --git a/src/views/win/SkOSWindow_win.cpp b/src/views/win/SkOSWindow_win.cpp
index 8b0211d..e948323 100644
--- a/src/views/win/SkOSWindow_win.cpp
+++ b/src/views/win/SkOSWindow_win.cpp
@@ -20,27 +20,23 @@
 #include "SkGraphics.h"
 
 #if SK_ANGLE
-#include "gl/angle/SkANGLEGLContext.h"
+#include "gl/GrGLAssembleInterface.h"
 #include "gl/GrGLInterface.h"
 #include "GLES2/gl2.h"
-
-#define ANGLE_GL_CALL(IFACE, X)                                 \
-    do {                                                        \
-        (IFACE)->fFunctions.f##X;                               \
-    } while (false)
-
+#include <EGL/egl.h>
+#include <EGL/eglext.h>
 #endif // SK_ANGLE
 
 #if SK_COMMAND_BUFFER
 #include "gl/command_buffer/SkCommandBufferGLContext.h"
-
-#define COMMAND_BUFFER_GL_CALL(IFACE, X)                                 \
-    do {                                                        \
-        (IFACE)->fFunctions.f##X;                               \
-    } while (false)
-
 #endif // SK_COMMAND_BUFFER
 
+#define GL_CALL(IFACE, X)                                 \
+    SkASSERT(IFACE);                                      \
+    do {                                                  \
+        (IFACE)->fFunctions.f##X;                         \
+    } while (false)
+
 #define WM_EVENT_CALLBACK (WM_USER+0)
 
 void post_skwinevent(HWND hwnd)
@@ -395,6 +391,69 @@
 
 #if SK_ANGLE
 
+static 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;
+}
+
+struct ANGLEAssembleContext {
+    ANGLEAssembleContext() {
+        fEGL = GetModuleHandle("libEGL.dll");
+        fGL = GetModuleHandle("libEGLESv2.dll");
+    }
+
+    bool isValid() const { return SkToBool(fEGL) && SkToBool(fGL); }
+
+    HMODULE fEGL;
+    HMODULE fGL;
+};
+
+static GrGLFuncPtr angle_get_gl_proc(void* ctx, const char name[]) {
+    const ANGLEAssembleContext& context = *reinterpret_cast<const ANGLEAssembleContext*>(ctx);
+    GrGLFuncPtr proc = (GrGLFuncPtr) GetProcAddress(context.fGL, name);
+    if (proc) {
+        return proc;
+    }
+    proc = (GrGLFuncPtr) GetProcAddress(context.fEGL, name);
+    if (proc) {
+        return proc;
+    }
+    return eglGetProcAddress(name);
+}
+
+static const GrGLInterface* get_angle_gl_interface() {
+    ANGLEAssembleContext context;
+    if (!context.isValid()) {
+        return nullptr;
+    }
+    return GrGLAssembleGLESInterface(&context, angle_get_gl_proc);
+}
+
 bool create_ANGLE(EGLNativeWindowType hWnd,
                   int msaaSampleCount,
                   EGLDisplay* eglDisplay,
@@ -418,7 +477,7 @@
         EGL_NONE, EGL_NONE
     };
 
-    EGLDisplay display = SkANGLEGLContext::GetD3DEGLDisplay(GetDC(hWnd), false);
+    EGLDisplay display = get_angle_egl_display(GetDC(hWnd));
 
     if (EGL_NO_DISPLAY == display) {
         SkDebugf("Could not create ANGLE egl display!\n");
@@ -500,32 +559,31 @@
         if (false == bResult) {
             return false;
         }
-        SkAutoTUnref<const GrGLInterface> intf(GrGLCreateANGLEInterface());
-
-        if (intf) {
-            ANGLE_GL_CALL(intf, ClearStencil(0));
-            ANGLE_GL_CALL(intf, ClearColor(0, 0, 0, 0));
-            ANGLE_GL_CALL(intf, StencilMask(0xffffffff));
-            ANGLE_GL_CALL(intf, Clear(GL_STENCIL_BUFFER_BIT |GL_COLOR_BUFFER_BIT));
+        fANGLEInterface.reset(get_angle_gl_interface());
+        if (!fANGLEInterface) {
+            this->detachANGLE();
+            return false;
         }
-    }
-    if (eglMakeCurrent(fDisplay, fSurface, fSurface, fContext)) {
+        GL_CALL(fANGLEInterface, ClearStencil(0));
+        GL_CALL(fANGLEInterface, ClearColor(0, 0, 0, 0));
+        GL_CALL(fANGLEInterface, StencilMask(0xffffffff));
+        GL_CALL(fANGLEInterface, Clear(GL_STENCIL_BUFFER_BIT |GL_COLOR_BUFFER_BIT));
+        if (!eglMakeCurrent(fDisplay, fSurface, fSurface, fContext)) {
+            this->detachANGLE();
+            return false;
+        }
         eglGetConfigAttrib(fDisplay, fConfig, EGL_STENCIL_SIZE, &info->fStencilBits);
         eglGetConfigAttrib(fDisplay, fConfig, EGL_SAMPLES, &info->fSampleCount);
 
-        SkAutoTUnref<const GrGLInterface> intf(GrGLCreateANGLEInterface());
-
-        if (intf ) {
-            ANGLE_GL_CALL(intf, Viewport(0, 0,
-                                         SkScalarRoundToInt(this->width()),
-                                         SkScalarRoundToInt(this->height())));
-        }
+        GL_CALL(fANGLEInterface, Viewport(0, 0, SkScalarRoundToInt(this->width()),
+                                                SkScalarRoundToInt(this->height())));
         return true;
     }
     return false;
 }
 
 void SkOSWindow::detachANGLE() {
+    fANGLEInterface.reset(nullptr);
     eglMakeCurrent(fDisplay, EGL_NO_SURFACE , EGL_NO_SURFACE , EGL_NO_CONTEXT);
 
     eglDestroyContext(fDisplay, fContext);
@@ -539,11 +597,7 @@
 }
 
 void SkOSWindow::presentANGLE() {
-    SkAutoTUnref<const GrGLInterface> intf(GrGLCreateANGLEInterface());
-
-    if (intf) {
-        ANGLE_GL_CALL(intf, Flush());
-    }
+    GL_CALL(fANGLEInterface, Flush());
 
     eglSwapBuffers(fDisplay, fSurface);
 }
@@ -559,10 +613,10 @@
 
         SkAutoTUnref<const GrGLInterface> intf(GrGLCreateCommandBufferInterface());
         if (intf) {
-            COMMAND_BUFFER_GL_CALL(intf, ClearStencil(0));
-            COMMAND_BUFFER_GL_CALL(intf, ClearColor(0, 0, 0, 0));
-            COMMAND_BUFFER_GL_CALL(intf, StencilMask(0xffffffff));
-            COMMAND_BUFFER_GL_CALL(intf, Clear(GL_STENCIL_BUFFER_BIT |GL_COLOR_BUFFER_BIT));
+            GL_CALL(intf, ClearStencil(0));
+            GL_CALL(intf, ClearColor(0, 0, 0, 0));
+            GL_CALL(intf, StencilMask(0xffffffff));
+            GL_CALL(intf, Clear(GL_STENCIL_BUFFER_BIT |GL_COLOR_BUFFER_BIT));
         }
     }
 
@@ -573,8 +627,7 @@
         SkAutoTUnref<const GrGLInterface> intf(GrGLCreateCommandBufferInterface());
 
         if (intf ) {
-            COMMAND_BUFFER_GL_CALL(intf, Viewport(0, 0,
-                                         SkScalarRoundToInt(this->width()),
+            GL_CALL(intf, Viewport(0, 0, SkScalarRoundToInt(this->width()),
                                          SkScalarRoundToInt(this->height())));
         }
         return true;
diff --git a/tests/EGLImageTest.cpp b/tests/EGLImageTest.cpp
index f19592c..7f0d7ea 100644
--- a/tests/EGLImageTest.cpp
+++ b/tests/EGLImageTest.cpp
@@ -11,9 +11,11 @@
 #include "GrContextFactory.h"
 #include "gl/GrGLGpu.h"
 #include "gl/GrGLUtil.h"
-#include "gl/SkGLContext.h"
+#include "gl/GLContext.h"
 
-static void cleanup(SkGLContext* glctx0, GrGLuint texID0, SkGLContext* glctx1, GrContext* grctx1,
+using sk_gpu_test::GLContext;
+
+static void cleanup(GLContext* glctx0, GrGLuint texID0, GLContext* glctx1, GrContext* grctx1,
                     const GrGLTextureInfo* grbackendtex1, GrEGLImage image1) {
     if (glctx1) {
         glctx1->makeCurrent();
@@ -91,7 +93,7 @@
         return;
     }
 
-    SkAutoTDelete<SkGLContext> glCtx1 = glCtx0->createNew();
+    SkAutoTDelete<GLContext> glCtx1 = glCtx0->createNew();
     if (!glCtx1) {
         return;
     }
diff --git a/tests/GLProgramsTest.cpp b/tests/GLProgramsTest.cpp
index 03938fb..57274e0 100644
--- a/tests/GLProgramsTest.cpp
+++ b/tests/GLProgramsTest.cpp
@@ -455,7 +455,7 @@
     // We suppress prints to avoid spew
     GrContextOptions opts;
     opts.fSuppressPrints = true;
-    GrContextFactory debugFactory(opts);
+    sk_gpu_test::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 800b18c..bd18883 100644
--- a/tests/GrContextFactoryTest.cpp
+++ b/tests/GrContextFactoryTest.cpp
@@ -13,6 +13,8 @@
 #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 54fcfc1..566ec12 100644
--- a/tests/GrPorterDuffTest.cpp
+++ b/tests/GrPorterDuffTest.cpp
@@ -1147,8 +1147,8 @@
 DEF_GPUTEST(PorterDuffNoDualSourceBlending, reporter, /*factory*/) {
     GrContextOptions opts;
     opts.fSuppressDualSourceBlending = true;
-    GrContextFactory mockFactory(opts);
-    GrContext* ctx = mockFactory.get(GrContextFactory::kNull_GLContextType);
+    sk_gpu_test::GrContextFactory mockFactory(opts);
+    GrContext* ctx = mockFactory.get(sk_gpu_test::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 15ee54c..8485fda 100644
--- a/tests/ImageTest.cpp
+++ b/tests/ImageTest.cpp
@@ -26,6 +26,8 @@
 #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 114207d..fc9e65e 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/SkGLContext.h"
+#include "gl/GLContext.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 4b19a85..119976f 100644
--- a/tests/Test.h
+++ b/tests/Test.h
@@ -11,9 +11,11 @@
 #include "SkTRegistry.h"
 #include "SkTypes.h"
 
+namespace sk_gpu_test {
 class GrContextFactory;
+class GLContext;
+}  // namespace sk_gpu_test
 class GrContext;
-class SkGLContext;
 
 namespace skiatest {
 
@@ -41,7 +43,7 @@
 #define REPORT_FAILURE(reporter, cond, message) \
     reporter->reportFailed(skiatest::Failure(__FILE__, __LINE__, cond, message))
 
-typedef void (*TestProc)(skiatest::Reporter*, GrContextFactory*);
+typedef void (*TestProc)(skiatest::Reporter*, sk_gpu_test::GrContextFactory*);
 
 struct Test {
     Test(const char* n, bool g, TestProc p) : name(n), needsGpu(g), proc(p) {}
@@ -83,7 +85,7 @@
 };
 template<typename T>
 void RunWithGPUTestContexts(T testFunction, GPUTestContexts contexts, Reporter* reporter,
-                            GrContextFactory* factory);
+                            sk_gpu_test::GrContextFactory* factory);
 
 /** Timer provides wall-clock duration since its creation. */
 class Timer {
@@ -133,32 +135,32 @@
         }                            \
     } while (0)
 
-#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 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 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, SkGLContext* a2
+#define GPUTEST_CONTEXT_ARGS2(a1, a2) GrContext* a1, sk_gpu_test::GLContext* 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*, GrContextFactory*); \
-    skiatest::TestRegistry name##TestRegistry(                       \
-            skiatest::Test(#name, true, test_##name));               \
-    void test_##name(skiatest::Reporter* reporter, GrContextFactory* factory)
+#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_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,               \
-                                         GrContextFactory* factory) {                \
+                                         sk_gpu_test::GrContextFactory* factory) {   \
         skiatest::RunWithGPUTestContexts(test_##name, contexts, reporter, factory);  \
     }                                                                                \
     skiatest::TestRegistry name##TestRegistry(                                       \
diff --git a/tests/TestConfigParsing.cpp b/tests/TestConfigParsing.cpp
index 9c030ed..4057a37 100644
--- a/tests/TestConfigParsing.cpp
+++ b/tests/TestConfigParsing.cpp
@@ -9,6 +9,8 @@
 #include "Test.h"
 #include <initializer_list>
 
+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 890042e..05ab9ff 100644
--- a/tests/TestTest.cpp
+++ b/tests/TestTest.cpp
@@ -9,7 +9,7 @@
 
 #if SK_SUPPORT_GPU
 #include "GrContext.h"
-#include "gl/SkGLContext.h"
+#include "gl/GLContext.h"
 #endif
 
 
@@ -64,7 +64,7 @@
 #endif
 
 // This is an example of a GPU test that tests a property that should work for all GPU contexts.
-// It uses the additional SkGLContext* glContext to implement the test.
+// It uses the additional GLContext* 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 1d22686..dd08354 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 5d21d1e..9783db8 100644
--- a/tests/skia_test.cpp
+++ b/tests/skia_test.cpp
@@ -24,6 +24,7 @@
 #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 1920a52..e9fbdfb 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/SkGLContext.h"
+#include "gl/GLContext.h"
 
 class GrContext;
 struct GrGLInterface;
diff --git a/tools/flags/SkCommonFlagsConfig.cpp b/tools/flags/SkCommonFlagsConfig.cpp
index 9e0fd60..1ee3130 100644
--- a/tools/flags/SkCommonFlagsConfig.cpp
+++ b/tools/flags/SkCommonFlagsConfig.cpp
@@ -9,6 +9,10 @@
 
 #include <stdlib.h>
 
+#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 39f1f97..abf5946 100644
--- a/tools/flags/SkCommonFlagsConfig.h
+++ b/tools/flags/SkCommonFlagsConfig.h
@@ -50,7 +50,7 @@
 // * backends that represent a shorthand of above (such as "msaa16" representing "gpu(samples=16)")
 class SkCommandLineConfigGpu : public SkCommandLineConfig {
   public:
-    typedef GrContextFactory::GLContextType ContextType;
+    typedef sk_gpu_test::GrContextFactory::GLContextType ContextType;
     SkCommandLineConfigGpu(const SkString& tag, const SkTArray<SkString>& viaParts,
                            ContextType contextType, bool useNVPR, bool useDIText, int samples,
                            SkColorType colorType, SkColorProfileType profileType);
diff --git a/src/gpu/GrContextFactory.cpp b/tools/gpu/GrContextFactory.cpp
similarity index 79%
rename from src/gpu/GrContextFactory.cpp
rename to tools/gpu/GrContextFactory.cpp
index 465c910..cb23014 100755
--- a/src/gpu/GrContextFactory.cpp
+++ b/tools/gpu/GrContextFactory.cpp
@@ -1,3 +1,4 @@
+
 /*
  * Copyright 2014 Google Inc.
  *
@@ -6,25 +7,23 @@
  */
 
 #include "GrContextFactory.h"
+#include "gl/GLContext.h"
 
 #if SK_ANGLE
-    #include "gl/angle/SkANGLEGLContext.h"
+    #include "gl/angle/GLContext_angle.h"
 #endif
 #if SK_COMMAND_BUFFER
-    #include "gl/command_buffer/SkCommandBufferGLContext.h"
+    #include "gl/command_buffer/GLContext_command_buffer.h"
 #endif
-#include "gl/debug/SkDebugGLContext.h"
+#include "gl/debug/DebugGLContext.h"
 #if SK_MESA
-    #include "gl/mesa/SkMesaGLContext.h"
+    #include "gl/mesa/GLContext_mesa.h"
 #endif
-#if SK_VULKAN
-#include "vk/GrVkBackendContext.h"
-#endif
-#include "gl/SkGLContext.h"
-#include "gl/SkNullGLContext.h"
+#include "gl/null/NullGLContext.h"
 #include "gl/GrGLGpu.h"
 #include "GrCaps.h"
 
+namespace sk_gpu_test {
 GrContextFactory::GrContextFactory() { }
 
 GrContextFactory::GrContextFactory(const GrContextOptions& opts)
@@ -74,43 +73,43 @@
             return ContextInfo(context.fGrContext, context.fGLContext);
         }
     }
-    SkAutoTDelete<SkGLContext> glCtx;
+    SkAutoTDelete<GLContext> glCtx;
     SkAutoTUnref<GrContext> grCtx;
     switch (type) {
         case kNative_GLContextType:
-            glCtx.reset(SkCreatePlatformGLContext(kNone_GrGLStandard));
+            glCtx.reset(CreatePlatformGLContext(kNone_GrGLStandard));
             break;
         case kGL_GLContextType:
-            glCtx.reset(SkCreatePlatformGLContext(kGL_GrGLStandard));
+            glCtx.reset(CreatePlatformGLContext(kGL_GrGLStandard));
             break;
         case kGLES_GLContextType:
-            glCtx.reset(SkCreatePlatformGLContext(kGLES_GrGLStandard));
+            glCtx.reset(CreatePlatformGLContext(kGLES_GrGLStandard));
             break;
 #if SK_ANGLE
 #ifdef SK_BUILD_FOR_WIN
         case kANGLE_GLContextType:
-            glCtx.reset(SkANGLEGLContext::CreateDirectX());
+            glCtx.reset(CreateANGLEDirect3DGLContext());
             break;
 #endif
         case kANGLE_GL_GLContextType:
-            glCtx.reset(SkANGLEGLContext::CreateOpenGL());
+            glCtx.reset(CreateANGLEOpenGLGLContext());
             break;
 #endif
 #if SK_COMMAND_BUFFER
         case kCommandBuffer_GLContextType:
-            glCtx.reset(SkCommandBufferGLContext::Create());
+            glCtx.reset(CommandBufferGLContext::Create());
             break;
 #endif
 #if SK_MESA
         case kMESA_GLContextType:
-            glCtx.reset(SkMesaGLContext::Create());
+            glCtx.reset(CreateMesaGLContext());
             break;
 #endif
         case kNull_GLContextType:
-            glCtx.reset(SkNullGLContext::Create());
+            glCtx.reset(CreateNullGLContext());
             break;
         case kDebug_GLContextType:
-            glCtx.reset(SkDebugGLContext::Create());
+            glCtx.reset(CreateDebugGLContext());
             break;
     }
     if (nullptr == glCtx.get()) {
@@ -129,15 +128,14 @@
     }
 
     glCtx->makeCurrent();
+    GrBackendContext p3dctx = reinterpret_cast<GrBackendContext>(glInterface.get());
 #ifdef SK_VULKAN
     if (kEnableNVPR_GLContextOptions & options) {
         return ContextInfo();
     } else {
-        GrBackendContext p3dctx = reinterpret_cast<GrBackendContext>(GrVkBackendContext::Create());
         grCtx.reset(GrContext::Create(kVulkan_GrBackend, p3dctx, fGlobalOptions));
     }
 #else
-    GrBackendContext p3dctx = reinterpret_cast<GrBackendContext>(glInterface.get());
     grCtx.reset(GrContext::Create(kOpenGL_GrBackend, p3dctx, fGlobalOptions));
 #endif
     if (!grCtx.get()) {
@@ -161,3 +159,4 @@
     context.fOptions = options;
     return ContextInfo(context.fGrContext, context.fGLContext);
 }
+}  // namespace sk_gpu_test
diff --git a/src/gpu/GrContextFactory.h b/tools/gpu/GrContextFactory.h
similarity index 90%
rename from src/gpu/GrContextFactory.h
rename to tools/gpu/GrContextFactory.h
index 1bc1e21..b174608 100644
--- a/src/gpu/GrContextFactory.h
+++ b/tools/gpu/GrContextFactory.h
@@ -11,9 +11,10 @@
 #include "GrContext.h"
 #include "GrContextOptions.h"
 
-#include "gl/SkGLContext.h"
+#include "gl/GLContext.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 +111,11 @@
     struct ContextInfo {
         ContextInfo()
             : fGrContext(nullptr), fGLContext(nullptr) { }
-        ContextInfo(GrContext* grContext, SkGLContext* glContext)
+        ContextInfo(GrContext* grContext, GLContext* glContext)
             : fGrContext(grContext), fGLContext(glContext) { }
         GrContext* fGrContext;
-        SkGLContext* fGLContext; //! Valid until the factory destroys it via abandonContexts() or
-                                 //! destroyContexts().
+        GLContext* fGLContext; //! Valid until the factory destroys it via abandonContexts() or
+                               //! destroyContexts().
     };
 
     /**
@@ -133,13 +134,13 @@
 
 private:
     struct Context {
-        GLContextType fType;
-        GLContextOptions fOptions;
-        SkGLContext*  fGLContext;
-        GrContext*    fGrContext;
+        GLContextType       fType;
+        GLContextOptions    fOptions;
+        GLContext*          fGLContext;
+        GrContext*          fGrContext;
     };
     SkTArray<Context, true> fContexts;
     const GrContextOptions  fGlobalOptions;
 };
-
+}  // namespace sk_gpu_test
 #endif
diff --git a/src/gpu/GrTest.cpp b/tools/gpu/GrTest.cpp
similarity index 100%
rename from src/gpu/GrTest.cpp
rename to tools/gpu/GrTest.cpp
diff --git a/src/gpu/GrTest.h b/tools/gpu/GrTest.h
similarity index 100%
rename from src/gpu/GrTest.h
rename to tools/gpu/GrTest.h
diff --git a/src/gpu/gl/SkGLContext.cpp b/tools/gpu/gl/GLContext.cpp
similarity index 81%
rename from src/gpu/gl/SkGLContext.cpp
rename to tools/gpu/gl/GLContext.cpp
index 1f9011f..ac0e310 100644
--- a/src/gpu/gl/SkGLContext.cpp
+++ b/tools/gpu/gl/GLContext.cpp
@@ -1,16 +1,18 @@
+
 /*
  * 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 "gl/SkGLContext.h"
-#include "GrGLUtil.h"
+#include "GLContext.h"
+#include "gl/GrGLUtil.h"
 #include "SkGpuFenceSync.h"
 
-class SkGLContext::GLFenceSync : public SkGpuFenceSync {
+namespace sk_gpu_test {
+class GLContext::GLFenceSync : public SkGpuFenceSync {
 public:
-    static GLFenceSync* CreateIfSupported(const SkGLContext*);
+    static GLFenceSync* CreateIfSupported(const GLContext*);
 
     SkPlatformGpuFence SK_WARN_UNUSED_RESULT insertFence() const override;
     bool waitFence(SkPlatformGpuFence fence, bool flush) const override;
@@ -36,12 +38,12 @@
     typedef SkGpuFenceSync INHERITED;
 };
 
-SkGLContext::SkGLContext()
+GLContext::GLContext()
     : fCurrentFenceIdx(0) {
     memset(fFrameFences, 0, sizeof(fFrameFences));
 }
 
-SkGLContext::~SkGLContext() {
+GLContext::~GLContext() {
     // Subclass should call teardown.
 #ifdef SK_DEBUG
     for (size_t i = 0; i < SK_ARRAY_COUNT(fFrameFences); i++) {
@@ -52,13 +54,13 @@
     SkASSERT(nullptr == fFenceSync.get());
 }
 
-void SkGLContext::init(const GrGLInterface* gl, SkGpuFenceSync* fenceSync) {
+void GLContext::init(const GrGLInterface* gl, SkGpuFenceSync* fenceSync) {
     SkASSERT(!fGL.get());
     fGL.reset(gl);
     fFenceSync.reset(fenceSync ? fenceSync : GLFenceSync::CreateIfSupported(this));
 }
 
-void SkGLContext::teardown() {
+void GLContext::teardown() {
     if (fFenceSync) {
         for (size_t i = 0; i < SK_ARRAY_COUNT(fFrameFences); i++) {
             if (fFrameFences[i]) {
@@ -72,15 +74,15 @@
     fGL.reset(nullptr);
 }
 
-void SkGLContext::makeCurrent() const {
+void GLContext::makeCurrent() const {
     this->onPlatformMakeCurrent();
 }
 
-void SkGLContext::swapBuffers() {
+void GLContext::swapBuffers() {
     this->onPlatformSwapBuffers();
 }
 
-void SkGLContext::waitOnSyncOrSwap() {
+void GLContext::waitOnSyncOrSwap() {
     if (!fFenceSync) {
         // Fallback on the platform SwapBuffers method for synchronization. This may have no effect.
         this->swapBuffers();
@@ -98,7 +100,7 @@
     fCurrentFenceIdx = (fCurrentFenceIdx + 1) % SK_ARRAY_COUNT(fFrameFences);
 }
 
-void SkGLContext::testAbandon() {
+void GLContext::testAbandon() {
     if (fGL) {
         fGL->abandon();
     }
@@ -107,12 +109,12 @@
     }
 }
 
-SkGLContext::GLFenceSync* SkGLContext::GLFenceSync::CreateIfSupported(const SkGLContext* ctx) {
+GLContext::GLFenceSync* GLContext::GLFenceSync::CreateIfSupported(const GLContext* ctx) {
     SkAutoTDelete<GLFenceSync> ret(new GLFenceSync);
 
     if (kGL_GrGLStandard == ctx->gl()->fStandard) {
         const GrGLubyte* versionStr;
-        SK_GL_RET(*ctx, versionStr, GetString(GR_GL_VERSION));
+        GR_GL_CALL_RET(ctx->gl(), versionStr, GetString(GR_GL_VERSION));
         GrGLVersion version = GrGLGetVersionFromString(reinterpret_cast<const char*>(versionStr));
         if (version < GR_GL_VER(3,2) && !ctx->gl()->hasExtension("GL_ARB_sync")) {
             return nullptr;
@@ -142,23 +144,23 @@
     return ret.release();
 }
 
-SkPlatformGpuFence SkGLContext::GLFenceSync::insertFence() const {
+SkPlatformGpuFence GLContext::GLFenceSync::insertFence() const {
     return fGLFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0);
 }
 
-bool SkGLContext::GLFenceSync::waitFence(SkPlatformGpuFence fence, bool flush) const {
+bool GLContext::GLFenceSync::waitFence(SkPlatformGpuFence fence, bool flush) const {
     GLsync glsync = static_cast<GLsync>(fence);
     return GL_WAIT_FAILED != fGLClientWaitSync(glsync, flush ? GL_SYNC_FLUSH_COMMANDS_BIT : 0, -1);
 }
 
-void SkGLContext::GLFenceSync::deleteFence(SkPlatformGpuFence fence) const {
+void GLContext::GLFenceSync::deleteFence(SkPlatformGpuFence fence) const {
     GLsync glsync = static_cast<GLsync>(fence);
     fGLDeleteSync(glsync);
 }
 
-GrGLint SkGLContext::createTextureRectangle(int width, int height, GrGLenum internalFormat,
-                                            GrGLenum externalFormat, GrGLenum externalType,
-                                            GrGLvoid* data) {
+GrGLint GLContext::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;
@@ -176,10 +178,11 @@
     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/include/gpu/gl/SkGLContext.h b/tools/gpu/gl/GLContext.h
similarity index 65%
rename from include/gpu/gl/SkGLContext.h
rename to tools/gpu/gl/GLContext.h
index fe41a60..3f47613 100644
--- a/include/gpu/gl/SkGLContext.h
+++ b/tools/gpu/gl/GLContext.h
@@ -5,29 +5,29 @@
  * Use of this source code is governed by a BSD-style license that can be
  * found in the LICENSE file.
  */
-#ifndef SkGLContext_DEFINED
-#define SkGLContext_DEFINED
+#ifndef GLContext_DEFINED
+#define GLContext_DEFINED
 
-#include "GrGLInterface.h"
+#include "gl/GrGLInterface.h"
 #include "../private/SkGpuFenceSync.h"
 
+
+namespace sk_gpu_test {
 /**
- * Create an offscreen opengl context with an RGBA8 / 8bit stencil FBO.
- * Provides a GrGLInterface struct of function pointers for the context.
- * This class is intended for Skia's testing needs and not for general
- * use.
+ * Create an offscreen Oppengl context. Provides a GrGLInterface struct of function pointers for
+ * the context. This class is intended for Skia's internal testing needs and not for general use.
  */
-class SK_API SkGLContext : public SkNoncopyable {
+class GLContext : public SkNoncopyable {
 public:
-    virtual ~SkGLContext();
+    virtual ~GLContext();
 
     bool isValid() const { return NULL != gl(); }
 
-    const GrGLInterface* gl() const { return fGL.get(); }
+    const GrGLInterface *gl() const { return fGL.get(); }
 
     bool fenceSyncSupport() const { return fFenceSync != nullptr; }
 
-    bool getMaxGpuFrameLag(int* maxFrameLag) const {
+    bool getMaxGpuFrameLag(int *maxFrameLag) const {
         if (!fFenceSync) {
             return false;
         }
@@ -39,12 +39,13 @@
 
     /** Used for testing EGLImage integration. Take a GL_TEXTURE_2D and wraps it in an EGL Image */
     virtual GrEGLImage texture2DToEGLImage(GrGLuint /*texID*/) const { return 0; }
-    virtual void destroyEGLImage(GrEGLImage) const {}
+
+    virtual void destroyEGLImage(GrEGLImage) const { }
 
     /** Used for testing GL_TEXTURE_RECTANGLE integration. */
     GrGLint createTextureRectangle(int width, int height, GrGLenum internalFormat,
                                    GrGLenum externalFormat, GrGLenum externalType,
-                                   GrGLvoid* data);
+                                   GrGLvoid *data);
 
     /**
      * Used for testing EGLImage integration. Takes a EGLImage and wraps it in a
@@ -81,37 +82,42 @@
      * Creates a new GL context of the same type and makes the returned context current
      * (if not null).
      */
-    virtual SkGLContext* createNew() const { return nullptr; }
+    virtual GLContext *createNew() const { return nullptr; }
 
     class GLFenceSync;  // SkGpuFenceSync implementation that uses the OpenGL functionality.
 
     /*
-     * returns the fencesync object owned by this SkGLContext
+     * returns the fencesync object owned by this GLContext
      */
-    SkGpuFenceSync* fenceSync() { return fFenceSync.get(); }
+    SkGpuFenceSync *fenceSync() { return fFenceSync.get(); }
 
 protected:
-    SkGLContext();
+    GLContext();
 
     /*
      * Methods that sublcasses must call from their constructors and destructors.
      */
-    void init(const GrGLInterface*, SkGpuFenceSync* = NULL);
+    void init(const GrGLInterface *, SkGpuFenceSync * = NULL);
+
     void teardown();
 
     /*
      * Operations that have a platform-dependent implementation.
      */
     virtual void onPlatformMakeCurrent() const = 0;
+
     virtual void onPlatformSwapBuffers() const = 0;
-    virtual GrGLFuncPtr onPlatformGetProcAddress(const char*) const = 0;
+
+    virtual GrGLFuncPtr onPlatformGetProcAddress(const char *) const = 0;
 
 private:
-    enum { kMaxFrameLag = 3 };
+    enum {
+        kMaxFrameLag = 3
+    };
 
-    SkAutoTDelete<SkGpuFenceSync> fFenceSync;
-    SkPlatformGpuFence            fFrameFences[kMaxFrameLag - 1];
-    int                           fCurrentFenceIdx;
+    SkAutoTDelete <SkGpuFenceSync> fFenceSync;
+    SkPlatformGpuFence fFrameFences[kMaxFrameLag - 1];
+    int fCurrentFenceIdx;
 
     /** Subclass provides the gl interface object if construction was
      *  successful. */
@@ -120,26 +126,16 @@
     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 SkGLContext created
+ * context with which to share display lists. This should be a pointer to an GLContext 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.
  */
-SK_API SkGLContext* SkCreatePlatformGLContext(GrGLStandard forcedGpuAPI,
-                                              SkGLContext* shareContext = nullptr);
+GLContext* CreatePlatformGLContext(GrGLStandard forcedGpuAPI, GLContext *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/tools/gpu/gl/angle/GLContext_angle.cpp b/tools/gpu/gl/angle/GLContext_angle.cpp
new file mode 100644
index 0000000..f1e8aad
--- /dev/null
+++ b/tools/gpu/gl/angle/GLContext_angle.cpp
@@ -0,0 +1,320 @@
+
+/*
+ * 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 "GLContext_angle.h"
+
+#include <EGL/egl.h>
+#include <EGL/eglext.h>
+
+#include "gl/GrGLDefines.h"
+#include "gl/GrGLUtil.h"
+
+#include "gl/GrGLInterface.h"
+#include "gl/GrGLAssembleInterface.h"
+#include "../ports/SkOSLibrary.h"
+
+#include <EGL/egl.h>
+
+#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<const Libs*>(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) {
+    PFNEGLGETPLATFORMDISPLAYEXTPROC eglGetPlatformDisplayEXT;
+    eglGetPlatformDisplayEXT =
+        (PFNEGLGETPLATFORMDISPLAYEXTPROC)eglGetProcAddress("eglGetPlatformDisplayEXT");
+
+    // We expect ANGLE to support this extension
+    if (!eglGetPlatformDisplayEXT) {
+        return EGL_NO_DISPLAY;
+    }
+
+    EGLDisplay display = EGL_NO_DISPLAY;
+    if (useGLBackend) {
+        EGLint attribs[3] = {
+            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.
+        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;
+}
+
+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)
+    : fContext(EGL_NO_CONTEXT)
+    , fDisplay(EGL_NO_DISPLAY)
+    , fSurface(EGL_NO_SURFACE) {
+
+    EGLint numConfigs;
+    static const EGLint configAttribs[] = {
+        EGL_SURFACE_TYPE, EGL_PBUFFER_BIT,
+        EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
+        EGL_RED_SIZE, 8,
+        EGL_GREEN_SIZE, 8,
+        EGL_BLUE_SIZE, 8,
+        EGL_ALPHA_SIZE, 8,
+        EGL_NONE
+    };
+
+    fIsGLBackend = useGLBackend;
+    fDisplay = get_angle_egl_display(EGL_DEFAULT_DISPLAY, useGLBackend);
+    if (EGL_NO_DISPLAY == fDisplay) {
+        SkDebugf("Could not create EGL display!");
+        return;
+    }
+
+    EGLint majorVersion;
+    EGLint minorVersion;
+    eglInitialize(fDisplay, &majorVersion, &minorVersion);
+
+    EGLConfig surfaceConfig;
+    eglChooseConfig(fDisplay, configAttribs, &surfaceConfig, 1, &numConfigs);
+
+    static const EGLint contextAttribs[] = {
+        EGL_CONTEXT_CLIENT_VERSION, 2,
+        EGL_NONE
+    };
+    fContext = eglCreateContext(fDisplay, surfaceConfig, nullptr, contextAttribs);
+
+
+    static const EGLint surfaceAttribs[] = {
+        EGL_WIDTH, 1,
+        EGL_HEIGHT, 1,
+        EGL_NONE
+    };
+
+    fSurface = eglCreatePbufferSurface(fDisplay, surfaceConfig, surfaceAttribs);
+
+    eglMakeCurrent(fDisplay, fSurface, fSurface, fContext);
+
+    SkAutoTUnref<const GrGLInterface> gl(sk_gpu_test::CreateANGLEGLInterface());
+    if (nullptr == gl.get()) {
+        SkDebugf("Could not create ANGLE GL interface!\n");
+        this->destroyGLContext();
+        return;
+    }
+    if (!gl->validate()) {
+        SkDebugf("Could not validate ANGLE GL interface!\n");
+        this->destroyGLContext();
+        return;
+    }
+
+    this->init(gl.release());
+}
+
+ANGLEGLContext::~ANGLEGLContext() {
+    this->teardown();
+    this->destroyGLContext();
+}
+
+GrEGLImage ANGLEGLContext::texture2DToEGLImage(GrGLuint texID) const {
+    if (!this->gl()->hasExtension("EGL_KHR_gl_texture_2D_image")) {
+        return GR_EGL_NO_IMAGE;
+    }
+    GrEGLImage img;
+    GrEGLint attribs[] = { GR_EGL_GL_TEXTURE_LEVEL, 0,
+                           GR_EGL_IMAGE_PRESERVED, GR_EGL_TRUE,
+                           GR_EGL_NONE };
+    // 64 bit cast is to shut Visual C++ up about casting 32 bit value to a pointer.
+    GrEGLClientBuffer clientBuffer = reinterpret_cast<GrEGLClientBuffer>((uint64_t)texID);
+    GR_GL_CALL_RET(this->gl(), img,
+                   EGLCreateImage(fDisplay, fContext, GR_EGL_GL_TEXTURE_2D, clientBuffer,
+                                  attribs));
+    return img;
+}
+
+void ANGLEGLContext::destroyEGLImage(GrEGLImage image) const {
+    GR_GL_CALL(this->gl(), EGLDestroyImage(fDisplay, image));
+}
+
+GrGLuint ANGLEGLContext::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) {
+        return 0;
+    }
+    GrGLuint texID;
+    GR_GL_CALL(this->gl(), GenTextures(1, &texID));
+    if (!texID) {
+        return 0;
+    }
+    GR_GL_CALL(this->gl(), BindTexture(GR_GL_TEXTURE_EXTERNAL, texID));
+    if (GR_GL_GET_ERROR(this->gl()) != GR_GL_NO_ERROR) {
+        GR_GL_CALL(this->gl(), DeleteTextures(1, &texID));
+        return 0;
+    }
+    glEGLImageTargetTexture2D(GR_GL_TEXTURE_EXTERNAL, image);
+    if (GR_GL_GET_ERROR(this->gl()) != GR_GL_NO_ERROR) {
+        GR_GL_CALL(this->gl(), DeleteTextures(1, &texID));
+        return 0;
+    }
+    return texID;
+}
+
+sk_gpu_test::GLContext* ANGLEGLContext::createNew() const {
+#ifdef SK_BUILD_FOR_WIN
+    sk_gpu_test::GLContext* ctx = fIsGLBackend ? sk_gpu_test::CreateANGLEOpenGLGLContext()
+                                               : sk_gpu_test::CreateANGLEDirect3DGLContext();
+#else
+    sk_gpu_test::GLContext* ctx = sk_gpu_test::CreateANGLEOpenGLGLContext();
+#endif
+    if (ctx) {
+        ctx->makeCurrent();
+    }
+    return ctx;
+}
+
+void ANGLEGLContext::destroyGLContext() {
+    if (fDisplay) {
+        eglMakeCurrent(fDisplay, 0, 0, 0);
+
+        if (fContext) {
+            eglDestroyContext(fDisplay, fContext);
+            fContext = EGL_NO_CONTEXT;
+        }
+
+        if (fSurface) {
+            eglDestroySurface(fDisplay, fSurface);
+            fSurface = EGL_NO_SURFACE;
+        }
+
+        //TODO should we close the display?
+        fDisplay = EGL_NO_DISPLAY;
+    }
+}
+
+void ANGLEGLContext::onPlatformMakeCurrent() const {
+    if (!eglMakeCurrent(fDisplay, fSurface, fSurface, fContext)) {
+        SkDebugf("Could not set the context.\n");
+    }
+}
+
+void ANGLEGLContext::onPlatformSwapBuffers() const {
+    if (!eglSwapBuffers(fDisplay, fSurface)) {
+        SkDebugf("Could not complete eglSwapBuffers.\n");
+    }
+}
+
+GrGLFuncPtr ANGLEGLContext::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() {
+        ANGLEGLContext* ctx = new ANGLEGLContext(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/angle/GLContext_angle.h b/tools/gpu/gl/angle/GLContext_angle.h
new file mode 100644
index 0000000..519ea6b
--- /dev/null
+++ b/tools/gpu/gl/angle/GLContext_angle.h
@@ -0,0 +1,30 @@
+
+/*
+ * 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/src/gpu/gl/command_buffer/SkCommandBufferGLContext.cpp b/tools/gpu/gl/command_buffer/GLContext_command_buffer.cpp
similarity index 86%
rename from src/gpu/gl/command_buffer/SkCommandBufferGLContext.cpp
rename to tools/gpu/gl/command_buffer/GLContext_command_buffer.cpp
index 516c155..b878cb4 100644
--- a/src/gpu/gl/command_buffer/SkCommandBufferGLContext.cpp
+++ b/tools/gpu/gl/command_buffer/GLContext_command_buffer.cpp
@@ -1,13 +1,15 @@
+
 /*
  * 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/SkCommandBufferGLContext.h"
+#include "gl/command_buffer/GLContext_command_buffer.h"
 #include "../ports/SkOSEnvironment.h"
 #include "../ports/SkOSLibrary.h"
 
@@ -82,6 +84,7 @@
 static void* gLibrary = nullptr;
 static bool gfFunctionsLoadedSuccessfully = false;
 
+namespace {
 static void load_command_buffer_functions() {
     if (!gLibrary) {
 #if defined _WIN32
@@ -124,22 +127,24 @@
 }
 
 SK_DECLARE_STATIC_ONCE(loadCommandBufferOnce);
-void LoadCommandBufferOnce() {
+static void load_command_buffer_once() {
     SkOnce(&loadCommandBufferOnce, load_command_buffer_functions);
 }
 
-const GrGLInterface* GrGLCreateCommandBufferInterface() {
-    LoadCommandBufferOnce();
+static const GrGLInterface* create_command_buffer_interface() {
+    load_command_buffer_once();
     if (!gfFunctionsLoadedSuccessfully) {
         return nullptr;
     }
     return GrGLAssembleGLESInterface(gLibrary, command_buffer_get_gl_proc);
 }
 
-SkCommandBufferGLContext::SkCommandBufferGLContext()
-    : fContext(EGL_NO_CONTEXT)
-    , fDisplay(EGL_NO_DISPLAY)
-    , fSurface(EGL_NO_SURFACE) {
+}  // anonymous namespace
+
+namespace sk_gpu_test {
+
+CommandBufferGLContext::CommandBufferGLContext()
+    : fContext(EGL_NO_CONTEXT), fDisplay(EGL_NO_DISPLAY), fSurface(EGL_NO_SURFACE) {
 
     static const EGLint configAttribs[] = {
         EGL_SURFACE_TYPE, EGL_PBUFFER_BIT,
@@ -160,18 +165,18 @@
     initializeGLContext(nullptr, configAttribs, surfaceAttribs);
 }
 
-SkCommandBufferGLContext::SkCommandBufferGLContext(void* nativeWindow, int msaaSampleCount) {
-    static const EGLint surfaceAttribs[] = { EGL_NONE };
+CommandBufferGLContext::CommandBufferGLContext(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) {
@@ -181,9 +186,9 @@
     initializeGLContext(nativeWindow, configAttribs, surfaceAttribs);
 }
 
-void SkCommandBufferGLContext::initializeGLContext(void* nativeWindow, const int* configAttribs,
-                                                   const int* surfaceAttribs) {
-    LoadCommandBufferOnce();
+void CommandBufferGLContext::initializeGLContext(void *nativeWindow, const int *configAttribs,
+                                                 const int *surfaceAttribs) {
+    load_command_buffer_once();
     if (!gfFunctionsLoadedSuccessfully) {
         SkDebugf("Command Buffer: Could not load EGL functions.\n");
         return;
@@ -206,7 +211,7 @@
     }
 
     EGLint numConfigs;
-    if (!gfChooseConfig(fDisplay, configAttribs, static_cast<EGLConfig*>(&fConfig), 1,
+    if (!gfChooseConfig(fDisplay, configAttribs, static_cast<EGLConfig *>(&fConfig), 1,
                         &numConfigs) || numConfigs != 1) {
         SkDebugf("Command Buffer: Could not choose EGL config.\n");
         this->destroyGLContext();
@@ -216,7 +221,7 @@
     if (nativeWindow) {
         fSurface = gfCreateWindowSurface(fDisplay,
                                          static_cast<EGLConfig>(fConfig),
-                                         (EGLNativeWindowType)nativeWindow,
+                                         (EGLNativeWindowType) nativeWindow,
                                          surfaceAttribs);
     } else {
         fSurface = gfCreatePbufferSurface(fDisplay,
@@ -246,7 +251,7 @@
         return;
     }
 
-    SkAutoTUnref<const GrGLInterface> gl(GrGLCreateCommandBufferInterface());
+    SkAutoTUnref<const GrGLInterface> gl(create_command_buffer_interface());
     if (nullptr == gl.get()) {
         SkDebugf("Command Buffer: Could not create CommandBuffer GL interface.\n");
         this->destroyGLContext();
@@ -261,12 +266,12 @@
     this->init(gl.release());
 }
 
-SkCommandBufferGLContext::~SkCommandBufferGLContext() {
+CommandBufferGLContext::~CommandBufferGLContext() {
     this->teardown();
     this->destroyGLContext();
 }
 
-void SkCommandBufferGLContext::destroyGLContext() {
+void CommandBufferGLContext::destroyGLContext() {
     if (!gfFunctionsLoadedSuccessfully) {
         return;
     }
@@ -288,7 +293,7 @@
     }
 }
 
-void SkCommandBufferGLContext::onPlatformMakeCurrent() const {
+void CommandBufferGLContext::onPlatformMakeCurrent() const {
     if (!gfFunctionsLoadedSuccessfully) {
         return;
     }
@@ -297,7 +302,7 @@
     }
 }
 
-void SkCommandBufferGLContext::onPlatformSwapBuffers() const {
+void CommandBufferGLContext::onPlatformSwapBuffers() const {
     if (!gfFunctionsLoadedSuccessfully) {
         return;
     }
@@ -306,14 +311,14 @@
     }
 }
 
-GrGLFuncPtr SkCommandBufferGLContext::onPlatformGetProcAddress(const char* name) const {
+GrGLFuncPtr CommandBufferGLContext::onPlatformGetProcAddress(const char *name) const {
     if (!gfFunctionsLoadedSuccessfully) {
         return nullptr;
     }
     return gfGetProcAddress(name);
 }
 
-void SkCommandBufferGLContext::presentCommandBuffer() {
+void CommandBufferGLContext::presentCommandBuffer() {
     if (this->gl()) {
         this->gl()->fFunctions.fFlush();
     }
@@ -321,18 +326,20 @@
     this->onPlatformSwapBuffers();
 }
 
-bool SkCommandBufferGLContext::makeCurrent() {
+bool CommandBufferGLContext::makeCurrent() {
     return gfMakeCurrent(fDisplay, fSurface, fSurface, fContext) != EGL_FALSE;
 }
 
-int SkCommandBufferGLContext::getStencilBits() {
+int CommandBufferGLContext::getStencilBits() {
     EGLint result = 0;
     gfGetConfigAttrib(fDisplay, static_cast<EGLConfig>(fConfig), EGL_STENCIL_SIZE, &result);
     return result;
 }
 
-int SkCommandBufferGLContext::getSampleCount() {
+int CommandBufferGLContext::getSampleCount() {
     EGLint result = 0;
     gfGetConfigAttrib(fDisplay, static_cast<EGLConfig>(fConfig), EGL_SAMPLES, &result);
     return result;
 }
+
+}  // namespace sk_gpu_test
diff --git a/tools/gpu/gl/command_buffer/GLContext_command_buffer.h b/tools/gpu/gl/command_buffer/GLContext_command_buffer.h
new file mode 100644
index 0000000..73f02e2
--- /dev/null
+++ b/tools/gpu/gl/command_buffer/GLContext_command_buffer.h
@@ -0,0 +1,68 @@
+
+/*
+ * 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/src/gpu/gl/debug/GrGLCreateDebugInterface.cpp b/tools/gpu/gl/debug/DebugGLContext.cpp
similarity index 75%
rename from src/gpu/gl/debug/GrGLCreateDebugInterface.cpp
rename to tools/gpu/gl/debug/DebugGLContext.cpp
index 02b5cf7..f4cbbea 100644
--- a/src/gpu/gl/debug/GrGLCreateDebugInterface.cpp
+++ b/tools/gpu/gl/debug/DebugGLContext.cpp
@@ -1,3 +1,4 @@
+
 /*
  * Copyright 2012 Google Inc.
  *
@@ -5,8 +6,7 @@
  * found in the LICENSE file.
  */
 
-
-#include "gl/GrGLInterface.h"
+#include "DebugGLContext.h"
 
 #include "GrBufferObj.h"
 #include "GrFrameBufferObj.h"
@@ -217,254 +217,254 @@
         }
     }
 
-     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,
-                                              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,
+        // a frameBufferID of 0 is acceptable - it binds to the default
+        // frame buffer
+        GrFrameBufferObj *frameBuffer = FIND(frameBufferID, GrFrameBufferObj,
                                              kFrameBuffer_ObjTypes);
-             GrAlwaysAssert(buffer);
 
-             GrAlwaysAssert(!buffer->getDeleted());
-             buffer->deleteAction();
-         }
-     }
+        this->setFrameBuffer(frameBuffer);
+    }
 
-     GrGLvoid deleteRenderbuffers(GrGLsizei n,const GrGLuint *renderBuffers) override {
+    GrGLvoid bindRenderbuffer(GrGLenum target, GrGLuint renderBufferID) override {
 
-         // first potentially unbind the buffers
-         if (this->getRenderBuffer()) {
-             for (int i = 0; i < n; ++i) {
+        GrAlwaysAssert(GR_GL_RENDERBUFFER == target);
 
-                 if (renderBuffers[i] ==
-                     this->getRenderBuffer()->getID()) {
-                     // this ID is the current render buffer - make no
-                     // render buffer be bound
-                     this->setRenderBuffer(nullptr);
-                 }
-             }
-         }
+        // a renderBufferID of 0 is acceptable - it unbinds the bound render buffer
+        GrRenderBufferObj *renderBuffer = FIND(renderBufferID, GrRenderBufferObj,
+                                               kRenderBuffer_ObjTypes);
 
-         // 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()) {
+        this->setRenderBuffer(renderBuffer);
+    }
 
-             GrFrameBufferObj *frameBuffer = 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);
 
-             for (int i = 0; i < n; ++i) {
+            if (pTU->getTexture()) {
+                for (int j = 0; j < n; ++j) {
 
-                 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);
-                 }
-             }
-         }
+                    if (textures[j] == pTU->getTexture()->getID()) {
+                        // this ID is the current texture - revert the binding to 0
+                        pTU->setTexture(nullptr);
+                    }
+                }
+            }
+        }
 
-         // then actually "delete" the buffers
-         for (int i = 0; i < n; ++i) {
-             GrRenderBufferObj *buffer = FIND(renderBuffers[i], GrRenderBufferObj,
-                                              kRenderBuffer_ObjTypes);
-             GrAlwaysAssert(buffer);
+        // 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()) {
 
-             // 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());
+            GrFrameBufferObj *frameBuffer = this->getFrameBuffer();
 
-             GrAlwaysAssert(!buffer->getDeleted());
-             buffer->deleteAction();
-         }
-     }
+            for (int i = 0; i < n; ++i) {
 
-     GrGLvoid framebufferRenderbuffer(GrGLenum target,
-                                      GrGLenum attachment,
-                                      GrGLenum renderbuffertarget,
-                                      GrGLuint renderBufferID) override {
+                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);
+                }
+            }
+        }
 
-         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);
+        // then actually "delete" the buffers
+        for (int i = 0; i < n; ++i) {
+            GrTextureObj *buffer = FIND(textures[i], GrTextureObj, kTexture_ObjTypes);
+            GrAlwaysAssert(buffer);
 
-         GrFrameBufferObj *framebuffer = this->getFrameBuffer();
-         // A render buffer cannot be attached to the default framebuffer
-         GrAlwaysAssert(framebuffer);
+            // OpenGL gives no guarantees if a texture is deleted while attached to
+            // something other than the currently bound frame buffer
+            GrAlwaysAssert(!buffer->getBound());
 
-         // a renderBufferID of 0 is acceptable - it unbinds the current
-         // render buffer
-         GrRenderBufferObj *renderbuffer = FIND(renderBufferID, GrRenderBufferObj,
-                                                kRenderBuffer_ObjTypes);
+            GrAlwaysAssert(!buffer->getDeleted());
+            buffer->deleteAction();
+        }
 
-         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 {
 
-     ////////////////////////////////////////////////////////////////////////////////
-     GrGLvoid framebufferTexture2D(GrGLenum target, GrGLenum attachment, GrGLenum textarget,
-                                   GrGLuint textureID, GrGLint level) override {
+        // first potentially unbind the buffers
+        if (this->getFrameBuffer()) {
+            for (int i = 0; i < n; ++i) {
 
-         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);
+                if (frameBuffers[i] ==
+                    this->getFrameBuffer()->getID()) {
+                    // this ID is the current frame buffer - rebind to the default
+                    this->setFrameBuffer(nullptr);
+                }
+            }
+        }
 
-         GrFrameBufferObj *framebuffer = this->getFrameBuffer();
-         // A texture cannot be attached to the default framebuffer
-         GrAlwaysAssert(framebuffer);
+        // then actually "delete" the buffers
+        for (int i = 0; i < n; ++i) {
+            GrFrameBufferObj *buffer = FIND(frameBuffers[i], GrFrameBufferObj,
+                                            kFrameBuffer_ObjTypes);
+            GrAlwaysAssert(buffer);
 
-         // 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(!buffer->getDeleted());
+            buffer->deleteAction();
+        }
+    }
 
-         GrAlwaysAssert(0 == level);
+    GrGLvoid deleteRenderbuffers(GrGLsizei n,const GrGLuint *renderBuffers) override {
 
-         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;
-         };
-     }
+        // 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;
+        };
+    }
 
     GrGLuint createProgram() override {
 
@@ -1229,8 +1229,28 @@
     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
 
-////////////////////////////////////////////////////////////////////////////////
-
-const GrGLInterface* GrGLCreateDebugInterface() { return new DebugInterface; }
+namespace sk_gpu_test {
+GLContext* CreateDebugGLContext() {
+    GLContext* ctx = new DebugGLContext();
+    if (ctx->isValid()) {
+        return ctx;
+    }
+    delete ctx;
+    return nullptr;
+}
+}
diff --git a/tools/gpu/gl/debug/DebugGLContext.h b/tools/gpu/gl/debug/DebugGLContext.h
new file mode 100644
index 0000000..0ac505b
--- /dev/null
+++ b/tools/gpu/gl/debug/DebugGLContext.h
@@ -0,0 +1,17 @@
+
+/*
+ * 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/src/gpu/gl/debug/GrBufferObj.cpp b/tools/gpu/gl/debug/GrBufferObj.cpp
similarity index 99%
rename from src/gpu/gl/debug/GrBufferObj.cpp
rename to tools/gpu/gl/debug/GrBufferObj.cpp
index ee0993d..37d4438 100644
--- a/src/gpu/gl/debug/GrBufferObj.cpp
+++ b/tools/gpu/gl/debug/GrBufferObj.cpp
@@ -1,3 +1,4 @@
+
 /*
  * Copyright 2012 Google Inc.
  *
diff --git a/src/gpu/gl/debug/GrBufferObj.h b/tools/gpu/gl/debug/GrBufferObj.h
similarity index 98%
rename from src/gpu/gl/debug/GrBufferObj.h
rename to tools/gpu/gl/debug/GrBufferObj.h
index 5b5015b..96aef6e 100644
--- a/src/gpu/gl/debug/GrBufferObj.h
+++ b/tools/gpu/gl/debug/GrBufferObj.h
@@ -1,3 +1,4 @@
+
 /*
  * Copyright 2012 Google Inc.
  *
@@ -9,7 +10,7 @@
 #define GrBufferObj_DEFINED
 
 #include "GrFakeRefObj.h"
-#include "../GrGLDefines.h"
+#include "gl/GrGLDefines.h"
 
 ////////////////////////////////////////////////////////////////////////////////
 class GrBufferObj : public GrFakeRefObj {
diff --git a/src/gpu/gl/debug/GrFBBindableObj.h b/tools/gpu/gl/debug/GrFBBindableObj.h
similarity index 99%
rename from src/gpu/gl/debug/GrFBBindableObj.h
rename to tools/gpu/gl/debug/GrFBBindableObj.h
index 2d490ef..e2b43a6 100644
--- a/src/gpu/gl/debug/GrFBBindableObj.h
+++ b/tools/gpu/gl/debug/GrFBBindableObj.h
@@ -1,3 +1,4 @@
+
 /*
  * Copyright 2012 Google Inc.
  *
diff --git a/src/gpu/gl/debug/GrFakeRefObj.h b/tools/gpu/gl/debug/GrFakeRefObj.h
similarity index 100%
rename from src/gpu/gl/debug/GrFakeRefObj.h
rename to tools/gpu/gl/debug/GrFakeRefObj.h
diff --git a/src/gpu/gl/debug/GrFrameBufferObj.cpp b/tools/gpu/gl/debug/GrFrameBufferObj.cpp
similarity index 99%
rename from src/gpu/gl/debug/GrFrameBufferObj.cpp
rename to tools/gpu/gl/debug/GrFrameBufferObj.cpp
index a8acc3d..7dc12ac 100644
--- a/src/gpu/gl/debug/GrFrameBufferObj.cpp
+++ b/tools/gpu/gl/debug/GrFrameBufferObj.cpp
@@ -1,3 +1,4 @@
+
 /*
  * Copyright 2012 Google Inc.
  *
diff --git a/src/gpu/gl/debug/GrFrameBufferObj.h b/tools/gpu/gl/debug/GrFrameBufferObj.h
similarity index 99%
rename from src/gpu/gl/debug/GrFrameBufferObj.h
rename to tools/gpu/gl/debug/GrFrameBufferObj.h
index 40e123e..42a0eff 100644
--- a/src/gpu/gl/debug/GrFrameBufferObj.h
+++ b/tools/gpu/gl/debug/GrFrameBufferObj.h
@@ -1,3 +1,4 @@
+
 /*
  * Copyright 2012 Google Inc.
  *
diff --git a/src/gpu/gl/debug/GrProgramObj.cpp b/tools/gpu/gl/debug/GrProgramObj.cpp
similarity index 99%
rename from src/gpu/gl/debug/GrProgramObj.cpp
rename to tools/gpu/gl/debug/GrProgramObj.cpp
index d45bd1c..d6cc36b 100644
--- a/src/gpu/gl/debug/GrProgramObj.cpp
+++ b/tools/gpu/gl/debug/GrProgramObj.cpp
@@ -1,3 +1,4 @@
+
 /*
  * Copyright 2012 Google Inc.
  *
diff --git a/src/gpu/gl/debug/GrProgramObj.h b/tools/gpu/gl/debug/GrProgramObj.h
similarity index 99%
rename from src/gpu/gl/debug/GrProgramObj.h
rename to tools/gpu/gl/debug/GrProgramObj.h
index 6e5ec65..a25341a 100644
--- a/src/gpu/gl/debug/GrProgramObj.h
+++ b/tools/gpu/gl/debug/GrProgramObj.h
@@ -1,3 +1,4 @@
+
 /*
  * Copyright 2012 Google Inc.
  *
diff --git a/src/gpu/gl/debug/GrRenderBufferObj.h b/tools/gpu/gl/debug/GrRenderBufferObj.h
similarity index 99%
rename from src/gpu/gl/debug/GrRenderBufferObj.h
rename to tools/gpu/gl/debug/GrRenderBufferObj.h
index dae08f5..8231ef5 100644
--- a/src/gpu/gl/debug/GrRenderBufferObj.h
+++ b/tools/gpu/gl/debug/GrRenderBufferObj.h
@@ -1,3 +1,4 @@
+
 /*
  * Copyright 2012 Google Inc.
  *
diff --git a/src/gpu/gl/debug/GrShaderObj.cpp b/tools/gpu/gl/debug/GrShaderObj.cpp
similarity index 99%
rename from src/gpu/gl/debug/GrShaderObj.cpp
rename to tools/gpu/gl/debug/GrShaderObj.cpp
index 67cca3e..8d3caa1 100644
--- a/src/gpu/gl/debug/GrShaderObj.cpp
+++ b/tools/gpu/gl/debug/GrShaderObj.cpp
@@ -1,3 +1,4 @@
+
 /*
  * Copyright 2012 Google Inc.
  *
diff --git a/src/gpu/gl/debug/GrShaderObj.h b/tools/gpu/gl/debug/GrShaderObj.h
similarity index 96%
rename from src/gpu/gl/debug/GrShaderObj.h
rename to tools/gpu/gl/debug/GrShaderObj.h
index 871494a..327bd7f 100644
--- a/src/gpu/gl/debug/GrShaderObj.h
+++ b/tools/gpu/gl/debug/GrShaderObj.h
@@ -1,3 +1,4 @@
+
 /*
  * Copyright 2012 Google Inc.
  *
@@ -9,7 +10,7 @@
 #define GrShaderObj_DEFINED
 
 #include "GrFakeRefObj.h"
-#include "../GrGLDefines.h"
+#include "gl/GrGLDefines.h"
 
 ////////////////////////////////////////////////////////////////////////////////
 class GrShaderObj : public GrFakeRefObj {
diff --git a/src/gpu/gl/debug/GrTextureObj.cpp b/tools/gpu/gl/debug/GrTextureObj.cpp
similarity index 99%
rename from src/gpu/gl/debug/GrTextureObj.cpp
rename to tools/gpu/gl/debug/GrTextureObj.cpp
index 62cb399..86063fb 100644
--- a/src/gpu/gl/debug/GrTextureObj.cpp
+++ b/tools/gpu/gl/debug/GrTextureObj.cpp
@@ -1,3 +1,4 @@
+
 /*
  * Copyright 2012 Google Inc.
  *
diff --git a/src/gpu/gl/debug/GrTextureObj.h b/tools/gpu/gl/debug/GrTextureObj.h
similarity index 99%
rename from src/gpu/gl/debug/GrTextureObj.h
rename to tools/gpu/gl/debug/GrTextureObj.h
index bc649f3..fcf851d 100644
--- a/src/gpu/gl/debug/GrTextureObj.h
+++ b/tools/gpu/gl/debug/GrTextureObj.h
@@ -1,3 +1,4 @@
+
 /*
  * Copyright 2012 Google Inc.
  *
diff --git a/src/gpu/gl/debug/GrTextureUnitObj.cpp b/tools/gpu/gl/debug/GrTextureUnitObj.cpp
similarity index 99%
rename from src/gpu/gl/debug/GrTextureUnitObj.cpp
rename to tools/gpu/gl/debug/GrTextureUnitObj.cpp
index 8de0b09..316dcec 100644
--- a/src/gpu/gl/debug/GrTextureUnitObj.cpp
+++ b/tools/gpu/gl/debug/GrTextureUnitObj.cpp
@@ -1,3 +1,4 @@
+
 /*
  * Copyright 2012 Google Inc.
  *
diff --git a/src/gpu/gl/debug/GrTextureUnitObj.h b/tools/gpu/gl/debug/GrTextureUnitObj.h
similarity index 100%
rename from src/gpu/gl/debug/GrTextureUnitObj.h
rename to tools/gpu/gl/debug/GrTextureUnitObj.h
diff --git a/src/gpu/gl/debug/GrVertexArrayObj.h b/tools/gpu/gl/debug/GrVertexArrayObj.h
similarity index 100%
rename from src/gpu/gl/debug/GrVertexArrayObj.h
rename to tools/gpu/gl/debug/GrVertexArrayObj.h
diff --git a/src/gpu/gl/egl/SkCreatePlatformGLContext_egl.cpp b/tools/gpu/gl/egl/CreatePlatformGLContext_egl.cpp
similarity index 94%
rename from src/gpu/gl/egl/SkCreatePlatformGLContext_egl.cpp
rename to tools/gpu/gl/egl/CreatePlatformGLContext_egl.cpp
index 1644254..ac2e7ca 100644
--- a/src/gpu/gl/egl/SkCreatePlatformGLContext_egl.cpp
+++ b/tools/gpu/gl/egl/CreatePlatformGLContext_egl.cpp
@@ -1,10 +1,11 @@
+
 /*
  * 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/SkGLContext.h"
+#include "gl/GLContext.h"
 
 #include <GLES2/gl2.h>
 
@@ -34,7 +35,7 @@
     typedef SkGpuFenceSync INHERITED;
 };
 
-class EGLGLContext : public SkGLContext  {
+class EGLGLContext : public sk_gpu_test::GLContext {
 public:
     EGLGLContext(GrGLStandard forcedGpuAPI);
     ~EGLGLContext() override;
@@ -42,7 +43,7 @@
     GrEGLImage texture2DToEGLImage(GrGLuint texID) const override;
     void destroyEGLImage(GrEGLImage) const override;
     GrGLuint eglImageToExternalTexture(GrEGLImage) const override;
-    SkGLContext* createNew() const override;
+    sk_gpu_test::GLContext* createNew() const override;
 
 private:
     void destroyGLContext();
@@ -253,8 +254,8 @@
     return texID;
 }
 
-SkGLContext* EGLGLContext::createNew() const {
-    SkGLContext* ctx = SkCreatePlatformGLContext(this->gl()->fStandard);
+sk_gpu_test::GLContext* EGLGLContext::createNew() const {
+    sk_gpu_test::GLContext* ctx = new EGLGLContext(this->gl()->fStandard);
     if (ctx) {
         ctx->makeCurrent();
     }
@@ -317,17 +318,20 @@
     eglDestroySyncKHR(fDisplay, eglsync);
 }
 
-} // anonymous namespace
+}  // anonymous namespace
 
-SkGLContext* SkCreatePlatformGLContext(GrGLStandard forcedGpuAPI, SkGLContext* shareContext) {
+namespace sk_gpu_test {
+GLContext *CreatePlatformGLContext(GrGLStandard forcedGpuAPI, GLContext *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/src/gpu/gl/glx/SkCreatePlatformGLContext_glx.cpp b/tools/gpu/gl/glx/CreatePlatformGLContext_glx.cpp
similarity index 96%
rename from src/gpu/gl/glx/SkCreatePlatformGLContext_glx.cpp
rename to tools/gpu/gl/glx/CreatePlatformGLContext_glx.cpp
index d0bd1de..b2168e3 100644
--- a/src/gpu/gl/glx/SkCreatePlatformGLContext_glx.cpp
+++ b/tools/gpu/gl/glx/CreatePlatformGLContext_glx.cpp
@@ -1,10 +1,11 @@
+
 /*
  * 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/SkGLContext.h"
+#include "gl/GLContext.h"
 
 #include <X11/Xlib.h>
 #include <GL/glx.h>
@@ -43,7 +44,7 @@
     return 0;
 }
 
-class GLXGLContext : public SkGLContext {
+class GLXGLContext : public sk_gpu_test::GLContext {
 public:
     GLXGLContext(GrGLStandard forcedGpuAPI, GLXGLContext* shareList);
     ~GLXGLContext() override;
@@ -330,10 +331,11 @@
     return glXGetProcAddress(reinterpret_cast<const GLubyte*>(procName));
 }
 
-} // anonymous namespace
+}  // anonymous namespace
 
-SkGLContext* SkCreatePlatformGLContext(GrGLStandard forcedGpuAPI, SkGLContext* shareContext) {
-    GLXGLContext* glxShareContext = reinterpret_cast<GLXGLContext*>(shareContext);
+namespace sk_gpu_test {
+GLContext *CreatePlatformGLContext(GrGLStandard forcedGpuAPI, GLContext *shareContext) {
+    GLXGLContext *glxShareContext = reinterpret_cast<GLXGLContext *>(shareContext);
     GLXGLContext *ctx = new GLXGLContext(forcedGpuAPI, glxShareContext);
     if (!ctx->isValid()) {
         delete ctx;
@@ -341,3 +343,4 @@
     }
     return ctx;
 }
+}  // namespace sk_gpu_test
diff --git a/src/gpu/gl/iOS/SkCreatePlatformGLContext_iOS.mm b/tools/gpu/gl/iOS/CreatePlatformGLContext_iOS.mm
similarity index 89%
rename from src/gpu/gl/iOS/SkCreatePlatformGLContext_iOS.mm
rename to tools/gpu/gl/iOS/CreatePlatformGLContext_iOS.mm
index 54dc59a..d6507f2 100644
--- a/src/gpu/gl/iOS/SkCreatePlatformGLContext_iOS.mm
+++ b/tools/gpu/gl/iOS/CreatePlatformGLContext_iOS.mm
@@ -6,7 +6,7 @@
  * found in the LICENSE file.
  */
 
-#include "gl/SkGLContext.h"
+#include "GLContext.h"
 #import <OpenGLES/EAGL.h>
 #include <dlfcn.h>
 
@@ -14,7 +14,7 @@
 
 namespace {
 
-class IOSGLContext : public SkGLContext {
+class IOSGLContext : public sk_gpu_test::GLContext {
 public:
     IOSGLContext();
     ~IOSGLContext() override;
@@ -87,9 +87,10 @@
     return reinterpret_cast<GrGLFuncPtr>(dlsym(fGLLibrary, procName));
 }
 
-} // anonymous namespace
+}  // anonymous namespace
 
-SkGLContext* SkCreatePlatformGLContext(GrGLStandard forcedGpuAPI, SkGLContext* shareContext) {
+namespace sk_gpu_test {
+GLContext *CreatePlatformGLContext(GrGLStandard forcedGpuAPI, GLContext *shareContext) {
     SkASSERT(!shareContext);
     if (shareContext) {
         return NULL;
@@ -97,10 +98,11 @@
     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/src/gpu/gl/mac/SkCreatePlatformGLContext_mac.cpp b/tools/gpu/gl/mac/CreatePlatformGLContext_mac.cpp
similarity index 91%
rename from src/gpu/gl/mac/SkCreatePlatformGLContext_mac.cpp
rename to tools/gpu/gl/mac/CreatePlatformGLContext_mac.cpp
index 0ca62ad..7da99d7 100644
--- a/src/gpu/gl/mac/SkCreatePlatformGLContext_mac.cpp
+++ b/tools/gpu/gl/mac/CreatePlatformGLContext_mac.cpp
@@ -1,3 +1,4 @@
+
 /*
  * Copyright 2011 Google Inc.
  *
@@ -5,16 +6,15 @@
  * found in the LICENSE file.
  */
 #include "SkTypes.h"
-#if defined(SK_BUILD_FOR_MAC)
 
-#include "gl/SkGLContext.h"
+#include "gl/GLContext.h"
 #include "AvailabilityMacros.h"
 
 #include <OpenGL/OpenGL.h>
 #include <dlfcn.h>
 
 namespace {
-class MacGLContext : public SkGLContext {
+class MacGLContext : public sk_gpu_test::GLContext {
 public:
     MacGLContext();
     ~MacGLContext() override;
@@ -106,9 +106,10 @@
     return reinterpret_cast<GrGLFuncPtr>(dlsym(fGLLibrary, procName));
 }
 
-} // anonymous namespace
+}  // anonymous namespace
 
-SkGLContext* SkCreatePlatformGLContext(GrGLStandard forcedGpuAPI, SkGLContext* shareContext) {
+namespace sk_gpu_test {
+GLContext* CreatePlatformGLContext(GrGLStandard forcedGpuAPI, GLContext* shareContext) {
     SkASSERT(!shareContext);
     if (shareContext) {
         return nullptr;
@@ -124,5 +125,4 @@
     }
     return ctx;
 }
-
-#endif//defined(SK_BUILD_FOR_MAC)
+}  // namespace sk_gpu_test
diff --git a/tools/gpu/gl/mesa/GLContext_mesa.cpp b/tools/gpu/gl/mesa/GLContext_mesa.cpp
new file mode 100644
index 0000000..e6cc7c7
--- /dev/null
+++ b/tools/gpu/gl/mesa/GLContext_mesa.cpp
@@ -0,0 +1,151 @@
+
+/*
+ * 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/osmesa.h>
+
+#include "gl/mesa/GLContext_mesa.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<Context>(0)), fImage(nullptr) {
+    GR_STATIC_ASSERT(sizeof(Context) == sizeof(OSMesaContext));
+
+    /* Create an RGBA-mode context */
+#if OSMESA_MAJOR_VERSION * 100 + OSMESA_MINOR_VERSION >= 305
+    /* specify Z, stencil, accum sizes */
+    fContext = (Context)OSMesaCreateContextExt(OSMESA_BGRA, 0, 0, 0, nullptr);
+#else
+    fContext = (Context) OSMesaCreateContext(OSMESA_BGRA, nullptr);
+#endif
+    if (!fContext) {
+        SkDebugf("OSMesaCreateContext failed!\n");
+        this->destroyGLContext();
+        return;
+    }
+    // Allocate the image buffer
+    fImage = (GrGLubyte *) sk_malloc_throw(gBOGUS_SIZE * gBOGUS_SIZE *
+                                           4 * sizeof(GrGLubyte));
+    if (!fImage) {
+        SkDebugf("Alloc image buffer failed!\n");
+        this->destroyGLContext();
+        return;
+    }
+
+    // Bind the buffer to the context and make it current
+    if (!OSMesaMakeCurrent((OSMesaContext) fContext,
+                           fImage,
+                           GR_GL_UNSIGNED_BYTE,
+                           gBOGUS_SIZE,
+                           gBOGUS_SIZE)) {
+        SkDebugf("OSMesaMakeCurrent failed!\n");
+        this->destroyGLContext();
+        return;
+    }
+
+    SkAutoTUnref<const GrGLInterface> gl(create_mesa_interface());
+    if (nullptr == gl.get()) {
+        SkDebugf("Could not create GL interface!\n");
+        this->destroyGLContext();
+        return;
+    }
+
+    if (!gl->validate()) {
+        SkDebugf("Could not validate GL interface!\n");
+        this->destroyGLContext();
+        return;
+    }
+
+    this->init(gl.release());
+}
+
+MesaGLContext::~MesaGLContext() {
+    this->teardown();
+    this->destroyGLContext();
+}
+
+void MesaGLContext::destroyGLContext() {
+    if (fImage) {
+        sk_free(fImage);
+        fImage = nullptr;
+    }
+
+    if (fContext) {
+        OSMesaDestroyContext((OSMesaContext) fContext);
+        fContext = static_cast<Context>(0);
+    }
+}
+
+
+void MesaGLContext::onPlatformMakeCurrent() const {
+    if (fContext) {
+        if (!OSMesaMakeCurrent((OSMesaContext) fContext, fImage,
+                               GR_GL_UNSIGNED_BYTE, gBOGUS_SIZE, gBOGUS_SIZE)) {
+            SkDebugf("Could not make MESA context current.");
+        }
+    }
+}
+
+void MesaGLContext::onPlatformSwapBuffers() const { }
+
+GrGLFuncPtr MesaGLContext::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/tools/gpu/gl/mesa/GLContext_mesa.h b/tools/gpu/gl/mesa/GLContext_mesa.h
new file mode 100644
index 0000000..0d6ee4d
--- /dev/null
+++ b/tools/gpu/gl/mesa/GLContext_mesa.h
@@ -0,0 +1,17 @@
+
+/*
+ * 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
new file mode 100644
index 0000000..70de993
--- /dev/null
+++ b/tools/gpu/gl/mesa/osmesa_wrapper.h
@@ -0,0 +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.
+ */
+
+// 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 <GL/osmesa.h>
diff --git a/tools/gpu/gl/null/NullGLContext.cpp b/tools/gpu/gl/null/NullGLContext.cpp
new file mode 100644
index 0000000..4781c90
--- /dev/null
+++ b/tools/gpu/gl/null/NullGLContext.cpp
@@ -0,0 +1,630 @@
+
+/*
+ * 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<intptr_t>(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<GrGLuint>(fFreeListHead);
+            fFreeListHead = reinterpret_cast<intptr_t>(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<BufferObj*>(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<BufferObj*>   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 <typename T>
+    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
new file mode 100644
index 0000000..16fb9fd
--- /dev/null
+++ b/tools/gpu/gl/null/NullGLContext.h
@@ -0,0 +1,17 @@
+
+/*
+ * 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/src/gpu/gl/win/SkCreatePlatformGLContext_win.cpp b/tools/gpu/gl/win/CreatePlatformGLContext_win.cpp
similarity index 94%
rename from src/gpu/gl/win/SkCreatePlatformGLContext_win.cpp
rename to tools/gpu/gl/win/CreatePlatformGLContext_win.cpp
index e99aa15..efee28b 100644
--- a/src/gpu/gl/win/SkCreatePlatformGLContext_win.cpp
+++ b/tools/gpu/gl/win/CreatePlatformGLContext_win.cpp
@@ -1,3 +1,4 @@
+
 /*
  * Copyright 2011 Google Inc.
  *
@@ -5,7 +6,7 @@
  * found in the LICENSE file.
  */
 
-#include "gl/SkGLContext.h"
+#include "gl/GLContext.h"
 
 #include <windows.h>
 #include <GL/GL.h>
@@ -16,7 +17,7 @@
 
 namespace {
 
-class WinGLContext : public SkGLContext {
+class WinGLContext : public sk_gpu_test::GLContext {
 public:
     WinGLContext(GrGLStandard forcedGpuAPI);
 	~WinGLContext() override;
@@ -186,15 +187,18 @@
 
 } // anonymous namespace
 
-SkGLContext* SkCreatePlatformGLContext(GrGLStandard forcedGpuAPI, SkGLContext* shareContext) {
+namespace sk_gpu_test {
+GLContext* CreatePlatformGLContext(GrGLStandard forcedGpuAPI, GLContext *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/tools/kilobench/kilobench.cpp b/tools/kilobench/kilobench.cpp
index c0422d8..8123835 100644
--- a/tools/kilobench/kilobench.cpp
+++ b/tools/kilobench/kilobench.cpp
@@ -20,6 +20,7 @@
 #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"
@@ -29,6 +30,8 @@
 #include <sys/types.h>
 #include <sys/wait.h>
 
+using namespace sk_gpu_test;
+
 /*
  * This is an experimental GPU only benchmarking program.  The initial implementation will only
  * support SKPs.
@@ -144,14 +147,14 @@
     void setup() {
         fGL->makeCurrent();
         // Make sure we're done with whatever came before.
-        SK_GL(*fGL, Finish());
+        GR_GL_CALL(fGL->gl(), Finish());
     }
 
     SkCanvas* beginTiming(SkCanvas* canvas) { return canvas; }
 
     void endTiming(bool usePlatformSwapBuffers) {
         if (fGL) {
-            SK_GL(*fGL, Flush());
+            GR_GL_CALL(fGL->gl(), Flush());
             if (usePlatformSwapBuffers) {
                 fGL->swapBuffers();
             } else {
@@ -160,7 +163,7 @@
         }
     }
     void finish() {
-        SK_GL(*fGL, Finish());
+        GR_GL_CALL(fGL->gl(), Finish());
     }
 
     bool needsFrameTiming(int* maxFrameLag) const {
@@ -215,10 +218,10 @@
         return true;
     }
 
-    SkGLContext* gl() { return fGL; }
+    GLContext* gl() { return fGL; }
 
 private:
-    SkGLContext* fGL;
+    GLContext* fGL;
     SkAutoTDelete<SkSurface> fSurface;
 };
 
@@ -279,7 +282,7 @@
 static double now_ms() { return SkTime::GetNSecs() * 1e-6; }
 
 struct TimingThread {
-    TimingThread(SkGLContext* mainContext)
+    TimingThread(GLContext* mainContext)
         : fFenceSync(mainContext->fenceSync())
         ,  fMainContext(mainContext)
         ,  fDone(false) {}
@@ -305,8 +308,8 @@
 
     void timingLoop() {
         // Create a context which shares display lists with the main thread
-        SkAutoTDelete<SkGLContext> glContext(SkCreatePlatformGLContext(kNone_GrGLStandard,
-                                                                       fMainContext));
+        SkAutoTDelete<GLContext> glContext(CreatePlatformGLContext(kNone_GrGLStandard,
+                                                                   fMainContext));
         glContext->makeCurrent();
 
         // Basic timing methodology is:
@@ -402,7 +405,7 @@
     SyncQueue fFrameEndSyncs;
     SkTArray<double> fTimings;
     SkMutex fDoneMutex;
-    SkGLContext* fMainContext;
+    GLContext* fMainContext;
     bool fDone;
 };
 
diff --git a/tools/skiaserve/Request.cpp b/tools/skiaserve/Request.cpp
index 1d946ab..d9e1bda 100644
--- a/tools/skiaserve/Request.cpp
+++ b/tools/skiaserve/Request.cpp
@@ -10,6 +10,8 @@
 #include "SkPictureRecorder.h"
 #include "SkPixelSerializer.h"
 
+using namespace sk_gpu_test;
+
 static int kDefaultWidth = 1920;
 static int kDefaultHeight = 1080;
 
@@ -63,8 +65,8 @@
 SkCanvas* Request::getCanvas() {
 #if SK_SUPPORT_GPU
     GrContextFactory* factory = fContextFactory;
-    SkGLContext* gl = factory->getContextInfo(GrContextFactory::kNative_GLContextType,
-                                              GrContextFactory::kNone_GLContextOptions).fGLContext;
+    GLContext* 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 e3bc373..d19c2ba 100644
--- a/tools/skiaserve/Request.h
+++ b/tools/skiaserve/Request.h
@@ -19,7 +19,9 @@
 
 #include "UrlDataManager.h"
 
+namespace sk_gpu_test {
 class GrContextFactory;
+}
 struct MHD_Connection;
 struct MHD_PostProcessor;
 
@@ -69,7 +71,7 @@
     GrContext* getContext();
 
     sk_sp<SkPicture> fPicture;
-    GrContextFactory* fContextFactory;
+    sk_gpu_test::GrContextFactory* fContextFactory;
     SkAutoTUnref<SkSurface> fSurface;
     bool fGPUEnabled;
 };