OLD | NEW |
1 /* | 1 /* |
2 Copyright (C) 2012 Samsung Electronics | 2 Copyright (C) 2012 Samsung Electronics |
3 Copyright (C) 2012 Intel Corporation. All rights reserved. | 3 Copyright (C) 2012 Intel Corporation. All rights reserved. |
4 | 4 |
5 This library is free software; you can redistribute it and/or | 5 This library is free software; you can redistribute it and/or |
6 modify it under the terms of the GNU Library General Public | 6 modify it under the terms of the GNU Library General Public |
7 License as published by the Free Software Foundation; either | 7 License as published by the Free Software Foundation; either |
8 version 2 of the License, or (at your option) any later version. | 8 version 2 of the License, or (at your option) any later version. |
9 | 9 |
10 This library is distributed in the hope that it will be useful, | 10 This library is distributed in the hope that it will be useful, |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 | 61 |
62 if (m_context->m_renderStyle == GraphicsContext3D::RenderOffscreen) { | 62 if (m_context->m_renderStyle == GraphicsContext3D::RenderOffscreen) { |
63 m_offScreenSurface = GLPlatformSurface::createOffScreenSurface(); | 63 m_offScreenSurface = GLPlatformSurface::createOffScreenSurface(); |
64 | 64 |
65 if (!m_offScreenSurface) | 65 if (!m_offScreenSurface) |
66 return false; | 66 return false; |
67 | 67 |
68 if (!m_offScreenContext->initialize(m_offScreenSurface.get())) | 68 if (!m_offScreenContext->initialize(m_offScreenSurface.get())) |
69 return false; | 69 return false; |
70 | 70 |
| 71 #if USE(GRAPHICS_SURFACE) |
71 if (!makeContextCurrent()) | 72 if (!makeContextCurrent()) |
72 return false; | 73 return false; |
73 #if USE(GRAPHICS_SURFACE) | 74 |
74 m_surfaceOperation = CreateSurface; | 75 m_context->validateAttributes(); |
| 76 GLPlatformSurface::SurfaceAttributes sharedSurfaceAttributes = GLPlatfor
mSurface::Default; |
| 77 if (m_context->m_attrs.alpha) |
| 78 sharedSurfaceAttributes = GLPlatformSurface::SupportAlpha; |
| 79 |
| 80 m_offScreenContext->releaseCurrent(); |
| 81 m_sharedSurface = GLPlatformSurface::createTransportSurface(sharedSurfac
eAttributes); |
| 82 if (!m_sharedSurface) |
| 83 return false; |
| 84 |
| 85 m_sharedContext = GLPlatformContext::createContext(m_context->m_renderSt
yle); |
| 86 if (!m_sharedContext) |
| 87 return false; |
| 88 |
| 89 if (!m_sharedContext->initialize(m_sharedSurface.get(), m_offScreenConte
xt->handle())) |
| 90 return false; |
| 91 |
| 92 if (!makeSharedContextCurrent()) |
| 93 return false; |
| 94 |
| 95 m_surfaceHandle = GraphicsSurfaceToken(m_sharedSurface->handle()); |
75 #endif | 96 #endif |
76 } | 97 } |
77 | 98 |
| 99 if (!makeContextCurrent()) |
| 100 return false; |
| 101 |
78 return true; | 102 return true; |
79 } | 103 } |
80 | 104 |
81 GraphicsContext3DPrivate::~GraphicsContext3DPrivate() | 105 GraphicsContext3DPrivate::~GraphicsContext3DPrivate() |
82 { | 106 { |
83 releaseResources(); | 107 releaseResources(); |
84 } | 108 } |
85 | 109 |
86 void GraphicsContext3DPrivate::releaseResources() | 110 void GraphicsContext3DPrivate::releaseResources() |
87 { | 111 { |
88 if (m_context->m_renderStyle == GraphicsContext3D::RenderToCurrentGLContext) | 112 if (m_context->m_renderStyle == GraphicsContext3D::RenderToCurrentGLContext) |
89 return; | 113 return; |
90 | 114 |
91 // Release the current context and drawable only after destroying any associ
ated gl resources. | 115 // Release the current context and drawable only after destroying any associ
ated gl resources. |
92 #if USE(GRAPHICS_SURFACE) | 116 #if USE(GRAPHICS_SURFACE) |
93 if (m_previousGraphicsSurface) | 117 if (m_sharedContext && m_sharedContext->handle() && m_sharedSurface) |
94 m_previousGraphicsSurface = nullptr; | 118 makeSharedContextCurrent(); |
95 | 119 |
96 if (m_graphicsSurface) | 120 if (m_sharedSurface) |
97 m_graphicsSurface = nullptr; | 121 m_sharedSurface->destroy(); |
98 | 122 |
99 m_surfaceHandle = GraphicsSurfaceToken(); | 123 if (m_sharedContext) { |
| 124 m_sharedContext->destroy(); |
| 125 m_sharedContext->releaseCurrent(); |
| 126 } |
100 #endif | 127 #endif |
101 if (m_offScreenSurface) | 128 if (m_offScreenSurface) |
102 m_offScreenSurface->destroy(); | 129 m_offScreenSurface->destroy(); |
103 | 130 |
104 if (m_offScreenContext) { | 131 if (m_offScreenContext) { |
105 m_offScreenContext->destroy(); | 132 m_offScreenContext->destroy(); |
106 m_offScreenContext->releaseCurrent(); | 133 m_offScreenContext->releaseCurrent(); |
107 } | 134 } |
108 } | 135 } |
109 | 136 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 } | 184 } |
158 | 185 |
159 glBindFramebuffer(Extensions3D::READ_FRAMEBUFFER, m_context->m_multisamp
leFBO); | 186 glBindFramebuffer(Extensions3D::READ_FRAMEBUFFER, m_context->m_multisamp
leFBO); |
160 glBindFramebuffer(Extensions3D::DRAW_FRAMEBUFFER, m_context->m_fbo); | 187 glBindFramebuffer(Extensions3D::DRAW_FRAMEBUFFER, m_context->m_fbo); |
161 | 188 |
162 // Use NEAREST as no scale is performed during the blit. | 189 // Use NEAREST as no scale is performed during the blit. |
163 m_context->getExtensions()->blitFramebuffer(0, 0, width, height, 0, 0, w
idth, height, GraphicsContext3D::COLOR_BUFFER_BIT, GraphicsContext3D::NEAREST); | 190 m_context->getExtensions()->blitFramebuffer(0, 0, width, height, 0, 0, w
idth, height, GraphicsContext3D::COLOR_BUFFER_BIT, GraphicsContext3D::NEAREST); |
164 | 191 |
165 if (enableScissorTest) | 192 if (enableScissorTest) |
166 m_context->enable(GraphicsContext3D::SCISSOR_TEST); | 193 m_context->enable(GraphicsContext3D::SCISSOR_TEST); |
167 | |
168 glBindFramebuffer(GL_FRAMEBUFFER, m_context->m_state.boundFBO); | |
169 } | 194 } |
170 | 195 |
171 return true; | 196 return true; |
172 } | 197 } |
173 | 198 |
174 #if USE(TEXTURE_MAPPER_GL) | 199 #if USE(TEXTURE_MAPPER_GL) |
175 void GraphicsContext3DPrivate::paintToTextureMapper(TextureMapper*, const FloatR
ect& /* target */, const TransformationMatrix&, float /* opacity */) | 200 void GraphicsContext3DPrivate::paintToTextureMapper(TextureMapper*, const FloatR
ect& /* target */, const TransformationMatrix&, float /* opacity */) |
176 { | 201 { |
177 notImplemented(); | 202 notImplemented(); |
178 } | 203 } |
179 #endif | 204 #endif |
180 | 205 |
181 #if USE(GRAPHICS_SURFACE) | 206 #if USE(GRAPHICS_SURFACE) |
182 void GraphicsContext3DPrivate::createGraphicsSurface() | 207 bool GraphicsContext3DPrivate::makeSharedContextCurrent() const |
183 { | 208 { |
184 static PendingSurfaceOperation pendingOperation = DeletePreviousSurface | Re
size | CreateSurface; | 209 bool success = m_sharedContext->makeCurrent(m_sharedSurface.get()); |
185 if (!(m_surfaceOperation & pendingOperation)) | |
186 return; | |
187 | 210 |
188 if (m_surfaceOperation & DeletePreviousSurface) { | 211 if (!m_sharedContext->isValid()) { |
189 m_previousGraphicsSurface = nullptr; | 212 // FIXME: Restore context |
190 m_surfaceOperation &= ~DeletePreviousSurface; | 213 if (m_contextLostCallback) |
| 214 m_contextLostCallback->onContextLost(); |
| 215 |
| 216 return false; |
191 } | 217 } |
192 | 218 |
193 if (!(m_surfaceOperation & pendingOperation)) | 219 return success; |
194 return; | |
195 | |
196 // Don't release current graphics surface until we have prepared surface | |
197 // with requested size. This is to avoid flashing during resize. | |
198 if (m_surfaceOperation & Resize) { | |
199 m_previousGraphicsSurface = m_graphicsSurface; | |
200 m_surfaceOperation &= ~Resize; | |
201 m_surfaceOperation |= DeletePreviousSurface; | |
202 m_size = IntSize(m_context->m_currentWidth, m_context->m_currentHeight); | |
203 } else | |
204 m_surfaceOperation &= ~CreateSurface; | |
205 | |
206 m_targetRect = IntRect(IntPoint(), m_size); | |
207 | |
208 if (m_size.isEmpty()) { | |
209 if (m_graphicsSurface) { | |
210 m_graphicsSurface = nullptr; | |
211 m_surfaceHandle = GraphicsSurfaceToken(); | |
212 makeContextCurrent(); | |
213 } | |
214 | |
215 return; | |
216 } | |
217 | |
218 m_offScreenContext->releaseCurrent(); | |
219 GraphicsSurface::Flags flags = GraphicsSurface::SupportsTextureTarget | Grap
hicsSurface::SupportsSharing; | |
220 | |
221 if (m_context->m_attrs.alpha) | |
222 flags |= GraphicsSurface::SupportsAlpha; | |
223 | |
224 m_graphicsSurface = GraphicsSurface::create(m_size, flags, m_offScreenContex
t->handle()); | |
225 | |
226 if (!m_graphicsSurface) | |
227 m_surfaceHandle = GraphicsSurfaceToken(); | |
228 else | |
229 m_surfaceHandle = GraphicsSurfaceToken(m_graphicsSurface->exportToken())
; | |
230 | |
231 makeContextCurrent(); | |
232 } | 220 } |
233 | 221 |
234 void GraphicsContext3DPrivate::didResizeCanvas(const IntSize& size) | 222 void GraphicsContext3DPrivate::didResizeCanvas(const IntSize& size) |
235 { | 223 { |
236 if (m_surfaceOperation & CreateSurface) { | 224 m_size = size; |
237 m_size = size; | |
238 createGraphicsSurface(); | |
239 return; | |
240 } | |
241 | 225 |
242 m_surfaceOperation |= Resize; | 226 if (makeSharedContextCurrent()) |
| 227 m_sharedSurface->setGeometry(IntRect(0, 0, m_size.width(), m_size.height
())); |
243 } | 228 } |
244 | 229 |
245 uint32_t GraphicsContext3DPrivate::copyToGraphicsSurface() | 230 uint32_t GraphicsContext3DPrivate::copyToGraphicsSurface() |
246 { | 231 { |
247 createGraphicsSurface(); | 232 if (m_context->m_layerComposited || !prepareBuffer() || !makeSharedContextCu
rrent()) |
248 | |
249 if (!m_graphicsSurface || m_context->m_layerComposited || !prepareBuffer()) | |
250 return 0; | 233 return 0; |
251 | 234 |
252 m_graphicsSurface->copyFromTexture(m_context->m_texture, m_targetRect); | 235 m_sharedSurface->updateContents(m_context->m_texture); |
253 makeContextCurrent(); | 236 makeContextCurrent(); |
254 | 237 glBindFramebuffer(GL_FRAMEBUFFER, m_context->m_state.boundFBO); |
255 return m_graphicsSurface->frontBuffer(); | 238 return 0; |
256 } | 239 } |
257 | 240 |
258 GraphicsSurfaceToken GraphicsContext3DPrivate::graphicsSurfaceToken() const | 241 GraphicsSurfaceToken GraphicsContext3DPrivate::graphicsSurfaceToken() const |
259 { | 242 { |
260 return m_surfaceHandle; | 243 return m_surfaceHandle; |
261 } | 244 } |
262 | 245 |
263 IntSize GraphicsContext3DPrivate::platformLayerSize() const | 246 IntSize GraphicsContext3DPrivate::platformLayerSize() const |
264 { | 247 { |
265 return m_size; | 248 return m_size; |
266 } | 249 } |
267 #endif | 250 #endif |
268 | 251 |
269 } // namespace WebCore | 252 } // namespace WebCore |
270 | 253 |
271 #endif // USE(3D_GRAPHICS) || USE(ACCELERATED_COMPOSITING) | 254 #endif // USE(3D_GRAPHICS) || USE(ACCELERATED_COMPOSITING) |
OLD | NEW |