OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2012 Google Inc. | 3 * Copyright 2012 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 | 8 |
9 #include "gl/angle/SkANGLEGLContext.h" | 9 #include "gl/angle/SkANGLEGLContext.h" |
10 | 10 |
11 #include <EGL/egl.h> | 11 #include <EGL/egl.h> |
12 #include <EGL/eglext.h> | 12 #include <EGL/eglext.h> |
13 | 13 |
14 #include "gl/GrGLDefines.h" | |
15 #include "gl/GrGLUtil.h" | |
16 | |
17 #define EGL_PLATFORM_ANGLE_ANGLE 0x3202 | 14 #define EGL_PLATFORM_ANGLE_ANGLE 0x3202 |
18 #define EGL_PLATFORM_ANGLE_TYPE_ANGLE 0x3203 | 15 #define EGL_PLATFORM_ANGLE_TYPE_ANGLE 0x3203 |
19 #define EGL_PLATFORM_ANGLE_TYPE_D3D9_ANGLE 0x3207 | 16 #define EGL_PLATFORM_ANGLE_TYPE_D3D9_ANGLE 0x3207 |
20 #define EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE 0x3208 | 17 #define EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE 0x3208 |
21 #define EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE 0x320D | 18 #define EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE 0x320D |
22 | 19 |
23 void* SkANGLEGLContext::GetD3DEGLDisplay(void* nativeDisplay, bool useGLBackend)
{ | 20 void* SkANGLEGLContext::GetD3DEGLDisplay(void* nativeDisplay, bool useGLBackend)
{ |
24 PFNEGLGETPLATFORMDISPLAYEXTPROC eglGetPlatformDisplayEXT; | 21 PFNEGLGETPLATFORMDISPLAYEXTPROC eglGetPlatformDisplayEXT; |
25 eglGetPlatformDisplayEXT = | 22 eglGetPlatformDisplayEXT = |
26 (PFNEGLGETPLATFORMDISPLAYEXTPROC)eglGetProcAddress("eglGetPlatformDispla
yEXT"); | 23 (PFNEGLGETPLATFORMDISPLAYEXTPROC)eglGetProcAddress("eglGetPlatformDispla
yEXT"); |
27 | 24 |
28 if (!eglGetPlatformDisplayEXT) { | 25 if (!eglGetPlatformDisplayEXT) { |
29 return eglGetDisplay(static_cast<EGLNativeDisplayType>(nativeDisplay)); | 26 return eglGetDisplay(static_cast<EGLNativeDisplayType>(nativeDisplay)); |
30 } | 27 } |
31 | 28 |
32 EGLDisplay display = EGL_NO_DISPLAY; | 29 EGLDisplay display = EGL_NO_DISPLAY; |
33 if (useGLBackend) { | 30 if (useGLBackend) { |
34 // Try for an ANGLE D3D11 context, fall back to D3D9. | 31 // Try for an ANGLE D3D11 context, fall back to D3D9. |
35 EGLint attribs[3] = { | 32 EGLint attribs[3] = { |
36 EGL_PLATFORM_ANGLE_TYPE_ANGLE, | 33 EGL_PLATFORM_ANGLE_TYPE_ANGLE, |
37 EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE, | 34 EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE, |
38 EGL_NONE | 35 EGL_NONE |
39 }; | 36 }; |
40 display = eglGetPlatformDisplayEXT(EGL_PLATFORM_ANGLE_ANGLE, nativeDispl
ay, attribs); | 37 display = eglGetPlatformDisplayEXT(EGL_PLATFORM_ANGLE_ANGLE, |
| 38 nativeDisplay, attribs); |
41 } else { | 39 } else { |
42 // Try for an ANGLE D3D11 context, fall back to D3D9, and finally GL. | 40 // Try for an ANGLE D3D11 context, fall back to D3D9, and finally GL. |
43 EGLint attribs[3][3] = { | 41 EGLint attribs[3][3] = { |
44 { | 42 { |
45 EGL_PLATFORM_ANGLE_TYPE_ANGLE, | 43 EGL_PLATFORM_ANGLE_TYPE_ANGLE, |
46 EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE, | 44 EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE, |
47 EGL_NONE | 45 EGL_NONE |
48 }, | 46 }, |
49 { | 47 { |
50 EGL_PLATFORM_ANGLE_TYPE_ANGLE, | 48 EGL_PLATFORM_ANGLE_TYPE_ANGLE, |
51 EGL_PLATFORM_ANGLE_TYPE_D3D9_ANGLE, | 49 EGL_PLATFORM_ANGLE_TYPE_D3D9_ANGLE, |
52 EGL_NONE | 50 EGL_NONE |
53 }, | 51 }, |
54 { | 52 { |
55 EGL_PLATFORM_ANGLE_TYPE_ANGLE, | 53 EGL_PLATFORM_ANGLE_TYPE_ANGLE, |
56 EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE, | 54 EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE, |
57 EGL_NONE | 55 EGL_NONE |
58 } | 56 } |
59 }; | 57 }; |
60 for (int i = 0; i < 3 && display == EGL_NO_DISPLAY; ++i) { | 58 for (int i = 0; i < 3 && display == EGL_NO_DISPLAY; ++i) { |
61 display = eglGetPlatformDisplayEXT(EGL_PLATFORM_ANGLE_ANGLE,nativeDi
splay, attribs[i]); | 59 display = eglGetPlatformDisplayEXT(EGL_PLATFORM_ANGLE_ANGLE, |
| 60 nativeDisplay, attribs[i]); |
62 } | 61 } |
63 } | 62 } |
64 return display; | 63 return display; |
65 } | 64 } |
66 | 65 |
67 SkANGLEGLContext::SkANGLEGLContext(bool useGLBackend) | 66 SkANGLEGLContext::SkANGLEGLContext(bool useGLBackend) |
68 : fContext(EGL_NO_CONTEXT) | 67 : fContext(EGL_NO_CONTEXT) |
69 , fDisplay(EGL_NO_DISPLAY) | 68 , fDisplay(EGL_NO_DISPLAY) |
70 , fSurface(EGL_NO_SURFACE) { | 69 , fSurface(EGL_NO_SURFACE) { |
71 | 70 |
72 EGLint numConfigs; | 71 EGLint numConfigs; |
73 static const EGLint configAttribs[] = { | 72 static const EGLint configAttribs[] = { |
74 EGL_SURFACE_TYPE, EGL_PBUFFER_BIT, | 73 EGL_SURFACE_TYPE, EGL_PBUFFER_BIT, |
75 EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, | 74 EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, |
76 EGL_RED_SIZE, 8, | 75 EGL_RED_SIZE, 8, |
77 EGL_GREEN_SIZE, 8, | 76 EGL_GREEN_SIZE, 8, |
78 EGL_BLUE_SIZE, 8, | 77 EGL_BLUE_SIZE, 8, |
79 EGL_ALPHA_SIZE, 8, | 78 EGL_ALPHA_SIZE, 8, |
80 EGL_NONE | 79 EGL_NONE |
81 }; | 80 }; |
82 | 81 |
83 fIsGLBackend = useGLBackend; | |
84 fDisplay = GetD3DEGLDisplay(EGL_DEFAULT_DISPLAY, useGLBackend); | 82 fDisplay = GetD3DEGLDisplay(EGL_DEFAULT_DISPLAY, useGLBackend); |
85 if (EGL_NO_DISPLAY == fDisplay) { | 83 if (EGL_NO_DISPLAY == fDisplay) { |
86 SkDebugf("Could not create EGL display!"); | 84 SkDebugf("Could not create EGL display!"); |
87 return; | 85 return; |
88 } | 86 } |
89 | 87 |
90 EGLint majorVersion; | 88 EGLint majorVersion; |
91 EGLint minorVersion; | 89 EGLint minorVersion; |
92 eglInitialize(fDisplay, &majorVersion, &minorVersion); | 90 eglInitialize(fDisplay, &majorVersion, &minorVersion); |
93 | 91 |
(...skipping 30 matching lines...) Expand all Loading... |
124 } | 122 } |
125 | 123 |
126 this->init(gl.detach()); | 124 this->init(gl.detach()); |
127 } | 125 } |
128 | 126 |
129 SkANGLEGLContext::~SkANGLEGLContext() { | 127 SkANGLEGLContext::~SkANGLEGLContext() { |
130 this->teardown(); | 128 this->teardown(); |
131 this->destroyGLContext(); | 129 this->destroyGLContext(); |
132 } | 130 } |
133 | 131 |
134 GrEGLImage SkANGLEGLContext::texture2DToEGLImage(GrGLuint texID) const { | |
135 if (!this->gl()->hasExtension("EGL_KHR_gl_texture_2D_image")) { | |
136 return GR_EGL_NO_IMAGE; | |
137 } | |
138 GrEGLImage img; | |
139 GrEGLint attribs[] = { GR_EGL_GL_TEXTURE_LEVEL, 0, | |
140 GR_EGL_IMAGE_PRESERVED, GR_EGL_TRUE, | |
141 GR_EGL_NONE }; | |
142 // 64 bit cast is to shut Visual C++ up about casting 32 bit value to a poin
ter. | |
143 GrEGLClientBuffer clientBuffer = reinterpret_cast<GrEGLClientBuffer>((uint64
_t)texID); | |
144 GR_GL_CALL_RET(this->gl(), img, | |
145 EGLCreateImage(fDisplay, fContext, GR_EGL_GL_TEXTURE_2D, clie
ntBuffer, | |
146 attribs)); | |
147 return img; | |
148 } | |
149 | |
150 void SkANGLEGLContext::destroyEGLImage(GrEGLImage image) const { | |
151 GR_GL_CALL(this->gl(), EGLDestroyImage(fDisplay, image)); | |
152 } | |
153 | |
154 GrGLuint SkANGLEGLContext::eglImageToExternalTexture(GrEGLImage image) const { | |
155 GrGLClearErr(this->gl()); | |
156 if (!this->gl()->hasExtension("GL_OES_EGL_image_external")) { | |
157 return 0; | |
158 } | |
159 GrGLEGLImageTargetTexture2DProc glEGLImageTargetTexture2D = | |
160 (GrGLEGLImageTargetTexture2DProc)eglGetProcAddress("glEGLImageTargetText
ure2DOES"); | |
161 if (!glEGLImageTargetTexture2D) { | |
162 return 0; | |
163 } | |
164 GrGLuint texID; | |
165 GR_GL_CALL(this->gl(), GenTextures(1, &texID)); | |
166 if (!texID) { | |
167 return 0; | |
168 } | |
169 GR_GL_CALL(this->gl(), BindTexture(GR_GL_TEXTURE_EXTERNAL, texID)); | |
170 if (GR_GL_GET_ERROR(this->gl()) != GR_GL_NO_ERROR) { | |
171 GR_GL_CALL(this->gl(), DeleteTextures(1, &texID)); | |
172 return 0; | |
173 } | |
174 glEGLImageTargetTexture2D(GR_GL_TEXTURE_EXTERNAL, image); | |
175 if (GR_GL_GET_ERROR(this->gl()) != GR_GL_NO_ERROR) { | |
176 GR_GL_CALL(this->gl(), DeleteTextures(1, &texID)); | |
177 return 0; | |
178 } | |
179 return texID; | |
180 } | |
181 | |
182 SkGLContext* SkANGLEGLContext::createNew() const { | |
183 SkGLContext* ctx = SkANGLEGLContext::Create(this->gl()->fStandard, fIsGLBack
end); | |
184 if (ctx) { | |
185 ctx->makeCurrent(); | |
186 } | |
187 return ctx; | |
188 } | |
189 | |
190 void SkANGLEGLContext::destroyGLContext() { | 132 void SkANGLEGLContext::destroyGLContext() { |
191 if (fDisplay) { | 133 if (fDisplay) { |
192 eglMakeCurrent(fDisplay, 0, 0, 0); | 134 eglMakeCurrent(fDisplay, 0, 0, 0); |
193 | 135 |
194 if (fContext) { | 136 if (fContext) { |
195 eglDestroyContext(fDisplay, fContext); | 137 eglDestroyContext(fDisplay, fContext); |
196 fContext = EGL_NO_CONTEXT; | 138 fContext = EGL_NO_CONTEXT; |
197 } | 139 } |
198 | 140 |
199 if (fSurface) { | 141 if (fSurface) { |
(...skipping 14 matching lines...) Expand all Loading... |
214 | 156 |
215 void SkANGLEGLContext::onPlatformSwapBuffers() const { | 157 void SkANGLEGLContext::onPlatformSwapBuffers() const { |
216 if (!eglSwapBuffers(fDisplay, fSurface)) { | 158 if (!eglSwapBuffers(fDisplay, fSurface)) { |
217 SkDebugf("Could not complete eglSwapBuffers.\n"); | 159 SkDebugf("Could not complete eglSwapBuffers.\n"); |
218 } | 160 } |
219 } | 161 } |
220 | 162 |
221 GrGLFuncPtr SkANGLEGLContext::onPlatformGetProcAddress(const char* name) const { | 163 GrGLFuncPtr SkANGLEGLContext::onPlatformGetProcAddress(const char* name) const { |
222 return eglGetProcAddress(name); | 164 return eglGetProcAddress(name); |
223 } | 165 } |
OLD | NEW |