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 |
14 #define EGL_PLATFORM_ANGLE_ANGLE 0x3202 | 17 #define EGL_PLATFORM_ANGLE_ANGLE 0x3202 |
15 #define EGL_PLATFORM_ANGLE_TYPE_ANGLE 0x3203 | 18 #define EGL_PLATFORM_ANGLE_TYPE_ANGLE 0x3203 |
16 #define EGL_PLATFORM_ANGLE_TYPE_D3D9_ANGLE 0x3207 | 19 #define EGL_PLATFORM_ANGLE_TYPE_D3D9_ANGLE 0x3207 |
17 #define EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE 0x3208 | 20 #define EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE 0x3208 |
18 #define EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE 0x320D | 21 #define EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE 0x320D |
19 | 22 |
20 void* SkANGLEGLContext::GetD3DEGLDisplay(void* nativeDisplay, bool useGLBackend)
{ | 23 void* SkANGLEGLContext::GetD3DEGLDisplay(void* nativeDisplay, bool useGLBackend)
{ |
21 PFNEGLGETPLATFORMDISPLAYEXTPROC eglGetPlatformDisplayEXT; | 24 PFNEGLGETPLATFORMDISPLAYEXTPROC eglGetPlatformDisplayEXT; |
22 eglGetPlatformDisplayEXT = | 25 eglGetPlatformDisplayEXT = |
23 (PFNEGLGETPLATFORMDISPLAYEXTPROC)eglGetProcAddress("eglGetPlatformDispla
yEXT"); | 26 (PFNEGLGETPLATFORMDISPLAYEXTPROC)eglGetProcAddress("eglGetPlatformDispla
yEXT"); |
24 | 27 |
25 if (!eglGetPlatformDisplayEXT) { | 28 if (!eglGetPlatformDisplayEXT) { |
26 return eglGetDisplay(static_cast<EGLNativeDisplayType>(nativeDisplay)); | 29 return eglGetDisplay(static_cast<EGLNativeDisplayType>(nativeDisplay)); |
27 } | 30 } |
28 | 31 |
29 EGLDisplay display = EGL_NO_DISPLAY; | 32 EGLDisplay display = EGL_NO_DISPLAY; |
30 if (useGLBackend) { | 33 if (useGLBackend) { |
31 // Try for an ANGLE D3D11 context, fall back to D3D9. | 34 // Try for an ANGLE D3D11 context, fall back to D3D9. |
32 EGLint attribs[3] = { | 35 EGLint attribs[3] = { |
33 EGL_PLATFORM_ANGLE_TYPE_ANGLE, | 36 EGL_PLATFORM_ANGLE_TYPE_ANGLE, |
34 EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE, | 37 EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE, |
35 EGL_NONE | 38 EGL_NONE |
36 }; | 39 }; |
37 display = eglGetPlatformDisplayEXT(EGL_PLATFORM_ANGLE_ANGLE, | 40 display = eglGetPlatformDisplayEXT(EGL_PLATFORM_ANGLE_ANGLE, nativeDispl
ay, attribs); |
38 nativeDisplay, attribs); | |
39 } else { | 41 } else { |
40 // Try for an ANGLE D3D11 context, fall back to D3D9, and finally GL. | 42 // Try for an ANGLE D3D11 context, fall back to D3D9, and finally GL. |
41 EGLint attribs[3][3] = { | 43 EGLint attribs[3][3] = { |
42 { | 44 { |
43 EGL_PLATFORM_ANGLE_TYPE_ANGLE, | 45 EGL_PLATFORM_ANGLE_TYPE_ANGLE, |
44 EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE, | 46 EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE, |
45 EGL_NONE | 47 EGL_NONE |
46 }, | 48 }, |
47 { | 49 { |
48 EGL_PLATFORM_ANGLE_TYPE_ANGLE, | 50 EGL_PLATFORM_ANGLE_TYPE_ANGLE, |
49 EGL_PLATFORM_ANGLE_TYPE_D3D9_ANGLE, | 51 EGL_PLATFORM_ANGLE_TYPE_D3D9_ANGLE, |
50 EGL_NONE | 52 EGL_NONE |
51 }, | 53 }, |
52 { | 54 { |
53 EGL_PLATFORM_ANGLE_TYPE_ANGLE, | 55 EGL_PLATFORM_ANGLE_TYPE_ANGLE, |
54 EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE, | 56 EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE, |
55 EGL_NONE | 57 EGL_NONE |
56 } | 58 } |
57 }; | 59 }; |
58 for (int i = 0; i < 3 && display == EGL_NO_DISPLAY; ++i) { | 60 for (int i = 0; i < 3 && display == EGL_NO_DISPLAY; ++i) { |
59 display = eglGetPlatformDisplayEXT(EGL_PLATFORM_ANGLE_ANGLE, | 61 display = eglGetPlatformDisplayEXT(EGL_PLATFORM_ANGLE_ANGLE,nativeDi
splay, attribs[i]); |
60 nativeDisplay, attribs[i]); | |
61 } | 62 } |
62 } | 63 } |
63 return display; | 64 return display; |
64 } | 65 } |
65 | 66 |
66 SkANGLEGLContext::SkANGLEGLContext(bool useGLBackend) | 67 SkANGLEGLContext::SkANGLEGLContext(bool useGLBackend) |
67 : fContext(EGL_NO_CONTEXT) | 68 : fContext(EGL_NO_CONTEXT) |
68 , fDisplay(EGL_NO_DISPLAY) | 69 , fDisplay(EGL_NO_DISPLAY) |
69 , fSurface(EGL_NO_SURFACE) { | 70 , fSurface(EGL_NO_SURFACE) { |
70 | 71 |
71 EGLint numConfigs; | 72 EGLint numConfigs; |
72 static const EGLint configAttribs[] = { | 73 static const EGLint configAttribs[] = { |
73 EGL_SURFACE_TYPE, EGL_PBUFFER_BIT, | 74 EGL_SURFACE_TYPE, EGL_PBUFFER_BIT, |
74 EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, | 75 EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, |
75 EGL_RED_SIZE, 8, | 76 EGL_RED_SIZE, 8, |
76 EGL_GREEN_SIZE, 8, | 77 EGL_GREEN_SIZE, 8, |
77 EGL_BLUE_SIZE, 8, | 78 EGL_BLUE_SIZE, 8, |
78 EGL_ALPHA_SIZE, 8, | 79 EGL_ALPHA_SIZE, 8, |
79 EGL_NONE | 80 EGL_NONE |
80 }; | 81 }; |
81 | 82 |
| 83 fIsGLBackend = useGLBackend; |
82 fDisplay = GetD3DEGLDisplay(EGL_DEFAULT_DISPLAY, useGLBackend); | 84 fDisplay = GetD3DEGLDisplay(EGL_DEFAULT_DISPLAY, useGLBackend); |
83 if (EGL_NO_DISPLAY == fDisplay) { | 85 if (EGL_NO_DISPLAY == fDisplay) { |
84 SkDebugf("Could not create EGL display!"); | 86 SkDebugf("Could not create EGL display!"); |
85 return; | 87 return; |
86 } | 88 } |
87 | 89 |
88 EGLint majorVersion; | 90 EGLint majorVersion; |
89 EGLint minorVersion; | 91 EGLint minorVersion; |
90 eglInitialize(fDisplay, &majorVersion, &minorVersion); | 92 eglInitialize(fDisplay, &majorVersion, &minorVersion); |
91 | 93 |
(...skipping 30 matching lines...) Expand all Loading... |
122 } | 124 } |
123 | 125 |
124 this->init(gl.detach()); | 126 this->init(gl.detach()); |
125 } | 127 } |
126 | 128 |
127 SkANGLEGLContext::~SkANGLEGLContext() { | 129 SkANGLEGLContext::~SkANGLEGLContext() { |
128 this->teardown(); | 130 this->teardown(); |
129 this->destroyGLContext(); | 131 this->destroyGLContext(); |
130 } | 132 } |
131 | 133 |
| 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 |
132 void SkANGLEGLContext::destroyGLContext() { | 190 void SkANGLEGLContext::destroyGLContext() { |
133 if (fDisplay) { | 191 if (fDisplay) { |
134 eglMakeCurrent(fDisplay, 0, 0, 0); | 192 eglMakeCurrent(fDisplay, 0, 0, 0); |
135 | 193 |
136 if (fContext) { | 194 if (fContext) { |
137 eglDestroyContext(fDisplay, fContext); | 195 eglDestroyContext(fDisplay, fContext); |
138 fContext = EGL_NO_CONTEXT; | 196 fContext = EGL_NO_CONTEXT; |
139 } | 197 } |
140 | 198 |
141 if (fSurface) { | 199 if (fSurface) { |
(...skipping 14 matching lines...) Expand all Loading... |
156 | 214 |
157 void SkANGLEGLContext::onPlatformSwapBuffers() const { | 215 void SkANGLEGLContext::onPlatformSwapBuffers() const { |
158 if (!eglSwapBuffers(fDisplay, fSurface)) { | 216 if (!eglSwapBuffers(fDisplay, fSurface)) { |
159 SkDebugf("Could not complete eglSwapBuffers.\n"); | 217 SkDebugf("Could not complete eglSwapBuffers.\n"); |
160 } | 218 } |
161 } | 219 } |
162 | 220 |
163 GrGLFuncPtr SkANGLEGLContext::onPlatformGetProcAddress(const char* name) const { | 221 GrGLFuncPtr SkANGLEGLContext::onPlatformGetProcAddress(const char* name) const { |
164 return eglGetProcAddress(name); | 222 return eglGetProcAddress(name); |
165 } | 223 } |
OLD | NEW |