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

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

Issue 1346423002: Skia: Add Command Buffer support to Linux/Mac (Closed) Base URL: https://skia.googlesource.com/skia@angle_on_linux
Patch Set: make windows compile Created 5 years, 2 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 | « src/gpu/gl/angle/GrGLCreateANGLEInterface.cpp ('k') | src/ports/SkOSLibrary.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2015 Google Inc. 3 * Copyright 2015 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 #include <EGL/egl.h> 8 #include <EGL/egl.h>
9 9
10 #include "SkOnce.h" 10 #include "SkOnce.h"
11 #include "gl/GrGLInterface.h" 11 #include "gl/GrGLInterface.h"
12 #include "gl/GrGLAssembleInterface.h" 12 #include "gl/GrGLAssembleInterface.h"
13 #include "gl/command_buffer/SkCommandBufferGLContext.h" 13 #include "gl/command_buffer/SkCommandBufferGLContext.h"
14 #include "../ports/SkOSLibrary.h"
14 15
15 typedef EGLDisplay (*GetDisplayProc)(EGLNativeDisplayType display_id); 16 typedef EGLDisplay (*GetDisplayProc)(EGLNativeDisplayType display_id);
16 typedef EGLBoolean (*InitializeProc)(EGLDisplay dpy, EGLint *major, EGLint *mino r); 17 typedef EGLBoolean (*InitializeProc)(EGLDisplay dpy, EGLint *major, EGLint *mino r);
17 typedef EGLBoolean (*TerminateProc)(EGLDisplay dpy); 18 typedef EGLBoolean (*TerminateProc)(EGLDisplay dpy);
18 typedef EGLBoolean (*ChooseConfigProc)(EGLDisplay dpy, const EGLint* attrib_list , EGLConfig* configs, EGLint config_size, EGLint* num_config); 19 typedef EGLBoolean (*ChooseConfigProc)(EGLDisplay dpy, const EGLint* attrib_list , EGLConfig* configs, EGLint config_size, EGLint* num_config);
19 typedef EGLBoolean (*GetConfigAttrib)(EGLDisplay dpy, EGLConfig config, EGLint a ttribute, EGLint* value); 20 typedef EGLBoolean (*GetConfigAttrib)(EGLDisplay dpy, EGLConfig config, EGLint a ttribute, EGLint* value);
20 typedef EGLSurface (*CreateWindowSurfaceProc)(EGLDisplay dpy, EGLConfig config, EGLNativeWindowType win, const EGLint* attrib_list); 21 typedef EGLSurface (*CreateWindowSurfaceProc)(EGLDisplay dpy, EGLConfig config, EGLNativeWindowType win, const EGLint* attrib_list);
21 typedef EGLSurface (*CreatePbufferSurfaceProc)(EGLDisplay dpy, EGLConfig config, const EGLint* attrib_list); 22 typedef EGLSurface (*CreatePbufferSurfaceProc)(EGLDisplay dpy, EGLConfig config, const EGLint* attrib_list);
22 typedef EGLBoolean (*DestroySurfaceProc)(EGLDisplay dpy, EGLSurface surface); 23 typedef EGLBoolean (*DestroySurfaceProc)(EGLDisplay dpy, EGLSurface surface);
23 typedef EGLContext (*CreateContextProc)(EGLDisplay dpy, EGLConfig config, EGLCon text share_context, const EGLint* attrib_list); 24 typedef EGLContext (*CreateContextProc)(EGLDisplay dpy, EGLConfig config, EGLCon text share_context, const EGLint* attrib_list);
24 typedef EGLBoolean (*DestroyContextProc)(EGLDisplay dpy, EGLContext ctx); 25 typedef EGLBoolean (*DestroyContextProc)(EGLDisplay dpy, EGLContext ctx);
25 typedef EGLBoolean (*MakeCurrentProc)(EGLDisplay dpy, EGLSurface draw, EGLSurfac e read, EGLContext ctx); 26 typedef EGLBoolean (*MakeCurrentProc)(EGLDisplay dpy, EGLSurface draw, EGLSurfac e read, EGLContext ctx);
26 typedef EGLBoolean (*SwapBuffersProc)(EGLDisplay dpy, EGLSurface surface); 27 typedef EGLBoolean (*SwapBuffersProc)(EGLDisplay dpy, EGLSurface surface);
27 typedef __eglMustCastToProperFunctionPointerType (*GetProcAddressProc)(const cha r* procname); 28 typedef __eglMustCastToProperFunctionPointerType (*GetProcAddressProc)(const cha r* procname);
28 29
29 static GetDisplayProc gfGetDisplay = nullptr; 30 static GetDisplayProc gfGetDisplay = nullptr;
30 static InitializeProc gfInitialize = nullptr; 31 static InitializeProc gfInitialize = nullptr;
31 static TerminateProc gfTerminate = nullptr; 32 static TerminateProc gfTerminate = nullptr;
32 static ChooseConfigProc gfChooseConfig = nullptr; 33 static ChooseConfigProc gfChooseConfig = nullptr;
33 static GetConfigAttrib gfGetConfigAttrib = nullptr; 34 static GetConfigAttrib gfGetConfigAttrib = nullptr;
34 static CreateWindowSurfaceProc gfCreateWindowSurface = nullptr; 35 static CreateWindowSurfaceProc gfCreateWindowSurface = nullptr;
35 static CreatePbufferSurfaceProc gfCreatePbufferSurface = nullptr; 36 static CreatePbufferSurfaceProc gfCreatePbufferSurface = nullptr;
36 static DestroySurfaceProc gfDestroySurface = nullptr; 37 static DestroySurfaceProc gfDestroySurface = nullptr;
37 static CreateContextProc gfCreateContext = nullptr; 38 static CreateContextProc gfCreateContext = nullptr;
38 static DestroyContextProc gfDestroyContext = nullptr; 39 static DestroyContextProc gfDestroyContext = nullptr;
39 static MakeCurrentProc gfMakeCurrent = nullptr; 40 static MakeCurrentProc gfMakeCurrent = nullptr;
40 static SwapBuffersProc gfSwapBuffers = nullptr; 41 static SwapBuffersProc gfSwapBuffers = nullptr;
41 static GetProcAddressProc gfGetProcAddress = nullptr; 42 static GetProcAddressProc gfGetProcAddress = nullptr;
42 43
43 static HMODULE ghLibrary = nullptr; 44 static void* gLibrary = nullptr;
44 static bool gfFunctionsLoadedSuccessfully = false; 45 static bool gfFunctionsLoadedSuccessfully = false;
45 46
46 static void load_command_buffer_functions() { 47 static void load_command_buffer_functions() {
47 if (!ghLibrary) { 48 if (!gLibrary) {
48 ghLibrary = LoadLibrary("command_buffer_gles2.dll"); 49 #if defined _WIN32
49 50 gLibrary = DynamicLoadLibrary("command_buffer_gles2.dll");
50 if (ghLibrary) { 51 #else
51 gfGetDisplay = (GetDisplayProc)::GetProcAddress(ghLibrary, "eglGetDi splay"); 52 gLibrary = DynamicLoadLibrary("libcommand_buffer_gles2.so");
52 gfInitialize = (InitializeProc)::GetProcAddress(ghLibrary, "eglIniti alize"); 53 #endif // defined _WIN32
53 gfTerminate = (TerminateProc)::GetProcAddress(ghLibrary, "eglTermina te"); 54 if (gLibrary) {
54 gfChooseConfig = (ChooseConfigProc)::GetProcAddress(ghLibrary, "eglC hooseConfig"); 55 gfGetDisplay = (GetDisplayProc)GetProcedureAddress(gLibrary, "eglGet Display");
55 gfGetConfigAttrib = (GetConfigAttrib)::GetProcAddress(ghLibrary, "eg lGetConfigAttrib"); 56 gfInitialize = (InitializeProc)GetProcedureAddress(gLibrary, "eglIni tialize");
56 gfCreateWindowSurface = (CreateWindowSurfaceProc)::GetProcAddress(gh Library, "eglCreateWindowSurface"); 57 gfTerminate = (TerminateProc)GetProcedureAddress(gLibrary, "eglTermi nate");
57 gfCreatePbufferSurface = (CreatePbufferSurfaceProc)::GetProcAddress( ghLibrary, "eglCreatePbufferSurface"); 58 gfChooseConfig = (ChooseConfigProc)GetProcedureAddress(gLibrary, "eg lChooseConfig");
58 gfDestroySurface = (DestroySurfaceProc)::GetProcAddress(ghLibrary, " eglDestroySurface"); 59 gfGetConfigAttrib = (GetConfigAttrib)GetProcedureAddress(gLibrary, " eglGetConfigAttrib");
59 gfCreateContext = (CreateContextProc)::GetProcAddress(ghLibrary, "eg lCreateContext"); 60 gfCreateWindowSurface = (CreateWindowSurfaceProc)GetProcedureAddress (gLibrary, "eglCreateWindowSurface");
60 gfDestroyContext = (DestroyContextProc)::GetProcAddress(ghLibrary, " eglDestroyContext"); 61 gfCreatePbufferSurface = (CreatePbufferSurfaceProc)GetProcedureAddre ss(gLibrary, "eglCreatePbufferSurface");
61 gfMakeCurrent = (MakeCurrentProc)::GetProcAddress(ghLibrary, "eglMak eCurrent"); 62 gfDestroySurface = (DestroySurfaceProc)GetProcedureAddress(gLibrary, "eglDestroySurface");
62 gfSwapBuffers = (SwapBuffersProc)::GetProcAddress(ghLibrary, "eglSwa pBuffers"); 63 gfCreateContext = (CreateContextProc)GetProcedureAddress(gLibrary, " eglCreateContext");
63 gfGetProcAddress = (GetProcAddressProc)::GetProcAddress(ghLibrary, " eglGetProcAddress"); 64 gfDestroyContext = (DestroyContextProc)GetProcedureAddress(gLibrary, "eglDestroyContext");
65 gfMakeCurrent = (MakeCurrentProc)GetProcedureAddress(gLibrary, "eglM akeCurrent");
66 gfSwapBuffers = (SwapBuffersProc)GetProcedureAddress(gLibrary, "eglS wapBuffers");
67 gfGetProcAddress = (GetProcAddressProc)GetProcedureAddress(gLibrary, "eglGetProcAddress");
64 68
65 gfFunctionsLoadedSuccessfully = gfGetDisplay && gfInitialize && gfTe rminate && 69 gfFunctionsLoadedSuccessfully = gfGetDisplay && gfInitialize && gfTe rminate &&
66 gfChooseConfig && gfCreateWindowSurf ace && 70 gfChooseConfig && gfCreateWindowSurf ace &&
67 gfCreatePbufferSurface && gfDestroyS urface && 71 gfCreatePbufferSurface && gfDestroyS urface &&
68 gfCreateContext && gfDestroyContext && gfMakeCurrent && 72 gfCreateContext && gfDestroyContext && gfMakeCurrent &&
69 gfSwapBuffers && gfGetProcAddress; 73 gfSwapBuffers && gfGetProcAddress;
70 74
71 } 75 }
72 } 76 }
73 } 77 }
74 78
75 static GrGLFuncPtr command_buffer_get_gl_proc(void* ctx, const char name[]) { 79 static GrGLFuncPtr command_buffer_get_gl_proc(void* ctx, const char name[]) {
76 GrGLFuncPtr proc = (GrGLFuncPtr) GetProcAddress((HMODULE)ctx, name); 80 GrGLFuncPtr proc = (GrGLFuncPtr) GetProcedureAddress(ctx, name);
77 if (proc) { 81 if (proc) {
78 return proc; 82 return proc;
79 } 83 }
80 if (!gfFunctionsLoadedSuccessfully) { 84 if (!gfFunctionsLoadedSuccessfully) {
81 return nullptr; 85 return nullptr;
82 } 86 }
83 return gfGetProcAddress(name); 87 return gfGetProcAddress(name);
84 } 88 }
85 89
86 SK_DECLARE_STATIC_ONCE(loadCommandBufferOnce); 90 SK_DECLARE_STATIC_ONCE(loadCommandBufferOnce);
87 void LoadCommandBufferOnce() { 91 void LoadCommandBufferOnce() {
88 SkOnce(&loadCommandBufferOnce, load_command_buffer_functions); 92 SkOnce(&loadCommandBufferOnce, load_command_buffer_functions);
89 } 93 }
90 94
91 const GrGLInterface* GrGLCreateCommandBufferInterface() { 95 const GrGLInterface* GrGLCreateCommandBufferInterface() {
92 LoadCommandBufferOnce(); 96 LoadCommandBufferOnce();
93 if (!gfFunctionsLoadedSuccessfully) { 97 if (!gfFunctionsLoadedSuccessfully) {
94 return nullptr; 98 return nullptr;
95 } 99 }
96 return GrGLAssembleGLESInterface(ghLibrary, command_buffer_get_gl_proc); 100 return GrGLAssembleGLESInterface(gLibrary, command_buffer_get_gl_proc);
97 } 101 }
98 102
99 SkCommandBufferGLContext::SkCommandBufferGLContext() 103 SkCommandBufferGLContext::SkCommandBufferGLContext()
100 : fContext(EGL_NO_CONTEXT) 104 : fContext(EGL_NO_CONTEXT)
101 , fDisplay(EGL_NO_DISPLAY) 105 , fDisplay(EGL_NO_DISPLAY)
102 , fSurface(EGL_NO_SURFACE) { 106 , fSurface(EGL_NO_SURFACE) {
103 107
104 static const EGLint configAttribs[] = { 108 static const EGLint configAttribs[] = {
105 EGL_SURFACE_TYPE, EGL_PBUFFER_BIT, 109 EGL_SURFACE_TYPE, EGL_PBUFFER_BIT,
106 EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, 110 EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 gfGetConfigAttrib(fDisplay, surfaceConfig, EGL_STENCIL_SIZE, &result); 266 gfGetConfigAttrib(fDisplay, surfaceConfig, EGL_STENCIL_SIZE, &result);
263 return result; 267 return result;
264 } 268 }
265 269
266 int SkCommandBufferGLContext::getSampleCount() { 270 int SkCommandBufferGLContext::getSampleCount() {
267 EGLint result = 0; 271 EGLint result = 0;
268 EGLConfig surfaceConfig = static_cast<EGLConfig>(fConfig); 272 EGLConfig surfaceConfig = static_cast<EGLConfig>(fConfig);
269 gfGetConfigAttrib(fDisplay, surfaceConfig, EGL_SAMPLES, &result); 273 gfGetConfigAttrib(fDisplay, surfaceConfig, EGL_SAMPLES, &result);
270 return result; 274 return result;
271 } 275 }
OLDNEW
« no previous file with comments | « src/gpu/gl/angle/GrGLCreateANGLEInterface.cpp ('k') | src/ports/SkOSLibrary.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698