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

Side by Side Diff: src/gpu/GrContextFactory.h

Issue 1815823002: Move SkGLContext and some GrGLInterface implementations to skgputest module (Closed) Base URL: https://chromium.googlesource.com/skia.git@debugobject
Patch Set: fix windows and android? Created 4 years, 8 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
« no previous file with comments | « samplecode/SampleApp.cpp ('k') | src/gpu/GrContextFactory.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright 2012 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #ifndef GrContextFactory_DEFINED
9 #define GrContextFactory_DEFINED
10
11 #include "GrContext.h"
12 #include "GrContextOptions.h"
13
14 #include "gl/SkGLContext.h"
15 #include "SkTArray.h"
16
17 /**
18 * This is a simple class that is useful in test apps that use different
19 * GrContexts backed by different types of GL contexts. It manages creating the
20 * GL context and a GrContext that uses it. The GL/Gr contexts persist until the
21 * factory is destroyed (though the caller can always grab a ref on the returned
22 * Gr and GL contexts to make them outlive the factory).
23 */
24 class GrContextFactory : SkNoncopyable {
25 public:
26 enum GLContextType {
27 kNative_GLContextType, //! OpenGL or OpenGL ES context.
28 kGL_GLContextType, //! OpenGL context.
29 kGLES_GLContextType, //! OpenGL ES context.
30 #if SK_ANGLE
31 #ifdef SK_BUILD_FOR_WIN
32 kANGLE_GLContextType, //! ANGLE on DirectX OpenGL ES context.
33 #endif
34 kANGLE_GL_GLContextType, //! ANGLE on OpenGL OpenGL ES context.
35 #endif
36 #if SK_COMMAND_BUFFER
37 kCommandBuffer_GLContextType, //! Chromium command buffer OpenGL ES cont ext.
38 #endif
39 #if SK_MESA
40 kMESA_GLContextType, //! MESA OpenGL context
41 #endif
42 kNull_GLContextType, //! Non-rendering OpenGL mock context.
43 kDebug_GLContextType, //! Non-rendering, state verifying OpenGL context.
44 kLastGLContextType = kDebug_GLContextType
45 };
46
47 static const int kGLContextTypeCnt = kLastGLContextType + 1;
48
49 /**
50 * Options for GL context creation. For historical and testing reasons the o ptions will default
51 * to not using GL_NV_path_rendering extension even when the driver support s it.
52 */
53 enum GLContextOptions {
54 kNone_GLContextOptions = 0,
55 kEnableNVPR_GLContextOptions = 0x1,
56 kRequireSRGBSupport_GLContextOptions = 0x2,
57 };
58
59 static bool IsRenderingGLContext(GLContextType type) {
60 switch (type) {
61 case kNull_GLContextType:
62 case kDebug_GLContextType:
63 return false;
64 default:
65 return true;
66 }
67 }
68
69 static const char* GLContextTypeName(GLContextType type) {
70 switch (type) {
71 case kNative_GLContextType:
72 return "native";
73 case kGL_GLContextType:
74 return "gl";
75 case kGLES_GLContextType:
76 return "gles";
77 #if SK_ANGLE
78 #ifdef SK_BUILD_FOR_WIN
79 case kANGLE_GLContextType:
80 return "angle";
81 #endif
82 case kANGLE_GL_GLContextType:
83 return "angle-gl";
84 #endif
85 #if SK_COMMAND_BUFFER
86 case kCommandBuffer_GLContextType:
87 return "commandbuffer";
88 #endif
89 #if SK_MESA
90 case kMESA_GLContextType:
91 return "mesa";
92 #endif
93 case kNull_GLContextType:
94 return "null";
95 case kDebug_GLContextType:
96 return "debug";
97 default:
98 SkFAIL("Unknown GL Context type.");
99 }
100 }
101
102 explicit GrContextFactory(const GrContextOptions& opts);
103 GrContextFactory();
104
105 ~GrContextFactory();
106
107 void destroyContexts();
108 void abandonContexts();
109
110 struct ContextInfo {
111 ContextInfo()
112 : fGrContext(nullptr), fGLContext(nullptr) { }
113 ContextInfo(GrContext* grContext, SkGLContext* glContext)
114 : fGrContext(grContext), fGLContext(glContext) { }
115 GrContext* fGrContext;
116 SkGLContext* fGLContext; //! Valid until the factory destroys it via aba ndonContexts() or
117 //! destroyContexts().
118 };
119
120 /**
121 * Get a context initialized with a type of GL context. It also makes the GL context current.
122 */
123 ContextInfo getContextInfo(GLContextType type,
124 GLContextOptions options = kNone_GLContextOptions );
125 /**
126 * Get a GrContext initialized with a type of GL context. It also makes the GL context current.
127 */
128 GrContext* get(GLContextType type,
129 GLContextOptions options = kNone_GLContextOptions) {
130 return this->getContextInfo(type, options).fGrContext;
131 }
132 const GrContextOptions& getGlobalOptions() const { return fGlobalOptions; }
133
134 private:
135 struct Context {
136 GLContextType fType;
137 GLContextOptions fOptions;
138 SkGLContext* fGLContext;
139 GrContext* fGrContext;
140 };
141 SkTArray<Context, true> fContexts;
142 const GrContextOptions fGlobalOptions;
143 };
144
145 #endif
OLDNEW
« no previous file with comments | « samplecode/SampleApp.cpp ('k') | src/gpu/GrContextFactory.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698