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

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

Issue 1845473004: Revert of Move SkGLContext and some GrGLInterface implementations to skgputest module (Closed) Base URL: https://chromium.googlesource.com/skia.git@debugobject
Patch Set: 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 };
57
58 static bool IsRenderingGLContext(GLContextType type) {
59 switch (type) {
60 case kNull_GLContextType:
61 case kDebug_GLContextType:
62 return false;
63 default:
64 return true;
65 }
66 }
67
68 static const char* GLContextTypeName(GLContextType type) {
69 switch (type) {
70 case kNative_GLContextType:
71 return "native";
72 case kGL_GLContextType:
73 return "gl";
74 case kGLES_GLContextType:
75 return "gles";
76 #if SK_ANGLE
77 #ifdef SK_BUILD_FOR_WIN
78 case kANGLE_GLContextType:
79 return "angle";
80 #endif
81 case kANGLE_GL_GLContextType:
82 return "angle-gl";
83 #endif
84 #if SK_COMMAND_BUFFER
85 case kCommandBuffer_GLContextType:
86 return "commandbuffer";
87 #endif
88 #if SK_MESA
89 case kMESA_GLContextType:
90 return "mesa";
91 #endif
92 case kNull_GLContextType:
93 return "null";
94 case kDebug_GLContextType:
95 return "debug";
96 default:
97 SkFAIL("Unknown GL Context type.");
98 }
99 }
100
101 explicit GrContextFactory(const GrContextOptions& opts);
102 GrContextFactory();
103
104 ~GrContextFactory();
105
106 void destroyContexts();
107 void abandonContexts();
108
109 struct ContextInfo {
110 ContextInfo()
111 : fGrContext(nullptr), fGLContext(nullptr) { }
112 ContextInfo(GrContext* grContext, SkGLContext* glContext)
113 : fGrContext(grContext), fGLContext(glContext) { }
114 GrContext* fGrContext;
115 SkGLContext* fGLContext; //! Valid until the factory destroys it via aba ndonContexts() or
116 //! destroyContexts().
117 };
118
119 /**
120 * Get a context initialized with a type of GL context. It also makes the GL context current.
121 */
122 ContextInfo getContextInfo(GLContextType type,
123 GLContextOptions options = kNone_GLContextOptions );
124 /**
125 * Get a GrContext initialized with a type of GL context. It also makes the GL context current.
126 */
127 GrContext* get(GLContextType type,
128 GLContextOptions options = kNone_GLContextOptions) {
129 return this->getContextInfo(type, options).fGrContext;
130 }
131 const GrContextOptions& getGlobalOptions() const { return fGlobalOptions; }
132
133 private:
134 struct Context {
135 GLContextType fType;
136 GLContextOptions fOptions;
137 SkGLContext* fGLContext;
138 GrContext* fGrContext;
139 };
140 SkTArray<Context, true> fContexts;
141 const GrContextOptions fGlobalOptions;
142 };
143
144 #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