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
This commit is contained in:
bsalomon 2016-03-30 18:56:19 -07:00 committed by Commit bot
parent 2238c9dbca
commit 3724e574a7
89 changed files with 1725 additions and 1057 deletions

View File

@ -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 @@ bool Target::capturePixels(SkBitmap* bmp) {
#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 @@ struct GPUTarget : public Target {
}
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);
}
};

View File

@ -29,8 +29,8 @@ struct Config {
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;

View File

@ -90,7 +90,6 @@ remove_srcs(
../src/gpu/GrContextFactory.cpp # For internal testing only.
../src/gpu/gl/GrGLCreateNativeInterface_none.cpp
../src/gpu/gl/GrGLDefaultInterface_none.cpp
../src/gpu/gl/SkCreatePlatformGLContext*.cpp # For internal testing only.
../src/gpu/gl/command_buffer/*
../src/gpu/gl/egl/*
../src/gpu/gl/glfw/*
@ -121,8 +120,6 @@ if (WIN32)
endif()
endif()
remove_srcs(../src/gpu/gl/angle/*) # TODO
# Certain files must be compiled with support for SSSE3, SSE4.1, AVX, or AVX2 intrinsics.
file (GLOB_RECURSE ssse3_srcs ../src/*ssse3*.cpp ../src/*SSSE3*.cpp)
file (GLOB_RECURSE sse41_srcs ../src/*sse4*.cpp ../src/*SSE4*.cpp)

View File

@ -70,6 +70,8 @@ DEFINE_int32(shard, 0, "Which shard do I run?");
DEFINE_bool(simpleCodec, false, "Only decode images to native scale");
using namespace DM;
using sk_gpu_test::GrContextFactory;
using sk_gpu_test::GLContext;
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
@ -1416,7 +1418,7 @@ int dm_main() {
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);

View File

@ -28,12 +28,13 @@ namespace DM {
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 @@ public:
void dumpGpuStats(SkString*) const {}
};
namespace sk_gpu_test {
class GrContextFactory {
public:
GrContextFactory() {};
@ -83,14 +85,15 @@ public:
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) {

View File

@ -45,6 +45,8 @@ DEFINE_bool(multiPage, false, "For document-type backends, render the source"
" into multiple pages");
DEFINE_bool(RAW_threading, true, "Allow RAW decodes to run on multiple threads?");
using sk_gpu_test::GrContextFactory;
namespace DM {
GMSrc::GMSrc(skiagm::GMRegistry::Factory factory) : fFactory(factory) {}

View File

@ -232,7 +232,8 @@ public:
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 @@ public:
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 {

View File

@ -433,7 +433,7 @@ DEF_SIMPLE_GM(new_texture_image, canvas, 225, 60) {
GrContext* context = nullptr;
#if SK_SUPPORT_GPU
context = canvas->getGrContext();
GrContextFactory factory;
sk_gpu_test::GrContextFactory factory;
#endif
if (!context) {
skiagm::GM::DrawGpuOnlyMessage(canvas);

View File

@ -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',

View File

@ -11,7 +11,7 @@
'type': 'none',
'conditions': [
[ 'skia_angle', {
'direct_dependent_settings': {
'all_dependent_settings': {
'include_dirs': [
'../third_party/externals/angle2/include',
],

View File

@ -24,7 +24,14 @@
'include_dirs': [
'../tools/flags',
],
}
},
'conditions': [
['skia_gpu', {
'dependencies': [
'gputest.gyp:skgputest',
],
}],
],
},
{
'target_name': 'flags_common',

View File

@ -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',

View File

@ -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',
],
},
}

View File

@ -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)$'], ],
}],
],
},
],

View File

@ -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',

View File

@ -37,15 +37,6 @@
'-llog',
],
}],
[ 'skia_gpu == 1', {
'include_dirs': [
'../src/gpu',
],
'sources': [
'../src/gpu/GrContextFactory.cpp',
'../src/gpu/GrContextFactory.h',
]
}],
],
},
],

View File

@ -14,6 +14,7 @@
'type': 'executable',
'include_dirs': [
'../src/core',
'../src/gpu',
'../src/ports',
'../tools/debugger',
'../tools/json',

View File

@ -125,6 +125,11 @@
'../include/gpu',
],
}],
[ 'skia_angle', {
'dependencies': [
'angle.gyp:*',
],
}],
[ 'skia_use_sdl == 1', {
'defines': [
'SK_USE_SDL',

View File

@ -20,6 +20,7 @@
'../include/private',
'../src/core',
'../src/effects',
'../src/gpu',
'../src/images',
'../src/image',
'../src/pdf',

View File

@ -43,39 +43,18 @@ const GrGLInterface* GrGLDefaultInterface();
*/
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*);

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -98,10 +98,11 @@ private:
#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;

View File

@ -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 @@ public:
break;
#if SK_ANGLE
case kANGLE_DeviceType:
glInterface.reset(GrGLCreateANGLEInterface());
glInterface.reset(sk_gpu_test::CreateANGLEGLInterface());
break;
#endif // SK_ANGLE
#if SK_COMMAND_BUFFER

View File

@ -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) {}

View File

@ -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();
}

View File

@ -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);
}

View File

@ -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();
}

View File

@ -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

View File

@ -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);
}

View File

@ -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

View File

@ -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;
}

View File

@ -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 @@ void SkOSWindow::presentGL() {
#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 @@ bool create_ANGLE(EGLNativeWindowType hWnd,
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 @@ bool SkOSWindow::attachANGLE(int msaaSampleCount, AttachmentInfo* info) {
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;
}
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;
}
}
if (eglMakeCurrent(fDisplay, fSurface, fSurface, fContext)) {
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::detachANGLE() {
}
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 @@ bool SkOSWindow::attachCommandBuffer(int msaaSampleCount, AttachmentInfo* info)
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 @@ bool SkOSWindow::attachCommandBuffer(int msaaSampleCount, AttachmentInfo* info)
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;

View File

@ -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 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(EGLImageTest, reporter, context0, glCtx0) {
return;
}
SkAutoTDelete<SkGLContext> glCtx1 = glCtx0->createNew();
SkAutoTDelete<GLContext> glCtx1 = glCtx0->createNew();
if (!glCtx1) {
return;
}

View File

@ -455,7 +455,7 @@ DEF_GPUTEST(GLPrograms, reporter, /*factory*/) {
// 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,

View File

@ -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.

View File

@ -1147,8 +1147,8 @@ static void test_lcd_coverage_fallback_case(skiatest::Reporter* reporter, const
DEF_GPUTEST(PorterDuffNoDualSourceBlending, reporter, /*factory*/) {
GrContextOptions opts;
opts.fSuppressDualSourceBlending = true;
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;

View File

@ -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();

View File

@ -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[]) {

View File

@ -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 @@ public:
#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 @@ enum GPUTestContexts {
};
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 @@ private:
} \
} 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( \

View File

@ -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"})

View File

@ -9,7 +9,7 @@
#if SK_SUPPORT_GPU
#include "GrContext.h"
#include "gl/SkGLContext.h"
#include "gl/GLContext.h"
#endif
@ -64,7 +64,7 @@ DEF_GPUTEST_FOR_NULL_CONTEXT(TestGpuNullContext, reporter, context) {
#endif
// This is an example of a GPU test that tests a property that should work for all GPU contexts.
// It uses the additional 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);

View File

@ -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"

View File

@ -24,6 +24,7 @@
#endif
using namespace skiatest;
using namespace sk_gpu_test;
DEFINE_bool2(extendedTest, x, false, "run extended tests for pathOps.");

View File

@ -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;

View File

@ -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

View File

@ -50,7 +50,7 @@ class SkCommandLineConfig {
// * backends that represent a shorthand of above (such as "msaa16" representing "gpu(samples=16)")
class SkCommandLineConfigGpu : public SkCommandLineConfig {
public:
typedef 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);

View File

@ -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 @@ GrContextFactory::ContextInfo GrContextFactory::getContextInfo(GLContextType typ
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 @@ GrContextFactory::ContextInfo GrContextFactory::getContextInfo(GLContextType typ
}
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 @@ GrContextFactory::ContextInfo GrContextFactory::getContextInfo(GLContextType typ
context.fOptions = options;
return ContextInfo(context.fGrContext, context.fGLContext);
}
} // namespace sk_gpu_test

View File

@ -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 @@ public:
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 @@ public:
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

View File

@ -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 @@ private:
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 @@ SkGLContext::~SkGLContext() {
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 @@ void SkGLContext::teardown() {
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 @@ void SkGLContext::waitOnSyncOrSwap() {
fCurrentFenceIdx = (fCurrentFenceIdx + 1) % SK_ARRAY_COUNT(fFrameFences);
}
void SkGLContext::testAbandon() {
void GLContext::testAbandon() {
if (fGL) {
fGL->abandon();
}
@ -107,12 +109,12 @@ void SkGLContext::testAbandon() {
}
}
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 @@ SkGLContext::GLFenceSync* SkGLContext::GLFenceSync::CreateIfSupported(const SkGL
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 @@ GrGLint SkGLContext::createTextureRectangle(int width, int height, GrGLenum inte
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

View File

@ -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 @@ public:
/** 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 @@ public:
* 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 @@ private:
friend class GLFenceSync; // For onPlatformGetProcAddress.
};
/** Creates platform-dependent GL context object. The shareContext parameter is in an optional
* context with which to share display lists. This should be a pointer to an 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);
/**
* 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
GLContext* CreatePlatformGLContext(GrGLStandard forcedGpuAPI, GLContext *shareContext = nullptr);
} // namespace sk_gpu_test
#endif

View File

@ -1,3 +1,4 @@
/*
* Copyright 2012 Google Inc.
*
@ -5,7 +6,7 @@
* found in the LICENSE file.
*/
#include "gl/angle/SkANGLEGLContext.h"
#include "GLContext_angle.h"
#include <EGL/egl.h>
#include <EGL/eglext.h>
@ -13,32 +14,57 @@
#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
void* SkANGLEGLContext::GetD3DEGLDisplay(void* nativeDisplay, bool useGLBackend) {
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 eglGetDisplay(static_cast<EGLNativeDisplayType>(nativeDisplay));
return EGL_NO_DISPLAY;
}
EGLDisplay display = EGL_NO_DISPLAY;
if (useGLBackend) {
// Try for an ANGLE D3D11 context, fall back to D3D9.
EGLint attribs[3] = {
EGL_PLATFORM_ANGLE_TYPE_ANGLE,
EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE,
EGL_NONE
EGL_PLATFORM_ANGLE_TYPE_ANGLE,
EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE,
EGL_NONE
};
display = eglGetPlatformDisplayEXT(EGL_PLATFORM_ANGLE_ANGLE, nativeDisplay, attribs);
} else {
// Try for an ANGLE D3D11 context, fall back to D3D9, and finally GL.
// Try for an ANGLE D3D11 context, fall back to D3D9.
EGLint attribs[3][3] = {
{
EGL_PLATFORM_ANGLE_TYPE_ANGLE,
@ -50,11 +76,6 @@ void* SkANGLEGLContext::GetD3DEGLDisplay(void* nativeDisplay, bool useGLBackend)
EGL_PLATFORM_ANGLE_TYPE_D3D9_ANGLE,
EGL_NONE
},
{
EGL_PLATFORM_ANGLE_TYPE_ANGLE,
EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE,
EGL_NONE
}
};
for (int i = 0; i < 3 && display == EGL_NO_DISPLAY; ++i) {
display = eglGetPlatformDisplayEXT(EGL_PLATFORM_ANGLE_ANGLE,nativeDisplay, attribs[i]);
@ -63,7 +84,30 @@ void* SkANGLEGLContext::GetD3DEGLDisplay(void* nativeDisplay, bool useGLBackend)
return display;
}
SkANGLEGLContext::SkANGLEGLContext(bool useGLBackend)
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) {
@ -80,7 +124,7 @@ SkANGLEGLContext::SkANGLEGLContext(bool useGLBackend)
};
fIsGLBackend = useGLBackend;
fDisplay = GetD3DEGLDisplay(EGL_DEFAULT_DISPLAY, useGLBackend);
fDisplay = get_angle_egl_display(EGL_DEFAULT_DISPLAY, useGLBackend);
if (EGL_NO_DISPLAY == fDisplay) {
SkDebugf("Could not create EGL display!");
return;
@ -110,7 +154,7 @@ SkANGLEGLContext::SkANGLEGLContext(bool useGLBackend)
eglMakeCurrent(fDisplay, fSurface, fSurface, fContext);
SkAutoTUnref<const GrGLInterface> gl(GrGLCreateANGLEInterface());
SkAutoTUnref<const GrGLInterface> gl(sk_gpu_test::CreateANGLEGLInterface());
if (nullptr == gl.get()) {
SkDebugf("Could not create ANGLE GL interface!\n");
this->destroyGLContext();
@ -125,12 +169,12 @@ SkANGLEGLContext::SkANGLEGLContext(bool useGLBackend)
this->init(gl.release());
}
SkANGLEGLContext::~SkANGLEGLContext() {
ANGLEGLContext::~ANGLEGLContext() {
this->teardown();
this->destroyGLContext();
}
GrEGLImage SkANGLEGLContext::texture2DToEGLImage(GrGLuint texID) const {
GrEGLImage ANGLEGLContext::texture2DToEGLImage(GrGLuint texID) const {
if (!this->gl()->hasExtension("EGL_KHR_gl_texture_2D_image")) {
return GR_EGL_NO_IMAGE;
}
@ -146,17 +190,16 @@ GrEGLImage SkANGLEGLContext::texture2DToEGLImage(GrGLuint texID) const {
return img;
}
void SkANGLEGLContext::destroyEGLImage(GrEGLImage image) const {
void ANGLEGLContext::destroyEGLImage(GrEGLImage image) const {
GR_GL_CALL(this->gl(), EGLDestroyImage(fDisplay, image));
}
GrGLuint SkANGLEGLContext::eglImageToExternalTexture(GrEGLImage image) const {
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) {
@ -180,12 +223,12 @@ GrGLuint SkANGLEGLContext::eglImageToExternalTexture(GrEGLImage image) const {
return texID;
}
SkGLContext* SkANGLEGLContext::createNew() const {
sk_gpu_test::GLContext* ANGLEGLContext::createNew() const {
#ifdef SK_BUILD_FOR_WIN
SkGLContext* ctx = fIsGLBackend ? SkANGLEGLContext::CreateOpenGL()
: SkANGLEGLContext::CreateDirectX();
sk_gpu_test::GLContext* ctx = fIsGLBackend ? sk_gpu_test::CreateANGLEOpenGLGLContext()
: sk_gpu_test::CreateANGLEDirect3DGLContext();
#else
SkGLContext* ctx = SkANGLEGLContext::CreateOpenGL();
sk_gpu_test::GLContext* ctx = sk_gpu_test::CreateANGLEOpenGLGLContext();
#endif
if (ctx) {
ctx->makeCurrent();
@ -193,7 +236,7 @@ SkGLContext* SkANGLEGLContext::createNew() const {
return ctx;
}
void SkANGLEGLContext::destroyGLContext() {
void ANGLEGLContext::destroyGLContext() {
if (fDisplay) {
eglMakeCurrent(fDisplay, 0, 0, 0);
@ -212,18 +255,66 @@ void SkANGLEGLContext::destroyGLContext() {
}
}
void SkANGLEGLContext::onPlatformMakeCurrent() const {
void ANGLEGLContext::onPlatformMakeCurrent() const {
if (!eglMakeCurrent(fDisplay, fSurface, fSurface, fContext)) {
SkDebugf("Could not set the context.\n");
}
}
void SkANGLEGLContext::onPlatformSwapBuffers() const {
void ANGLEGLContext::onPlatformSwapBuffers() const {
if (!eglSwapBuffers(fDisplay, fSurface)) {
SkDebugf("Could not complete eglSwapBuffers.\n");
}
}
GrGLFuncPtr SkANGLEGLContext::onPlatformGetProcAddress(const char* name) const {
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

View File

@ -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

View File

@ -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 GetProcAddressProc gfGetProcAddress = nullptr;
static void* gLibrary = nullptr;
static bool gfFunctionsLoadedSuccessfully = false;
namespace {
static void load_command_buffer_functions() {
if (!gLibrary) {
#if defined _WIN32
@ -124,22 +127,24 @@ static GrGLFuncPtr command_buffer_get_gl_proc(void* ctx, const char name[]) {
}
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 @@ SkCommandBufferGLContext::SkCommandBufferGLContext()
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 @@ SkCommandBufferGLContext::SkCommandBufferGLContext(void* nativeWindow, int msaaS
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 @@ void SkCommandBufferGLContext::initializeGLContext(void* nativeWindow, const int
}
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 @@ void SkCommandBufferGLContext::initializeGLContext(void* nativeWindow, const int
if (nativeWindow) {
fSurface = gfCreateWindowSurface(fDisplay,
static_cast<EGLConfig>(fConfig),
(EGLNativeWindowType)nativeWindow,
(EGLNativeWindowType) nativeWindow,
surfaceAttribs);
} else {
fSurface = gfCreatePbufferSurface(fDisplay,
@ -246,7 +251,7 @@ void SkCommandBufferGLContext::initializeGLContext(void* nativeWindow, const int
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 @@ void SkCommandBufferGLContext::initializeGLContext(void* nativeWindow, const int
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::destroyGLContext() {
}
}
void SkCommandBufferGLContext::onPlatformMakeCurrent() const {
void CommandBufferGLContext::onPlatformMakeCurrent() const {
if (!gfFunctionsLoadedSuccessfully) {
return;
}
@ -297,7 +302,7 @@ void SkCommandBufferGLContext::onPlatformMakeCurrent() const {
}
}
void SkCommandBufferGLContext::onPlatformSwapBuffers() const {
void CommandBufferGLContext::onPlatformSwapBuffers() const {
if (!gfFunctionsLoadedSuccessfully) {
return;
}
@ -306,14 +311,14 @@ void SkCommandBufferGLContext::onPlatformSwapBuffers() const {
}
}
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 @@ void SkCommandBufferGLContext::presentCommandBuffer() {
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

View File

@ -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

View File

@ -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 @@ public:
}
}
GrGLvoid useProgram(GrGLuint programID) override {
GrGLvoid useProgram(GrGLuint programID) override {
// A programID of 0 is legal
GrProgramObj *program = FIND(programID, GrProgramObj, kProgram_ObjTypes);
// A programID of 0 is legal
GrProgramObj *program = FIND(programID, GrProgramObj, kProgram_ObjTypes);
this->useProgram(program);
}
this->useProgram(program);
}
GrGLvoid bindFramebuffer(GrGLenum target, GrGLuint frameBufferID) override {
GrGLvoid bindFramebuffer(GrGLenum target, GrGLuint frameBufferID) override {
GrAlwaysAssert(GR_GL_FRAMEBUFFER == target ||
GR_GL_READ_FRAMEBUFFER == target ||
GR_GL_DRAW_FRAMEBUFFER);
GrAlwaysAssert(GR_GL_FRAMEBUFFER == target ||
GR_GL_READ_FRAMEBUFFER == target ||
GR_GL_DRAW_FRAMEBUFFER);
// a frameBufferID of 0 is acceptable - it binds to the default
// frame buffer
GrFrameBufferObj *frameBuffer = FIND(frameBufferID, GrFrameBufferObj,
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 @@ const char* DebugInterface::kExtensions[] = {
nullptr, // signifies the end of the array.
};
class DebugGLContext : public sk_gpu_test::GLContext {
public:
DebugGLContext() {
this->init(new DebugInterface());
}
~DebugGLContext() override { this->teardown(); }
private:
void onPlatformMakeCurrent() const override {}
void onPlatformSwapBuffers() const override {}
GrGLFuncPtr onPlatformGetProcAddress(const char*) const override { return nullptr; }
};
} // anonymous namespace
////////////////////////////////////////////////////////////////////////////////
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;
}
}

View File

@ -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

View File

@ -1,3 +1,4 @@
/*
* Copyright 2012 Google Inc.
*

View File

@ -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 {

View File

@ -1,3 +1,4 @@
/*
* Copyright 2012 Google Inc.
*

View File

@ -1,3 +1,4 @@
/*
* Copyright 2012 Google Inc.
*

View File

@ -1,3 +1,4 @@
/*
* Copyright 2012 Google Inc.
*

View File

@ -1,3 +1,4 @@
/*
* Copyright 2012 Google Inc.
*

View File

@ -1,3 +1,4 @@
/*
* Copyright 2012 Google Inc.
*

View File

@ -1,3 +1,4 @@
/*
* Copyright 2012 Google Inc.
*

View File

@ -1,3 +1,4 @@
/*
* Copyright 2012 Google Inc.
*

View File

@ -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 {

View File

@ -1,3 +1,4 @@
/*
* Copyright 2012 Google Inc.
*

View File

@ -1,3 +1,4 @@
/*
* Copyright 2012 Google Inc.
*

View File

@ -1,3 +1,4 @@
/*
* Copyright 2012 Google Inc.
*

View File

@ -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 @@ private:
typedef SkGpuFenceSync INHERITED;
};
class EGLGLContext : public SkGLContext {
class EGLGLContext : public sk_gpu_test::GLContext {
public:
EGLGLContext(GrGLStandard forcedGpuAPI);
~EGLGLContext() override;
@ -42,7 +43,7 @@ public:
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 @@ GrGLuint EGLGLContext::eglImageToExternalTexture(GrEGLImage image) const {
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 @@ void SkEGLFenceSync::deleteFence(SkPlatformGpuFence platformFence) const {
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

View File

@ -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 @@ static int ctxErrorHandler(Display *dpy, XErrorEvent *ev) {
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 @@ GrGLFuncPtr GLXGLContext::onPlatformGetProcAddress(const char* procName) const {
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 @@ SkGLContext* SkCreatePlatformGLContext(GrGLStandard forcedGpuAPI, SkGLContext* s
}
return ctx;
}
} // namespace sk_gpu_test

View File

@ -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 @@ GrGLFuncPtr IOSGLContext::onPlatformGetProcAddress(const char* procName) const {
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 @@ SkGLContext* SkCreatePlatformGLContext(GrGLStandard forcedGpuAPI, SkGLContext* s
if (kGL_GrGLStandard == forcedGpuAPI) {
return NULL;
}
IOSGLContext* ctx = new IOSGLContext;
IOSGLContext *ctx = new IOSGLContext;
if (!ctx->isValid()) {
delete ctx;
return NULL;
}
return ctx;
}
}

View File

@ -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 @@ GrGLFuncPtr MacGLContext::onPlatformGetProcAddress(const char* procName) const {
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 @@ SkGLContext* SkCreatePlatformGLContext(GrGLStandard forcedGpuAPI, SkGLContext* s
}
return ctx;
}
#endif//defined(SK_BUILD_FOR_MAC)
} // namespace sk_gpu_test

View File

@ -1,3 +1,4 @@
/*
* Copyright 2011 Google Inc.
*
@ -7,14 +8,52 @@
#include <GL/osmesa.h>
#include "gl/mesa/SkMesaGLContext.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;
SkMesaGLContext::SkMesaGLContext()
: fContext(static_cast<Context>(0))
, fImage(nullptr) {
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 */
@ -22,7 +61,7 @@ SkMesaGLContext::SkMesaGLContext()
/* specify Z, stencil, accum sizes */
fContext = (Context)OSMesaCreateContextExt(OSMESA_BGRA, 0, 0, 0, nullptr);
#else
fContext = (Context)OSMesaCreateContext(OSMESA_BGRA, nullptr);
fContext = (Context) OSMesaCreateContext(OSMESA_BGRA, nullptr);
#endif
if (!fContext) {
SkDebugf("OSMesaCreateContext failed!\n");
@ -39,7 +78,7 @@ SkMesaGLContext::SkMesaGLContext()
}
// Bind the buffer to the context and make it current
if (!OSMesaMakeCurrent((OSMesaContext)fContext,
if (!OSMesaMakeCurrent((OSMesaContext) fContext,
fImage,
GR_GL_UNSIGNED_BYTE,
gBOGUS_SIZE,
@ -49,7 +88,7 @@ SkMesaGLContext::SkMesaGLContext()
return;
}
SkAutoTUnref<const GrGLInterface> gl(GrGLCreateMesaInterface());
SkAutoTUnref<const GrGLInterface> gl(create_mesa_interface());
if (nullptr == gl.get()) {
SkDebugf("Could not create GL interface!\n");
this->destroyGLContext();
@ -65,36 +104,48 @@ SkMesaGLContext::SkMesaGLContext()
this->init(gl.release());
}
SkMesaGLContext::~SkMesaGLContext() {
MesaGLContext::~MesaGLContext() {
this->teardown();
this->destroyGLContext();
}
void SkMesaGLContext::destroyGLContext() {
void MesaGLContext::destroyGLContext() {
if (fImage) {
sk_free(fImage);
fImage = nullptr;
}
if (fContext) {
OSMesaDestroyContext((OSMesaContext)fContext);
OSMesaDestroyContext((OSMesaContext) fContext);
fContext = static_cast<Context>(0);
}
}
void SkMesaGLContext::onPlatformMakeCurrent() const {
void MesaGLContext::onPlatformMakeCurrent() const {
if (fContext) {
if (!OSMesaMakeCurrent((OSMesaContext)fContext, fImage,
if (!OSMesaMakeCurrent((OSMesaContext) fContext, fImage,
GR_GL_UNSIGNED_BYTE, gBOGUS_SIZE, gBOGUS_SIZE)) {
SkDebugf("Could not make MESA context current.");
}
}
}
void SkMesaGLContext::onPlatformSwapBuffers() const { }
void MesaGLContext::onPlatformSwapBuffers() const { }
GrGLFuncPtr SkMesaGLContext::onPlatformGetProcAddress(const char* procName) 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

View File

@ -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

View File

@ -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>

View File

@ -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

View File

@ -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

View File

@ -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 @@ GrGLFuncPtr WinGLContext::onPlatformGetProcAddress(const char* name) const {
} // 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

View File

@ -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 @@ struct GPUTarget {
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 @@ struct GPUTarget {
}
}
void finish() {
SK_GL(*fGL, Finish());
GR_GL_CALL(fGL->gl(), Finish());
}
bool needsFrameTiming(int* maxFrameLag) const {
@ -215,10 +218,10 @@ struct GPUTarget {
return true;
}
SkGLContext* gl() { return fGL; }
GLContext* gl() { return fGL; }
private:
SkGLContext* fGL;
GLContext* fGL;
SkAutoTDelete<SkSurface> fSurface;
};
@ -279,7 +282,7 @@ static int clamp_loops(int loops) {
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 @@ struct TimingThread {
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 @@ private:
SyncQueue fFrameEndSyncs;
SkTArray<double> fTimings;
SkMutex fDoneMutex;
SkGLContext* fMainContext;
GLContext* fMainContext;
bool fDone;
};

View File

@ -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 @@ SkData* Request::writeCanvasToPng(SkCanvas* canvas) {
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);

View File

@ -19,7 +19,9 @@
#include "UrlDataManager.h"
namespace sk_gpu_test {
class GrContextFactory;
}
struct MHD_Connection;
struct MHD_PostProcessor;
@ -69,7 +71,7 @@ private:
GrContext* getContext();
sk_sp<SkPicture> fPicture;
GrContextFactory* fContextFactory;
sk_gpu_test::GrContextFactory* fContextFactory;
SkAutoTUnref<SkSurface> fSurface;
bool fGPUEnabled;
};