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

Side by Side Diff: src/gpu/gl/command_buffer/SkCommandBufferGLContext.cpp

Issue 1306823003: skia: add ability to load command_buffer_gles2 (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: delete the display Created 5 years, 3 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
(Empty)
1
2 /*
3 * Copyright 2015 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
8 #include <EGL/egl.h>
9
10 #include "gl/GrGLInterface.h"
11 #include "gl/GrGLAssembleInterface.h"
12 #include "gl/command_buffer/SkCommandBufferGLContext.h"
13
14 typedef EGLDisplay (*GetDisplayProc)(EGLNativeDisplayType display_id);
15 typedef EGLBoolean (*InitializeProc)(EGLDisplay dpy, EGLint *major, EGLint *mino r);
16 typedef EGLBoolean (*TerminateProc)(EGLDisplay dpy);
17 typedef EGLBoolean (*ChooseConfigProc)(EGLDisplay dpy, const EGLint* attrib_list , EGLConfig* configs, EGLint config_size, EGLint* num_config);
18 typedef EGLSurface (*CreateWindowSurfaceProc)(EGLDisplay dpy, EGLConfig config, EGLNativeWindowType win, const EGLint* attrib_list);
19 typedef EGLSurface (*CreatePbufferSurfaceProc)(EGLDisplay dpy, EGLConfig config, const EGLint* attrib_list);
20 typedef EGLBoolean (*DestroySurfaceProc)(EGLDisplay dpy, EGLSurface surface);
21 typedef EGLContext (*CreateContextProc)(EGLDisplay dpy, EGLConfig config, EGLCon text share_context, const EGLint* attrib_list);
22 typedef EGLBoolean (*DestroyContextProc)(EGLDisplay dpy, EGLContext ctx);
23 typedef EGLBoolean (*MakeCurrentProc)(EGLDisplay dpy, EGLSurface draw, EGLSurfac e read, EGLContext ctx);
24 typedef EGLBoolean (*SwapBuffersProc)(EGLDisplay dpy, EGLSurface surface);
25 typedef __eglMustCastToProperFunctionPointerType (*GetProcAddressProc)(const cha r* procname);
26
27 static GetDisplayProc gfGetDisplay = nullptr;
28 static InitializeProc gfInitialize = nullptr;
29 static TerminateProc gfTerminate = nullptr;
30 static ChooseConfigProc gfChooseConfig = nullptr;
31 static CreateWindowSurfaceProc gfCreateWindowSurface = nullptr;
32 static CreatePbufferSurfaceProc gfCreatePbufferSurface = nullptr;
33 static DestroySurfaceProc gfDestroySurface = nullptr;
34 static CreateContextProc gfCreateContext = nullptr;
35 static DestroyContextProc gfDestroyContext = nullptr;
36 static MakeCurrentProc gfMakeCurrent = nullptr;
37 static SwapBuffersProc gfSwapBuffers = nullptr;
38 static GetProcAddressProc gfGetProcAddress = nullptr;
39
40 static HMODULE ghLibrary = nullptr;
bsalomon 2015/08/26 18:19:55 Should we use SkONCE here for thread safety?
hendrikw 2015/08/27 01:28:35 Done.
41 static bool gfFunctionsLoadedSuccessfully = false;
42
43 static bool LoadCommandBufferFunctions()
44 {
45 if (!ghLibrary) {
46 ghLibrary = LoadLibrary("command_buffer_gles2.dll");
47
48 if (ghLibrary) {
49 gfGetDisplay = (GetDisplayProc)::GetProcAddress(ghLibrary, "CommandB uffer_GetDisplay");
50 gfInitialize = (InitializeProc)::GetProcAddress(ghLibrary, "CommandB uffer_Initialize");
51 gfTerminate = (TerminateProc)::GetProcAddress(ghLibrary, "CommandBuf fer_Terminate");
52 gfChooseConfig = (ChooseConfigProc)::GetProcAddress(ghLibrary, "Comm andBuffer_ChooseConfig");
53 gfCreateWindowSurface = (CreateWindowSurfaceProc)::GetProcAddress(gh Library, "CommandBuffer_CreateWindowSurface");
54 gfCreatePbufferSurface = (CreatePbufferSurfaceProc)::GetProcAddress( ghLibrary, "CommandBuffer_CreatePbufferSurface");
55 gfDestroySurface = (DestroySurfaceProc)::GetProcAddress(ghLibrary, " CommandBuffer_DestroySurface");
56 gfCreateContext = (CreateContextProc)::GetProcAddress(ghLibrary, "Co mmandBuffer_CreateContext");
57 gfDestroyContext = (DestroyContextProc)::GetProcAddress(ghLibrary, " CommandBuffer_DestroyContext");
58 gfMakeCurrent = (MakeCurrentProc)::GetProcAddress(ghLibrary, "Comman dBuffer_MakeCurrent");
59 gfSwapBuffers = (SwapBuffersProc)::GetProcAddress(ghLibrary, "Comman dBuffer_SwapBuffers");
60 gfGetProcAddress = (GetProcAddressProc)::GetProcAddress(ghLibrary, " CommandBuffer_GetProcAddress");
61
62 gfFunctionsLoadedSuccessfully = gfGetDisplay && gfInitialize && gfTe rminate &&
63 gfChooseConfig && gfCreateWindowSurf ace &&
64 gfCreatePbufferSurface && gfDestroyS urface &&
65 gfCreateContext && gfDestroyContext && gfMakeCurrent &&
66 gfSwapBuffers && gfGetProcAddress;
67
68 }
69 }
70 return gfFunctionsLoadedSuccessfully;
71 }
72
73 static GrGLFuncPtr command_buffer_get_gl_proc(void* ctx, const char name[]) {
74 GrGLFuncPtr proc = (GrGLFuncPtr) GetProcAddress((HMODULE)ctx, name);
75 if (proc) {
76 return proc;
77 }
78 if (!gfFunctionsLoadedSuccessfully)
79 return nullptr;
80 return gfGetProcAddress(name);
81 }
82
83 const GrGLInterface* GrGLCreateCommandBufferInterface() {
84 if (!LoadCommandBufferFunctions())
85 return nullptr;
86 return GrGLAssembleGLESInterface(ghLibrary, command_buffer_get_gl_proc);
87 }
88
89 SkCommandBufferGLContext::SkCommandBufferGLContext()
90 : fContext(EGL_NO_CONTEXT)
91 , fDisplay(EGL_NO_DISPLAY)
92 , fSurface(EGL_NO_SURFACE) {
93
94 if (!LoadCommandBufferFunctions())
95 return;
96
97 EGLint numConfigs;
98 static const EGLint configAttribs[] = {
99 EGL_SURFACE_TYPE, EGL_PBUFFER_BIT,
100 EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
101 EGL_RED_SIZE, 8,
102 EGL_GREEN_SIZE, 8,
103 EGL_BLUE_SIZE, 8,
104 EGL_ALPHA_SIZE, 8,
105 EGL_NONE
106 };
107
108 fDisplay = gfGetDisplay(static_cast<EGLNativeDisplayType>(EGL_DEFAULT_DISPLA Y));
109 if (EGL_NO_DISPLAY == fDisplay) {
110 SkDebugf("Could not create EGL display!");
111 return;
112 }
113
114 EGLint majorVersion;
115 EGLint minorVersion;
116 gfInitialize(fDisplay, &majorVersion, &minorVersion);
117
118 EGLConfig surfaceConfig;
119 gfChooseConfig(fDisplay, configAttribs, &surfaceConfig, 1, &numConfigs);
120
121 static const EGLint surfaceAttribs[] = {
122 EGL_WIDTH, 1,
123 EGL_HEIGHT, 1,
124 EGL_NONE
125 };
126
127 fSurface = gfCreatePbufferSurface(fDisplay, surfaceConfig, surfaceAttribs);
128
129 static const EGLint contextAttribs[] = {
130 EGL_CONTEXT_CLIENT_VERSION, 2,
131 EGL_NONE
132 };
133 fContext = gfCreateContext(fDisplay, surfaceConfig, NULL, contextAttribs);
134
135 gfMakeCurrent(fDisplay, fSurface, fSurface, fContext);
136
137 SkAutoTUnref<const GrGLInterface> gl(GrGLCreateCommandBufferInterface());
138 if (NULL == gl.get()) {
139 SkDebugf("Could not create CommandBuffer GL interface!\n");
140 this->destroyGLContext();
141 return;
142 }
143 if (!gl->validate()) {
144 SkDebugf("Could not validate CommandBuffer GL interface!\n");
145 this->destroyGLContext();
146 return;
147 }
148
149 this->init(gl.detach());
150 }
151
152 SkCommandBufferGLContext::~SkCommandBufferGLContext() {
153 this->teardown();
154 this->destroyGLContext();
155 }
156
157 void SkCommandBufferGLContext::destroyGLContext() {
158 if (!gfFunctionsLoadedSuccessfully)
bsalomon 2015/08/26 18:19:55 style nit, {} and 4 space indent
hendrikw 2015/08/27 01:28:35 Done.
159 return;
160 if (fDisplay) {
161 gfMakeCurrent(fDisplay, 0, 0, 0);
162
163 if (fContext) {
164 gfDestroyContext(fDisplay, fContext);
165 fContext = EGL_NO_CONTEXT;
166 }
167
168 if (fSurface) {
169 gfDestroySurface(fDisplay, fSurface);
170 fSurface = EGL_NO_SURFACE;
171 }
172
173 gfTerminate(fDisplay);
174 fDisplay = EGL_NO_DISPLAY;
175 }
176 }
177
178 void SkCommandBufferGLContext::onPlatformMakeCurrent() const {
179 if (!gfFunctionsLoadedSuccessfully)
bsalomon 2015/08/26 18:19:55 {}/4
hendrikw 2015/08/27 01:28:35 Done.
180 return;
181 if (!gfMakeCurrent(fDisplay, fSurface, fSurface, fContext)) {
182 SkDebugf("Could not set the context.\n");
183 }
184 }
185
186 void SkCommandBufferGLContext::onPlatformSwapBuffers() const {
187 if (!gfFunctionsLoadedSuccessfully)
bsalomon 2015/08/26 18:19:55 {}/4
hendrikw 2015/08/27 01:28:35 Done.
188 return;
189 if (!gfSwapBuffers(fDisplay, fSurface)) {
190 SkDebugf("Could not complete gfSwapBuffers.\n");
191 }
192 }
193
194 GrGLFuncPtr SkCommandBufferGLContext::onPlatformGetProcAddress(const char* name) const {
195 if (!gfFunctionsLoadedSuccessfully)
bsalomon 2015/08/26 18:19:55 {}/4
hendrikw 2015/08/27 01:28:35 Done.
196 return nullptr;
197 return gfGetProcAddress(name);
198 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698