skia2/tools/gpu/gl/GLTestContext.h

111 lines
3.7 KiB
C
Raw Normal View History

Automatic update of all copyright notices to reflect new license terms. I have manually examined all of these diffs and restored a few files that seem to require manual adjustment. The following files still need to be modified manually, in a separate CL: android_sample/SampleApp/AndroidManifest.xml android_sample/SampleApp/res/layout/layout.xml android_sample/SampleApp/res/menu/sample.xml android_sample/SampleApp/res/values/strings.xml android_sample/SampleApp/src/com/skia/sampleapp/SampleApp.java android_sample/SampleApp/src/com/skia/sampleapp/SampleView.java experimental/CiCarbonSampleMain.c experimental/CocoaDebugger/main.m experimental/FileReaderApp/main.m experimental/SimpleCocoaApp/main.m experimental/iOSSampleApp/Shared/SkAlertPrompt.h experimental/iOSSampleApp/Shared/SkAlertPrompt.m experimental/iOSSampleApp/SkiOSSampleApp-Base.xcconfig experimental/iOSSampleApp/SkiOSSampleApp-Debug.xcconfig experimental/iOSSampleApp/SkiOSSampleApp-Release.xcconfig gpu/src/android/GrGLDefaultInterface_android.cpp gyp/common.gypi gyp_skia include/ports/SkHarfBuzzFont.h include/views/SkOSWindow_wxwidgets.h make.bat make.py src/opts/memset.arm.S src/opts/memset16_neon.S src/opts/memset32_neon.S src/opts/opts_check_arm.cpp src/ports/SkDebug_brew.cpp src/ports/SkMemory_brew.cpp src/ports/SkOSFile_brew.cpp src/ports/SkXMLParser_empty.cpp src/utils/ios/SkImageDecoder_iOS.mm src/utils/ios/SkOSFile_iOS.mm src/utils/ios/SkStream_NSData.mm tests/FillPathTest.cpp Review URL: http://codereview.appspot.com/4816058 git-svn-id: http://skia.googlecode.com/svn/trunk@1982 2bbb7eff-a529-9590-31e7-b0007b416f81
2011-07-28 14:26:00 +00:00
/*
* Copyright 2013 Google Inc.
Automatic update of all copyright notices to reflect new license terms. I have manually examined all of these diffs and restored a few files that seem to require manual adjustment. The following files still need to be modified manually, in a separate CL: android_sample/SampleApp/AndroidManifest.xml android_sample/SampleApp/res/layout/layout.xml android_sample/SampleApp/res/menu/sample.xml android_sample/SampleApp/res/values/strings.xml android_sample/SampleApp/src/com/skia/sampleapp/SampleApp.java android_sample/SampleApp/src/com/skia/sampleapp/SampleView.java experimental/CiCarbonSampleMain.c experimental/CocoaDebugger/main.m experimental/FileReaderApp/main.m experimental/SimpleCocoaApp/main.m experimental/iOSSampleApp/Shared/SkAlertPrompt.h experimental/iOSSampleApp/Shared/SkAlertPrompt.m experimental/iOSSampleApp/SkiOSSampleApp-Base.xcconfig experimental/iOSSampleApp/SkiOSSampleApp-Debug.xcconfig experimental/iOSSampleApp/SkiOSSampleApp-Release.xcconfig gpu/src/android/GrGLDefaultInterface_android.cpp gyp/common.gypi gyp_skia include/ports/SkHarfBuzzFont.h include/views/SkOSWindow_wxwidgets.h make.bat make.py src/opts/memset.arm.S src/opts/memset16_neon.S src/opts/memset32_neon.S src/opts/opts_check_arm.cpp src/ports/SkDebug_brew.cpp src/ports/SkMemory_brew.cpp src/ports/SkOSFile_brew.cpp src/ports/SkXMLParser_empty.cpp src/utils/ios/SkImageDecoder_iOS.mm src/utils/ios/SkOSFile_iOS.mm src/utils/ios/SkStream_NSData.mm tests/FillPathTest.cpp Review URL: http://codereview.appspot.com/4816058 git-svn-id: http://skia.googlecode.com/svn/trunk@1982 2bbb7eff-a529-9590-31e7-b0007b416f81
2011-07-28 14:26:00 +00:00
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef GLTestContext_DEFINED
#define GLTestContext_DEFINED
#include "include/gpu/gl/GrGLInterface.h"
#include "src/gpu/gl/GrGLUtil.h"
#include "tools/gpu/TestContext.h"
namespace sk_gpu_test {
/**
* An offscreen OpenGL 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.
* When SK_GL is not defined the GrGLInterface will always be nullptr.
*/
class GLTestContext : public TestContext {
public:
~GLTestContext() override;
GrBackendApi backend() override { return GrBackendApi::kOpenGL; }
/** Does this represent a successfully created GL context? */
bool isValid() const;
const GrGLInterface* gl() const { return fGLInterface.get(); }
/** Used for testing EGLImage integration. Take a GL_TEXTURE_2D and wraps it in an EGL Image */
virtual GrEGLImage texture2DToEGLImage(GrGLuint /*texID*/) const { return nullptr; }
virtual void destroyEGLImage(GrEGLImage) const { }
/**
* Used for testing EGLImage integration. Takes a EGLImage and wraps it in a
* GL_TEXTURE_EXTERNAL_OES.
*/
virtual GrGLuint eglImageToExternalTexture(GrEGLImage) const { return 0; }
void testAbandon() override;
/** Wait until all GPU work is finished. */
void finish() override;
void overrideVersion(const char* version, const char* shadingLanguageVersion);
/**
* Creates a new GL context of the same type and makes the returned context current
* (if not null).
*/
virtual std::unique_ptr<GLTestContext> makeNew() const { return nullptr; }
template<typename Ret, typename... Args>
void getGLProcAddress(Ret(GR_GL_FUNCTION_TYPE** out)(Args...),
const char* name, const char* ext = nullptr) const {
using Proc = Ret(GR_GL_FUNCTION_TYPE*)(Args...);
if (!SkStrStartsWith(name, "gl")) {
SK_ABORT("getGLProcAddress: proc name must have 'gl' prefix");
*out = nullptr;
} else if (ext) {
SkString fullname(name);
fullname.append(ext);
*out = reinterpret_cast<Proc>(this->onPlatformGetProcAddress(fullname.c_str()));
} else {
*out = reinterpret_cast<Proc>(this->onPlatformGetProcAddress(name));
}
}
sk_sp<GrDirectContext> makeContext(const GrContextOptions& options) override;
protected:
GLTestContext();
/*
* Methods that subclasses must call from their constructors and destructors.
*/
void init(sk_sp<const GrGLInterface>);
void teardown() override;
virtual GrGLFuncPtr onPlatformGetProcAddress(const char *) const = 0;
private:
/** Subclass provides the gl interface object if construction was successful. */
sk_sp<const GrGLInterface> fOriginalGLInterface;
/** The same as fOriginalGLInterface unless the version has been overridden. */
sk_sp<const GrGLInterface> fGLInterface;
#ifndef SK_GL
bool fWasInitialized = false;
#endif
using INHERITED = TestContext;
};
/**
* 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 GLTestContext created
* with SkCreatePlatformGLTestContext. NULL indicates that no sharing is to take place. Returns a
* valid gl context object or NULL if such can not be created.
*/
GLTestContext* CreatePlatformGLTestContext(GrGLStandard forcedGpuAPI,
GLTestContext *shareContext = nullptr);
} // namespace sk_gpu_test
#endif