Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(10)

Side by Side Diff: tools/gpu/gl/GLTestContext.h

Issue 1964243003: Add base class for GLTestContext and add new subclass VkTestContext. (Closed) Base URL: https://chromium.googlesource.com/skia.git@ContextInfo
Patch Set: undef more macros Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2013 Google Inc. 3 * Copyright 2013 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 #ifndef GLTestContext_DEFINED 8 #ifndef GLTestContext_DEFINED
9 #define GLTestContext_DEFINED 9 #define GLTestContext_DEFINED
10 10
11 #include "TestContext.h"
11 #include "gl/GrGLInterface.h" 12 #include "gl/GrGLInterface.h"
12 #include "../private/SkGpuFenceSync.h"
13
14 13
15 namespace sk_gpu_test { 14 namespace sk_gpu_test {
16 /** 15 /**
17 * Create an offscreen Oppengl context. Provides a GrGLInterface struct of funct ion pointers for 16 * An offscreen OpenGL context. Provides a GrGLInterface struct of function poin ters for the context
18 * the context. This class is intended for Skia's internal testing needs and not for general use. 17 * This class is intended for Skia's internal testing needs and not for general use.
19 */ 18 */
20 class GLTestContext : public SkNoncopyable { 19 class GLTestContext : public TestContext {
21 public: 20 public:
22 virtual ~GLTestContext(); 21 virtual ~GLTestContext();
23 22
24 bool isValid() const { return NULL != gl(); } 23 bool isValid() const override { return NULL != gl(); }
25 24
26 const GrGLInterface *gl() const { return fGL.get(); } 25 const GrGLInterface *gl() const { return fGL.get(); }
27 26
28 bool fenceSyncSupport() const { return fFenceSync != nullptr; }
29
30 bool getMaxGpuFrameLag(int *maxFrameLag) const {
31 if (!fFenceSync) {
32 return false;
33 }
34 *maxFrameLag = kMaxFrameLag;
35 return true;
36 }
37
38 void makeCurrent() const;
39
40 /** Used for testing EGLImage integration. Take a GL_TEXTURE_2D and wraps it in an EGL Image */ 27 /** Used for testing EGLImage integration. Take a GL_TEXTURE_2D and wraps it in an EGL Image */
41 virtual GrEGLImage texture2DToEGLImage(GrGLuint /*texID*/) const { return 0; } 28 virtual GrEGLImage texture2DToEGLImage(GrGLuint /*texID*/) const { return 0; }
42 29
43 virtual void destroyEGLImage(GrEGLImage) const { } 30 virtual void destroyEGLImage(GrEGLImage) const { }
44 31
45 /** Used for testing GL_TEXTURE_RECTANGLE integration. */ 32 /** Used for testing GL_TEXTURE_RECTANGLE integration. */
46 GrGLint createTextureRectangle(int width, int height, GrGLenum internalForma t, 33 GrGLint createTextureRectangle(int width, int height, GrGLenum internalForma t,
47 GrGLenum externalFormat, GrGLenum externalTyp e, 34 GrGLenum externalFormat, GrGLenum externalTyp e,
48 GrGLvoid *data); 35 GrGLvoid *data);
49 36
50 /** 37 /**
51 * Used for testing EGLImage integration. Takes a EGLImage and wraps it in a 38 * Used for testing EGLImage integration. Takes a EGLImage and wraps it in a
52 * GL_TEXTURE_EXTERNAL_OES. 39 * GL_TEXTURE_EXTERNAL_OES.
53 */ 40 */
54 virtual GrGLuint eglImageToExternalTexture(GrEGLImage) const { return 0; } 41 virtual GrGLuint eglImageToExternalTexture(GrEGLImage) const { return 0; }
55 42
56 void swapBuffers(); 43 void testAbandon() override;
57
58 /**
59 * The only purpose of this function it to provide a means of scheduling
60 * work on the GPU (since all of the subclasses create primary buffers for
61 * testing that are small and not meant to be rendered to the screen).
62 *
63 * If the platform supports fence sync (OpenGL 3.2+ or EGL_KHR_fence_sync),
64 * this will not swap any buffers, but rather emulate triple buffer
65 * synchronization using fences.
66 *
67 * Otherwise it will call the platform SwapBuffers method. This may or may
68 * not perform some sort of synchronization, depending on whether the
69 * drawing surface provided by the platform is double buffered.
70 */
71 void waitOnSyncOrSwap();
72
73 /**
74 * This notifies the context that we are deliberately testing abandoning
75 * the context. It is useful for debugging contexts that would otherwise
76 * test that GPU resources are properly deleted. It also allows a debugging
77 * context to test that further GL calls are not made by Skia GPU code.
78 */
79 void testAbandon();
80 44
81 /** 45 /**
82 * Creates a new GL context of the same type and makes the returned context current 46 * Creates a new GL context of the same type and makes the returned context current
83 * (if not null). 47 * (if not null).
84 */ 48 */
85 virtual GLTestContext *createNew() const { return nullptr; } 49 virtual GLTestContext *createNew() const { return nullptr; }
86 50
87 class GLFenceSync; // SkGpuFenceSync implementation that uses the OpenGL fu nctionality.
88
89 /*
90 * returns the fencesync object owned by this GLTestContext
91 */
92 SkGpuFenceSync *fenceSync() { return fFenceSync.get(); }
93
94 protected: 51 protected:
95 GLTestContext(); 52 GLTestContext();
96 53
97 /* 54 /*
98 * Methods that sublcasses must call from their constructors and destructors . 55 * Methods that sublcasses must call from their constructors and destructors .
99 */ 56 */
100 void init(const GrGLInterface *, SkGpuFenceSync * = NULL); 57 void init(const GrGLInterface *, SkGpuFenceSync * = NULL);
101 58
102 void teardown(); 59 void teardown() override;
103
104 /*
105 * Operations that have a platform-dependent implementation.
106 */
107 virtual void onPlatformMakeCurrent() const = 0;
108
109 virtual void onPlatformSwapBuffers() const = 0;
110 60
111 virtual GrGLFuncPtr onPlatformGetProcAddress(const char *) const = 0; 61 virtual GrGLFuncPtr onPlatformGetProcAddress(const char *) const = 0;
112 62
113 private: 63 private:
114 enum { 64 class GLFenceSync; // SkGpuFenceSync implementation that uses the OpenGL fu nctionality.
115 kMaxFrameLag = 3
116 };
117
118 SkAutoTDelete <SkGpuFenceSync> fFenceSync;
119 SkPlatformGpuFence fFrameFences[kMaxFrameLag - 1];
120 int fCurrentFenceIdx;
121 65
122 /** Subclass provides the gl interface object if construction was 66 /** Subclass provides the gl interface object if construction was
123 * successful. */ 67 * successful. */
124 SkAutoTUnref<const GrGLInterface> fGL; 68 SkAutoTUnref<const GrGLInterface> fGL;
125 69
126 friend class GLFenceSync; // For onPlatformGetProcAddress. 70 friend class GLFenceSync; // For onPlatformGetProcAddress.
71
72 typedef TestContext INHERITED;
127 }; 73 };
128 74
129 75 /**
130 /** Creates platform-dependent GL context object. The shareContext parameter is in an optional 76 * Creates platform-dependent GL context object. The shareContext parameter is in an optional
131 * context with which to share display lists. This should be a pointer to an GLT estContext created 77 * context with which to share display lists. This should be a pointer to an GLT estContext created
132 * with SkCreatePlatformGLTestContext. NULL indicates that no sharing is to tak e place. Returns a valid 78 * with SkCreatePlatformGLTestContext. NULL indicates that no sharing is to tak e place. Returns a
133 * gl context object or NULL if such can not be created. 79 * valid gl context object or NULL if such can not be created.
134 * Note: If Skia embedder needs a custom GL context that sets up the GL interfac e, this function
135 * should be implemented by the embedder. Otherwise, the default implementation for the platform
136 * should be compiled in the library.
137 */ 80 */
138 GLTestContext* CreatePlatformGLTestContext(GrGLStandard forcedGpuAPI, GLTestCont ext *shareContext = nullptr); 81 GLTestContext* CreatePlatformGLTestContext(GrGLStandard forcedGpuAPI,
82 GLTestContext *shareContext = nullptr );
139 83
140 } // namespace sk_gpu_test 84 } // namespace sk_gpu_test
141 #endif 85 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698