OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2010, Google Inc. All rights reserved. | 2 * Copyright (c) 2010, Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 m_context->bindTexture(GL_TEXTURE_2D, m_oldTextureUnitZeroId); | 71 m_context->bindTexture(GL_TEXTURE_2D, m_oldTextureUnitZeroId); |
72 m_context->activeTexture(m_oldActiveTextureUnit); | 72 m_context->activeTexture(m_oldActiveTextureUnit); |
73 } | 73 } |
74 | 74 |
75 private: | 75 private: |
76 blink::WebGraphicsContext3D* m_context; | 76 blink::WebGraphicsContext3D* m_context; |
77 GLenum m_oldActiveTextureUnit; | 77 GLenum m_oldActiveTextureUnit; |
78 Platform3DObject m_oldTextureUnitZeroId; | 78 Platform3DObject m_oldTextureUnitZeroId; |
79 }; | 79 }; |
80 | 80 |
81 PassRefPtr<DrawingBuffer> DrawingBuffer::create(blink::WebGraphicsContext3D* con
text, const IntSize& size, PreserveDrawingBuffer preserve, PassRefPtr<ContextEvi
ctionManager> contextEvictionManager) | 81 PassRefPtr<DrawingBuffer> DrawingBuffer::create(PassOwnPtr<blink::WebGraphicsCon
text3D> context, const IntSize& size, PreserveDrawingBuffer preserve, PassRefPtr
<ContextEvictionManager> contextEvictionManager) |
82 { | 82 { |
83 Extensions3DUtil extensionsUtil(context); | 83 ASSERT(context); |
| 84 Extensions3DUtil extensionsUtil(context.get()); |
84 bool multisampleSupported = extensionsUtil.supportsExtension("GL_CHROMIUM_fr
amebuffer_multisample") | 85 bool multisampleSupported = extensionsUtil.supportsExtension("GL_CHROMIUM_fr
amebuffer_multisample") |
85 && extensionsUtil.supportsExtension("GL_OES_rgb8_rgba8"); | 86 && extensionsUtil.supportsExtension("GL_OES_rgb8_rgba8"); |
86 if (multisampleSupported) { | 87 if (multisampleSupported) { |
87 extensionsUtil.ensureExtensionEnabled("GL_CHROMIUM_framebuffer_multisamp
le"); | 88 extensionsUtil.ensureExtensionEnabled("GL_CHROMIUM_framebuffer_multisamp
le"); |
88 extensionsUtil.ensureExtensionEnabled("GL_OES_rgb8_rgba8"); | 89 extensionsUtil.ensureExtensionEnabled("GL_OES_rgb8_rgba8"); |
89 } | 90 } |
90 bool packedDepthStencilSupported = extensionsUtil.supportsExtension("GL_OES_
packed_depth_stencil"); | 91 bool packedDepthStencilSupported = extensionsUtil.supportsExtension("GL_OES_
packed_depth_stencil"); |
91 if (packedDepthStencilSupported) | 92 if (packedDepthStencilSupported) |
92 extensionsUtil.ensureExtensionEnabled("GL_OES_packed_depth_stencil"); | 93 extensionsUtil.ensureExtensionEnabled("GL_OES_packed_depth_stencil"); |
93 | 94 |
94 RefPtr<DrawingBuffer> drawingBuffer = adoptRef(new DrawingBuffer(context, si
ze, multisampleSupported, packedDepthStencilSupported, preserve, contextEviction
Manager)); | 95 RefPtr<DrawingBuffer> drawingBuffer = adoptRef(new DrawingBuffer(context, mu
ltisampleSupported, packedDepthStencilSupported, preserve, contextEvictionManage
r)); |
| 96 if (!drawingBuffer->initialize(size)) |
| 97 return PassRefPtr<DrawingBuffer>(); |
95 return drawingBuffer.release(); | 98 return drawingBuffer.release(); |
96 } | 99 } |
97 | 100 |
98 DrawingBuffer::DrawingBuffer(blink::WebGraphicsContext3D* context, | 101 DrawingBuffer::DrawingBuffer(PassOwnPtr<blink::WebGraphicsContext3D> context, |
99 const IntSize& size, | |
100 bool multisampleExtensionSupported, | 102 bool multisampleExtensionSupported, |
101 bool packedDepthStencilExtensionSupported, | 103 bool packedDepthStencilExtensionSupported, |
102 PreserveDrawingBuffer preserve, | 104 PreserveDrawingBuffer preserve, |
103 PassRefPtr<ContextEvictionManager> contextEvictionManager) | 105 PassRefPtr<ContextEvictionManager> contextEvictionManager) |
104 : m_preserveDrawingBuffer(preserve) | 106 : m_preserveDrawingBuffer(preserve) |
105 , m_scissorEnabled(false) | 107 , m_scissorEnabled(false) |
106 , m_texture2DBinding(0) | 108 , m_texture2DBinding(0) |
107 , m_framebufferBinding(0) | 109 , m_framebufferBinding(0) |
108 , m_activeTextureUnit(GL_TEXTURE0) | 110 , m_activeTextureUnit(GL_TEXTURE0) |
109 , m_context(context) | 111 , m_context(context) |
110 , m_size(-1, -1) | 112 , m_size(-1, -1) |
111 , m_multisampleExtensionSupported(multisampleExtensionSupported) | 113 , m_multisampleExtensionSupported(multisampleExtensionSupported) |
112 , m_packedDepthStencilExtensionSupported(packedDepthStencilExtensionSupporte
d) | 114 , m_packedDepthStencilExtensionSupported(packedDepthStencilExtensionSupporte
d) |
113 , m_fbo(0) | 115 , m_fbo(0) |
114 , m_colorBuffer(0) | 116 , m_colorBuffer(0) |
115 , m_frontColorBuffer(0) | 117 , m_frontColorBuffer(0) |
116 , m_depthStencilBuffer(0) | 118 , m_depthStencilBuffer(0) |
117 , m_depthBuffer(0) | 119 , m_depthBuffer(0) |
118 , m_stencilBuffer(0) | 120 , m_stencilBuffer(0) |
119 , m_multisampleFBO(0) | 121 , m_multisampleFBO(0) |
120 , m_multisampleColorBuffer(0) | 122 , m_multisampleColorBuffer(0) |
121 , m_contentsChanged(true) | 123 , m_contentsChanged(true) |
122 , m_contentsChangeCommitted(false) | 124 , m_contentsChangeCommitted(false) |
123 , m_layerComposited(false) | 125 , m_layerComposited(false) |
| 126 , m_multisampleMode(None) |
124 , m_internalColorFormat(0) | 127 , m_internalColorFormat(0) |
125 , m_colorFormat(0) | 128 , m_colorFormat(0) |
126 , m_internalRenderbufferFormat(0) | 129 , m_internalRenderbufferFormat(0) |
127 , m_maxTextureSize(0) | 130 , m_maxTextureSize(0) |
| 131 , m_sampleCount(0) |
128 , m_packAlignment(4) | 132 , m_packAlignment(4) |
129 , m_contextEvictionManager(contextEvictionManager) | 133 , m_contextEvictionManager(contextEvictionManager) |
130 { | 134 { |
131 // Used by browser tests to detect the use of a DrawingBuffer. | 135 // Used by browser tests to detect the use of a DrawingBuffer. |
132 TRACE_EVENT_INSTANT0("test_gpu", "DrawingBufferCreation"); | 136 TRACE_EVENT_INSTANT0("test_gpu", "DrawingBufferCreation"); |
133 initialize(size); | |
134 } | 137 } |
135 | 138 |
136 DrawingBuffer::~DrawingBuffer() | 139 DrawingBuffer::~DrawingBuffer() |
137 { | 140 { |
138 releaseResources(); | 141 releaseResources(); |
139 } | 142 } |
140 | 143 |
141 void DrawingBuffer::markContentsChanged() | 144 void DrawingBuffer::markContentsChanged() |
142 { | 145 { |
143 m_contentsChanged = true; | 146 m_contentsChanged = true; |
144 m_contentsChangeCommitted = false; | 147 m_contentsChangeCommitted = false; |
145 m_layerComposited = false; | 148 m_layerComposited = false; |
146 } | 149 } |
147 | 150 |
148 bool DrawingBuffer::layerComposited() const | 151 bool DrawingBuffer::layerComposited() const |
149 { | 152 { |
150 return m_layerComposited; | 153 return m_layerComposited; |
151 } | 154 } |
152 | 155 |
153 void DrawingBuffer::markLayerComposited() | 156 void DrawingBuffer::markLayerComposited() |
154 { | 157 { |
155 m_layerComposited = true; | 158 m_layerComposited = true; |
156 } | 159 } |
157 | 160 |
158 blink::WebGraphicsContext3D* DrawingBuffer::context() | 161 blink::WebGraphicsContext3D* DrawingBuffer::context() |
159 { | 162 { |
160 return m_context; | 163 return m_context.get(); |
161 } | 164 } |
162 | 165 |
163 bool DrawingBuffer::prepareMailbox(blink::WebExternalTextureMailbox* outMailbox,
blink::WebExternalBitmap* bitmap) | 166 bool DrawingBuffer::prepareMailbox(blink::WebExternalTextureMailbox* outMailbox,
blink::WebExternalBitmap* bitmap) |
164 { | 167 { |
165 if (!m_context || !m_contentsChanged) | 168 if (!m_contentsChanged) |
166 return false; | 169 return false; |
167 | 170 |
168 m_context->makeContextCurrent(); | 171 m_context->makeContextCurrent(); |
169 | 172 |
170 // Resolve the multisampled buffer into m_colorBuffer texture. | 173 // Resolve the multisampled buffer into m_colorBuffer texture. |
171 if (m_multisampleMode != None) | 174 if (m_multisampleMode != None) |
172 commit(); | 175 commit(); |
173 | 176 |
174 if (bitmap) { | 177 if (bitmap) { |
175 bitmap->setSize(size()); | 178 bitmap->setSize(size()); |
176 | 179 |
177 unsigned char* pixels = bitmap->pixels(); | 180 unsigned char* pixels = bitmap->pixels(); |
178 bool needPremultiply = m_attributes.alpha && !m_attributes.premultiplied
Alpha; | 181 bool needPremultiply = m_attributes.alpha && !m_attributes.premultiplied
Alpha; |
179 WebGLImageConversion::AlphaOp op = needPremultiply ? WebGLImageConversio
n::AlphaDoPremultiply : WebGLImageConversion::AlphaDoNothing; | 182 WebGLImageConversion::AlphaOp op = needPremultiply ? WebGLImageConversio
n::AlphaDoPremultiply : WebGLImageConversion::AlphaDoNothing; |
180 if (pixels) | 183 if (pixels) |
181 readBackFramebuffer(pixels, size().width(), size().height(), Readbac
kSkia, op); | 184 readBackFramebuffer(pixels, size().width(), size().height(), Readbac
kSkia, op); |
182 } | 185 } |
183 | 186 |
184 // We must restore the texture binding since creating new textures, | 187 // We must restore the texture binding since creating new textures, |
185 // consuming and producing mailboxes changes it. | 188 // consuming and producing mailboxes changes it. |
186 ScopedTextureUnit0BindingRestorer restorer(m_context, m_activeTextureUnit, m
_texture2DBinding); | 189 ScopedTextureUnit0BindingRestorer restorer(m_context.get(), m_activeTextureU
nit, m_texture2DBinding); |
187 | 190 |
188 // First try to recycle an old buffer. | 191 // First try to recycle an old buffer. |
189 RefPtr<MailboxInfo> frontColorBufferMailbox = recycledMailbox(); | 192 RefPtr<MailboxInfo> frontColorBufferMailbox = recycledMailbox(); |
190 | 193 |
191 // No buffer available to recycle, create a new one. | 194 // No buffer available to recycle, create a new one. |
192 if (!frontColorBufferMailbox) { | 195 if (!frontColorBufferMailbox) { |
193 unsigned newColorBuffer = createColorTexture(m_size); | 196 unsigned newColorBuffer = createColorTexture(m_size); |
194 // Bad things happened, abandon ship. | 197 // Bad things happened, abandon ship. |
195 if (!newColorBuffer) | 198 if (!newColorBuffer) |
196 return false; | 199 return false; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
239 mailboxInfo->mailbox.syncPoint = mailbox.syncPoint; | 242 mailboxInfo->mailbox.syncPoint = mailbox.syncPoint; |
240 m_recycledMailboxes.prepend(mailboxInfo.release()); | 243 m_recycledMailboxes.prepend(mailboxInfo.release()); |
241 return; | 244 return; |
242 } | 245 } |
243 } | 246 } |
244 ASSERT_NOT_REACHED(); | 247 ASSERT_NOT_REACHED(); |
245 } | 248 } |
246 | 249 |
247 PassRefPtr<DrawingBuffer::MailboxInfo> DrawingBuffer::recycledMailbox() | 250 PassRefPtr<DrawingBuffer::MailboxInfo> DrawingBuffer::recycledMailbox() |
248 { | 251 { |
249 if (!m_context || m_recycledMailboxes.isEmpty()) | 252 if (m_recycledMailboxes.isEmpty()) |
250 return PassRefPtr<MailboxInfo>(); | 253 return PassRefPtr<MailboxInfo>(); |
251 | 254 |
252 RefPtr<MailboxInfo> mailboxInfo = m_recycledMailboxes.last().release(); | 255 RefPtr<MailboxInfo> mailboxInfo = m_recycledMailboxes.last().release(); |
253 m_recycledMailboxes.removeLast(); | 256 m_recycledMailboxes.removeLast(); |
254 | 257 |
255 if (mailboxInfo->mailbox.syncPoint) { | 258 if (mailboxInfo->mailbox.syncPoint) { |
256 m_context->waitSyncPoint(mailboxInfo->mailbox.syncPoint); | 259 m_context->waitSyncPoint(mailboxInfo->mailbox.syncPoint); |
257 mailboxInfo->mailbox.syncPoint = 0; | 260 mailboxInfo->mailbox.syncPoint = 0; |
258 } | 261 } |
259 | 262 |
260 if (mailboxInfo->size != m_size) { | 263 if (mailboxInfo->size != m_size) { |
261 m_context->bindTexture(GL_TEXTURE_2D, mailboxInfo->textureId); | 264 m_context->bindTexture(GL_TEXTURE_2D, mailboxInfo->textureId); |
262 texImage2DResourceSafe(GL_TEXTURE_2D, 0, m_internalColorFormat, m_size.w
idth(), m_size.height(), 0, m_colorFormat, GL_UNSIGNED_BYTE); | 265 texImage2DResourceSafe(GL_TEXTURE_2D, 0, m_internalColorFormat, m_size.w
idth(), m_size.height(), 0, m_colorFormat, GL_UNSIGNED_BYTE); |
263 mailboxInfo->size = m_size; | 266 mailboxInfo->size = m_size; |
264 } | 267 } |
265 | 268 |
266 return mailboxInfo.release(); | 269 return mailboxInfo.release(); |
267 } | 270 } |
268 | 271 |
269 PassRefPtr<DrawingBuffer::MailboxInfo> DrawingBuffer::createNewMailbox(unsigned
textureId) | 272 PassRefPtr<DrawingBuffer::MailboxInfo> DrawingBuffer::createNewMailbox(unsigned
textureId) |
270 { | 273 { |
271 RefPtr<MailboxInfo> returnMailbox = adoptRef(new MailboxInfo()); | 274 RefPtr<MailboxInfo> returnMailbox = adoptRef(new MailboxInfo()); |
272 m_context->genMailboxCHROMIUM(returnMailbox->mailbox.name); | 275 m_context->genMailboxCHROMIUM(returnMailbox->mailbox.name); |
273 returnMailbox->textureId = textureId; | 276 returnMailbox->textureId = textureId; |
274 returnMailbox->size = m_size; | 277 returnMailbox->size = m_size; |
275 m_textureMailboxes.append(returnMailbox); | 278 m_textureMailboxes.append(returnMailbox); |
276 return returnMailbox.release(); | 279 return returnMailbox.release(); |
277 } | 280 } |
278 | 281 |
279 void DrawingBuffer::initialize(const IntSize& size) | 282 bool DrawingBuffer::initialize(const IntSize& size) |
280 { | 283 { |
281 ASSERT(m_context); | |
282 m_attributes = m_context->getContextAttributes(); | 284 m_attributes = m_context->getContextAttributes(); |
283 Extensions3DUtil extensionsUtil(m_context); | 285 Extensions3DUtil extensionsUtil(m_context.get()); |
284 | 286 |
285 if (m_attributes.alpha) { | 287 if (m_attributes.alpha) { |
286 m_internalColorFormat = GL_RGBA; | 288 m_internalColorFormat = GL_RGBA; |
287 m_colorFormat = GL_RGBA; | 289 m_colorFormat = GL_RGBA; |
288 m_internalRenderbufferFormat = GL_RGBA8_OES; | 290 m_internalRenderbufferFormat = GL_RGBA8_OES; |
289 } else { | 291 } else { |
290 m_internalColorFormat = GL_RGB; | 292 m_internalColorFormat = GL_RGB; |
291 m_colorFormat = GL_RGB; | 293 m_colorFormat = GL_RGB; |
292 m_internalRenderbufferFormat = GL_RGB8_OES; | 294 m_internalRenderbufferFormat = GL_RGB8_OES; |
293 } | 295 } |
(...skipping 12 matching lines...) Expand all Loading... |
306 | 308 |
307 m_fbo = m_context->createFramebuffer(); | 309 m_fbo = m_context->createFramebuffer(); |
308 | 310 |
309 m_context->bindFramebuffer(GL_FRAMEBUFFER, m_fbo); | 311 m_context->bindFramebuffer(GL_FRAMEBUFFER, m_fbo); |
310 m_colorBuffer = createColorTexture(); | 312 m_colorBuffer = createColorTexture(); |
311 if (m_multisampleMode == ImplicitResolve) | 313 if (m_multisampleMode == ImplicitResolve) |
312 m_context->framebufferTexture2DMultisampleEXT(GL_FRAMEBUFFER, GL_COLOR_A
TTACHMENT0, GL_TEXTURE_2D, m_colorBuffer, 0, m_sampleCount); | 314 m_context->framebufferTexture2DMultisampleEXT(GL_FRAMEBUFFER, GL_COLOR_A
TTACHMENT0, GL_TEXTURE_2D, m_colorBuffer, 0, m_sampleCount); |
313 else | 315 else |
314 m_context->framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL
_TEXTURE_2D, m_colorBuffer, 0); | 316 m_context->framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL
_TEXTURE_2D, m_colorBuffer, 0); |
315 createSecondaryBuffers(); | 317 createSecondaryBuffers(); |
316 reset(size); | 318 return reset(size); |
317 } | 319 } |
318 | 320 |
319 bool DrawingBuffer::copyToPlatformTexture(blink::WebGraphicsContext3D* context,
Platform3DObject texture, GLenum internalFormat, GLenum destType, GLint level, b
ool premultiplyAlpha, bool flipY) | 321 bool DrawingBuffer::copyToPlatformTexture(blink::WebGraphicsContext3D* context,
Platform3DObject texture, GLenum internalFormat, GLenum destType, GLint level, b
ool premultiplyAlpha, bool flipY) |
320 { | 322 { |
321 if (!m_context || !m_context->makeContextCurrent()) | 323 if (!m_context->makeContextCurrent()) |
322 return false; | 324 return false; |
323 if (m_contentsChanged) { | 325 if (m_contentsChanged) { |
324 if (m_multisampleMode != None) { | 326 if (m_multisampleMode != None) { |
325 commit(); | 327 commit(); |
326 if (!m_framebufferBinding) | 328 if (!m_framebufferBinding) |
327 bind(); | 329 bind(); |
328 else | 330 else |
329 restoreFramebufferBinding(); | 331 restoreFramebufferBinding(); |
330 } | 332 } |
331 m_context->flush(); | 333 m_context->flush(); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
381 return true; | 383 return true; |
382 } | 384 } |
383 | 385 |
384 Platform3DObject DrawingBuffer::framebuffer() const | 386 Platform3DObject DrawingBuffer::framebuffer() const |
385 { | 387 { |
386 return m_fbo; | 388 return m_fbo; |
387 } | 389 } |
388 | 390 |
389 blink::WebLayer* DrawingBuffer::platformLayer() | 391 blink::WebLayer* DrawingBuffer::platformLayer() |
390 { | 392 { |
391 if (!m_context) | |
392 return 0; | |
393 | |
394 if (!m_layer) { | 393 if (!m_layer) { |
395 m_layer = adoptPtr(blink::Platform::current()->compositorSupport()->crea
teExternalTextureLayer(this)); | 394 m_layer = adoptPtr(blink::Platform::current()->compositorSupport()->crea
teExternalTextureLayer(this)); |
396 | 395 |
397 m_layer->setOpaque(!m_attributes.alpha); | 396 m_layer->setOpaque(!m_attributes.alpha); |
398 m_layer->setBlendBackgroundColor(m_attributes.alpha); | 397 m_layer->setBlendBackgroundColor(m_attributes.alpha); |
399 m_layer->setPremultipliedAlpha(m_attributes.premultipliedAlpha); | 398 m_layer->setPremultipliedAlpha(m_attributes.premultipliedAlpha); |
400 GraphicsLayer::registerContentsLayer(m_layer->layer()); | 399 GraphicsLayer::registerContentsLayer(m_layer->layer()); |
401 } | 400 } |
402 | 401 |
403 return m_layer->layer(); | 402 return m_layer->layer(); |
404 } | 403 } |
405 | 404 |
406 void DrawingBuffer::paintCompositedResultsToCanvas(ImageBuffer* imageBuffer) | 405 void DrawingBuffer::paintCompositedResultsToCanvas(ImageBuffer* imageBuffer) |
407 { | 406 { |
408 if (!m_context || !m_context->makeContextCurrent() || m_context->getGraphics
ResetStatusARB() != GL_NO_ERROR) | 407 if (!m_context->makeContextCurrent() || m_context->getGraphicsResetStatusARB
() != GL_NO_ERROR) |
409 return; | 408 return; |
410 | 409 |
411 if (!imageBuffer) | 410 if (!imageBuffer) |
412 return; | 411 return; |
413 Platform3DObject tex = imageBuffer->getBackingTexture(); | 412 Platform3DObject tex = imageBuffer->getBackingTexture(); |
414 if (tex) { | 413 if (tex) { |
415 RefPtr<MailboxInfo> bufferMailbox = adoptRef(new MailboxInfo()); | 414 RefPtr<MailboxInfo> bufferMailbox = adoptRef(new MailboxInfo()); |
416 m_context->genMailboxCHROMIUM(bufferMailbox->mailbox.name); | 415 m_context->genMailboxCHROMIUM(bufferMailbox->mailbox.name); |
417 m_context->bindTexture(GL_TEXTURE_2D, m_frontColorBuffer); | 416 m_context->bindTexture(GL_TEXTURE_2D, m_frontColorBuffer); |
418 m_context->produceTextureCHROMIUM(GL_TEXTURE_2D, bufferMailbox->mailbox.
name); | 417 m_context->produceTextureCHROMIUM(GL_TEXTURE_2D, bufferMailbox->mailbox.
name); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
464 m_context->deleteTexture(sourceTexture); | 463 m_context->deleteTexture(sourceTexture); |
465 | 464 |
466 m_context->bindFramebuffer(GL_FRAMEBUFFER, previousFramebuffer); | 465 m_context->bindFramebuffer(GL_FRAMEBUFFER, previousFramebuffer); |
467 } | 466 } |
468 | 467 |
469 void DrawingBuffer::clearPlatformLayer() | 468 void DrawingBuffer::clearPlatformLayer() |
470 { | 469 { |
471 if (m_layer) | 470 if (m_layer) |
472 m_layer->clearTexture(); | 471 m_layer->clearTexture(); |
473 | 472 |
474 if (m_context) | 473 m_context->flush(); |
475 m_context->flush(); | |
476 } | 474 } |
477 | 475 |
478 void DrawingBuffer::releaseResources() | 476 void DrawingBuffer::releaseResources() |
479 { | 477 { |
480 if (m_context) { | 478 m_context->makeContextCurrent(); |
481 m_context->makeContextCurrent(); | |
482 | 479 |
483 clearPlatformLayer(); | 480 clearPlatformLayer(); |
484 | 481 |
485 for (size_t i = 0; i < m_textureMailboxes.size(); i++) | 482 for (size_t i = 0; i < m_textureMailboxes.size(); i++) |
486 m_context->deleteTexture(m_textureMailboxes[i]->textureId); | 483 m_context->deleteTexture(m_textureMailboxes[i]->textureId); |
487 | 484 |
488 if (m_multisampleFBO) | 485 if (m_multisampleFBO) |
489 m_context->deleteFramebuffer(m_multisampleFBO); | 486 m_context->deleteFramebuffer(m_multisampleFBO); |
490 | 487 |
491 if (m_fbo) | 488 if (m_fbo) |
492 m_context->deleteFramebuffer(m_fbo); | 489 m_context->deleteFramebuffer(m_fbo); |
493 | 490 |
494 if (m_multisampleColorBuffer) | 491 if (m_multisampleColorBuffer) |
495 m_context->deleteRenderbuffer(m_multisampleColorBuffer); | 492 m_context->deleteRenderbuffer(m_multisampleColorBuffer); |
496 | 493 |
497 if (m_depthStencilBuffer) | 494 if (m_depthStencilBuffer) |
498 m_context->deleteRenderbuffer(m_depthStencilBuffer); | 495 m_context->deleteRenderbuffer(m_depthStencilBuffer); |
499 | 496 |
500 if (m_depthBuffer) | 497 if (m_depthBuffer) |
501 m_context->deleteRenderbuffer(m_depthBuffer); | 498 m_context->deleteRenderbuffer(m_depthBuffer); |
502 | 499 |
503 if (m_stencilBuffer) | 500 if (m_stencilBuffer) |
504 m_context->deleteRenderbuffer(m_stencilBuffer); | 501 m_context->deleteRenderbuffer(m_stencilBuffer); |
505 | 502 |
506 if (m_colorBuffer) | 503 if (m_colorBuffer) |
507 m_context->deleteTexture(m_colorBuffer); | 504 m_context->deleteTexture(m_colorBuffer); |
508 | 505 |
509 m_context = 0; | 506 m_context.clear(); |
510 } | |
511 | 507 |
512 setSize(IntSize()); | 508 setSize(IntSize()); |
513 | 509 |
514 m_colorBuffer = 0; | 510 m_colorBuffer = 0; |
515 m_frontColorBuffer = 0; | 511 m_frontColorBuffer = 0; |
516 m_multisampleColorBuffer = 0; | 512 m_multisampleColorBuffer = 0; |
517 m_depthStencilBuffer = 0; | 513 m_depthStencilBuffer = 0; |
518 m_depthBuffer = 0; | 514 m_depthBuffer = 0; |
519 m_stencilBuffer = 0; | 515 m_stencilBuffer = 0; |
520 m_multisampleFBO = 0; | 516 m_multisampleFBO = 0; |
521 m_fbo = 0; | 517 m_fbo = 0; |
522 m_contextEvictionManager.clear(); | 518 m_contextEvictionManager.clear(); |
523 | 519 |
524 m_recycledMailboxes.clear(); | 520 m_recycledMailboxes.clear(); |
525 m_textureMailboxes.clear(); | 521 m_textureMailboxes.clear(); |
526 | 522 |
527 if (m_layer) { | 523 if (m_layer) { |
528 GraphicsLayer::unregisterContentsLayer(m_layer->layer()); | 524 GraphicsLayer::unregisterContentsLayer(m_layer->layer()); |
529 m_layer.clear(); | 525 m_layer.clear(); |
530 } | 526 } |
531 } | 527 } |
532 | 528 |
533 unsigned DrawingBuffer::createColorTexture(const IntSize& size) | 529 unsigned DrawingBuffer::createColorTexture(const IntSize& size) |
534 { | 530 { |
535 if (!m_context) | |
536 return 0; | |
537 | |
538 unsigned offscreenColorTexture = m_context->createTexture(); | 531 unsigned offscreenColorTexture = m_context->createTexture(); |
539 if (!offscreenColorTexture) | 532 if (!offscreenColorTexture) |
540 return 0; | 533 return 0; |
541 | 534 |
542 m_context->bindTexture(GL_TEXTURE_2D, offscreenColorTexture); | 535 m_context->bindTexture(GL_TEXTURE_2D, offscreenColorTexture); |
543 m_context->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); | 536 m_context->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
544 m_context->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | 537 m_context->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
545 m_context->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)
; | 538 m_context->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)
; |
546 m_context->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)
; | 539 m_context->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)
; |
547 if (!size.isEmpty()) | 540 if (!size.isEmpty()) |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
644 m_context->framebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACH
MENT, GL_RENDERBUFFER, m_stencilBuffer); | 637 m_context->framebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACH
MENT, GL_RENDERBUFFER, m_stencilBuffer); |
645 } | 638 } |
646 } | 639 } |
647 m_context->bindRenderbuffer(GL_RENDERBUFFER, 0); | 640 m_context->bindRenderbuffer(GL_RENDERBUFFER, 0); |
648 } | 641 } |
649 | 642 |
650 | 643 |
651 | 644 |
652 void DrawingBuffer::clearFramebuffers(GLbitfield clearMask) | 645 void DrawingBuffer::clearFramebuffers(GLbitfield clearMask) |
653 { | 646 { |
654 if (!m_context) | |
655 return; | |
656 | |
657 // We will clear the multisample FBO, but we also need to clear the non-mult
isampled buffer. | 647 // We will clear the multisample FBO, but we also need to clear the non-mult
isampled buffer. |
658 if (m_multisampleFBO) { | 648 if (m_multisampleFBO) { |
659 m_context->bindFramebuffer(GL_FRAMEBUFFER, m_fbo); | 649 m_context->bindFramebuffer(GL_FRAMEBUFFER, m_fbo); |
660 m_context->clear(GL_COLOR_BUFFER_BIT); | 650 m_context->clear(GL_COLOR_BUFFER_BIT); |
661 } | 651 } |
662 | 652 |
663 m_context->bindFramebuffer(GL_FRAMEBUFFER, m_multisampleFBO ? m_multisampleF
BO : m_fbo); | 653 m_context->bindFramebuffer(GL_FRAMEBUFFER, m_multisampleFBO ? m_multisampleF
BO : m_fbo); |
664 m_context->clear(clearMask); | 654 m_context->clear(clearMask); |
665 } | 655 } |
666 | 656 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
714 int pixelDelta = oldestSize.width() * oldestSize.height(); | 704 int pixelDelta = oldestSize.width() * oldestSize.height(); |
715 | 705 |
716 s_currentResourceUsePixels -= pixelDelta; | 706 s_currentResourceUsePixels -= pixelDelta; |
717 adjustedSize = adjustSize(size); | 707 adjustedSize = adjustSize(size); |
718 s_currentResourceUsePixels += pixelDelta; | 708 s_currentResourceUsePixels += pixelDelta; |
719 | 709 |
720 evictContext = !adjustedSize.isEmpty(); | 710 evictContext = !adjustedSize.isEmpty(); |
721 return adjustedSize; | 711 return adjustedSize; |
722 } | 712 } |
723 | 713 |
724 void DrawingBuffer::reset(const IntSize& newSize) | 714 bool DrawingBuffer::reset(const IntSize& newSize) |
725 { | 715 { |
726 if (!m_context) | 716 ASSERT(!newSize.isEmpty()); |
727 return; | |
728 | |
729 IntSize adjustedSize; | 717 IntSize adjustedSize; |
730 bool evictContext = false; | 718 bool evictContext = false; |
731 bool isNewContext = m_size.isEmpty(); | 719 bool isNewContext = m_size.isEmpty(); |
732 if (s_allowContextEvictionOnCreate && isNewContext) | 720 if (s_allowContextEvictionOnCreate && isNewContext) |
733 adjustedSize = adjustSizeWithContextEviction(newSize, evictContext); | 721 adjustedSize = adjustSizeWithContextEviction(newSize, evictContext); |
734 else | 722 else |
735 adjustedSize = adjustSize(newSize); | 723 adjustedSize = adjustSize(newSize); |
736 | 724 |
737 if (adjustedSize.isEmpty()) | 725 if (adjustedSize.isEmpty()) |
738 return; | 726 return false; |
739 | 727 |
740 if (evictContext) | 728 if (evictContext) |
741 m_contextEvictionManager->forciblyLoseOldestContext("WARNING: WebGL cont
exts have exceeded the maximum allowed backbuffer area. Oldest context will be l
ost."); | 729 m_contextEvictionManager->forciblyLoseOldestContext("WARNING: WebGL cont
exts have exceeded the maximum allowed backbuffer area. Oldest context will be l
ost."); |
742 | 730 |
743 if (adjustedSize != m_size) { | 731 if (adjustedSize != m_size) { |
744 do { | 732 do { |
745 // resize multisample FBO | 733 // resize multisample FBO |
746 if (!resizeMultisampleFramebuffer(adjustedSize) || !resizeFramebuffe
r(adjustedSize)) { | 734 if (!resizeMultisampleFramebuffer(adjustedSize) || !resizeFramebuffe
r(adjustedSize)) { |
747 adjustedSize.scale(s_resourceAdjustedRatio); | 735 adjustedSize.scale(s_resourceAdjustedRatio); |
748 continue; | 736 continue; |
749 } | 737 } |
750 break; | 738 break; |
751 } while (!adjustedSize.isEmpty()); | 739 } while (!adjustedSize.isEmpty()); |
752 | 740 |
753 setSize(adjustedSize); | 741 setSize(adjustedSize); |
754 | 742 |
755 if (adjustedSize.isEmpty()) | 743 if (adjustedSize.isEmpty()) |
756 return; | 744 return false; |
757 } | 745 } |
758 | 746 |
759 m_context->disable(GL_SCISSOR_TEST); | 747 m_context->disable(GL_SCISSOR_TEST); |
760 m_context->clearColor(0, 0, 0, 0); | 748 m_context->clearColor(0, 0, 0, 0); |
761 m_context->colorMask(true, true, true, true); | 749 m_context->colorMask(true, true, true, true); |
762 | 750 |
763 GLbitfield clearMask = GL_COLOR_BUFFER_BIT; | 751 GLbitfield clearMask = GL_COLOR_BUFFER_BIT; |
764 if (m_attributes.depth) { | 752 if (m_attributes.depth) { |
765 m_context->clearDepth(1.0f); | 753 m_context->clearDepth(1.0f); |
766 clearMask |= GL_DEPTH_BUFFER_BIT; | 754 clearMask |= GL_DEPTH_BUFFER_BIT; |
767 m_context->depthMask(true); | 755 m_context->depthMask(true); |
768 } | 756 } |
769 if (m_attributes.stencil) { | 757 if (m_attributes.stencil) { |
770 m_context->clearStencil(0); | 758 m_context->clearStencil(0); |
771 clearMask |= GL_STENCIL_BUFFER_BIT; | 759 clearMask |= GL_STENCIL_BUFFER_BIT; |
772 m_context->stencilMaskSeparate(GL_FRONT, 0xFFFFFFFF); | 760 m_context->stencilMaskSeparate(GL_FRONT, 0xFFFFFFFF); |
773 } | 761 } |
774 | 762 |
775 clearFramebuffers(clearMask); | 763 clearFramebuffers(clearMask); |
| 764 return true; |
776 } | 765 } |
777 | 766 |
778 void DrawingBuffer::commit(long x, long y, long width, long height) | 767 void DrawingBuffer::commit(long x, long y, long width, long height) |
779 { | 768 { |
780 if (!m_context) | |
781 return; | |
782 | |
783 if (width < 0) | 769 if (width < 0) |
784 width = m_size.width(); | 770 width = m_size.width(); |
785 if (height < 0) | 771 if (height < 0) |
786 height = m_size.height(); | 772 height = m_size.height(); |
787 | 773 |
788 m_context->makeContextCurrent(); | 774 m_context->makeContextCurrent(); |
789 | 775 |
790 if (m_multisampleFBO && !m_contentsChangeCommitted) { | 776 if (m_multisampleFBO && !m_contentsChangeCommitted) { |
791 m_context->bindFramebuffer(GL_READ_FRAMEBUFFER_ANGLE, m_multisampleFBO); | 777 m_context->bindFramebuffer(GL_READ_FRAMEBUFFER_ANGLE, m_multisampleFBO); |
792 m_context->bindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, m_fbo); | 778 m_context->bindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, m_fbo); |
793 | 779 |
794 if (m_scissorEnabled) | 780 if (m_scissorEnabled) |
795 m_context->disable(GL_SCISSOR_TEST); | 781 m_context->disable(GL_SCISSOR_TEST); |
796 | 782 |
797 // Use NEAREST, because there is no scale performed during the blit. | 783 // Use NEAREST, because there is no scale performed during the blit. |
798 m_context->blitFramebufferCHROMIUM(x, y, width, height, x, y, width, hei
ght, GL_COLOR_BUFFER_BIT, GL_NEAREST); | 784 m_context->blitFramebufferCHROMIUM(x, y, width, height, x, y, width, hei
ght, GL_COLOR_BUFFER_BIT, GL_NEAREST); |
799 | 785 |
800 if (m_scissorEnabled) | 786 if (m_scissorEnabled) |
801 m_context->enable(GL_SCISSOR_TEST); | 787 m_context->enable(GL_SCISSOR_TEST); |
802 } | 788 } |
803 | 789 |
804 m_context->bindFramebuffer(GL_FRAMEBUFFER, m_fbo); | 790 m_context->bindFramebuffer(GL_FRAMEBUFFER, m_fbo); |
805 m_contentsChangeCommitted = true; | 791 m_contentsChangeCommitted = true; |
806 } | 792 } |
807 | 793 |
808 void DrawingBuffer::restoreFramebufferBinding() | 794 void DrawingBuffer::restoreFramebufferBinding() |
809 { | 795 { |
810 if (!m_context || !m_framebufferBinding) | 796 if (!m_framebufferBinding) |
811 return; | 797 return; |
812 | 798 |
813 m_context->bindFramebuffer(GL_FRAMEBUFFER, m_framebufferBinding); | 799 m_context->bindFramebuffer(GL_FRAMEBUFFER, m_framebufferBinding); |
814 } | 800 } |
815 | 801 |
816 bool DrawingBuffer::multisample() const | 802 bool DrawingBuffer::multisample() const |
817 { | 803 { |
818 return m_multisampleMode != None; | 804 return m_multisampleMode != None; |
819 } | 805 } |
820 | 806 |
821 void DrawingBuffer::bind() | 807 void DrawingBuffer::bind() |
822 { | 808 { |
823 if (!m_context) | |
824 return; | |
825 | |
826 m_context->bindFramebuffer(GL_FRAMEBUFFER, m_multisampleFBO ? m_multisampleF
BO : m_fbo); | 809 m_context->bindFramebuffer(GL_FRAMEBUFFER, m_multisampleFBO ? m_multisampleF
BO : m_fbo); |
827 } | 810 } |
828 | 811 |
829 void DrawingBuffer::setPackAlignment(GLint param) | 812 void DrawingBuffer::setPackAlignment(GLint param) |
830 { | 813 { |
831 m_packAlignment = param; | 814 m_packAlignment = param; |
832 } | 815 } |
833 | 816 |
834 void DrawingBuffer::paintRenderingResultsToCanvas(ImageBuffer* imageBuffer) | 817 void DrawingBuffer::paintRenderingResultsToCanvas(ImageBuffer* imageBuffer) |
835 { | 818 { |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
946 } | 929 } |
947 } | 930 } |
948 | 931 |
949 void DrawingBuffer::texImage2DResourceSafe(GLenum target, GLint level, GLenum in
ternalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum
type, GLint unpackAlignment) | 932 void DrawingBuffer::texImage2DResourceSafe(GLenum target, GLint level, GLenum in
ternalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum
type, GLint unpackAlignment) |
950 { | 933 { |
951 ASSERT(unpackAlignment == 1 || unpackAlignment == 2 || unpackAlignment == 4
|| unpackAlignment == 8); | 934 ASSERT(unpackAlignment == 1 || unpackAlignment == 2 || unpackAlignment == 4
|| unpackAlignment == 8); |
952 m_context->texImage2D(target, level, internalformat, width, height, border,
format, type, 0); | 935 m_context->texImage2D(target, level, internalformat, width, height, border,
format, type, 0); |
953 } | 936 } |
954 | 937 |
955 } // namespace WebCore | 938 } // namespace WebCore |
OLD | NEW |