| 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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 m_context->bindTexture(GL_TEXTURE_2D, m_oldTextureUnitZeroId); | 70 m_context->bindTexture(GL_TEXTURE_2D, m_oldTextureUnitZeroId); |
| 71 m_context->activeTexture(m_oldActiveTextureUnit); | 71 m_context->activeTexture(m_oldActiveTextureUnit); |
| 72 } | 72 } |
| 73 | 73 |
| 74 private: | 74 private: |
| 75 blink::WebGraphicsContext3D* m_context; | 75 blink::WebGraphicsContext3D* m_context; |
| 76 GLenum m_oldActiveTextureUnit; | 76 GLenum m_oldActiveTextureUnit; |
| 77 Platform3DObject m_oldTextureUnitZeroId; | 77 Platform3DObject m_oldTextureUnitZeroId; |
| 78 }; | 78 }; |
| 79 | 79 |
| 80 PassRefPtr<DrawingBuffer> DrawingBuffer::create(PassOwnPtr<blink::WebGraphicsCon
text3D> context, const IntSize& size, PreserveDrawingBuffer preserve, PassRefPtr
<ContextEvictionManager> contextEvictionManager) | 80 PassRefPtr<DrawingBuffer> DrawingBuffer::create(blink::WebGraphicsContext3D* con
text, const IntSize& size, PreserveDrawingBuffer preserve, PassRefPtr<ContextEvi
ctionManager> contextEvictionManager) |
| 81 { | 81 { |
| 82 ASSERT(context); | 82 Extensions3DUtil extensionsUtil(context); |
| 83 Extensions3DUtil extensionsUtil(context.get()); | |
| 84 bool multisampleSupported = extensionsUtil.supportsExtension("GL_CHROMIUM_fr
amebuffer_multisample") | 83 bool multisampleSupported = extensionsUtil.supportsExtension("GL_CHROMIUM_fr
amebuffer_multisample") |
| 85 && extensionsUtil.supportsExtension("GL_OES_rgb8_rgba8"); | 84 && extensionsUtil.supportsExtension("GL_OES_rgb8_rgba8"); |
| 86 if (multisampleSupported) { | 85 if (multisampleSupported) { |
| 87 extensionsUtil.ensureExtensionEnabled("GL_CHROMIUM_framebuffer_multisamp
le"); | 86 extensionsUtil.ensureExtensionEnabled("GL_CHROMIUM_framebuffer_multisamp
le"); |
| 88 extensionsUtil.ensureExtensionEnabled("GL_OES_rgb8_rgba8"); | 87 extensionsUtil.ensureExtensionEnabled("GL_OES_rgb8_rgba8"); |
| 89 } | 88 } |
| 90 bool packedDepthStencilSupported = extensionsUtil.supportsExtension("GL_OES_
packed_depth_stencil"); | 89 bool packedDepthStencilSupported = extensionsUtil.supportsExtension("GL_OES_
packed_depth_stencil"); |
| 91 if (packedDepthStencilSupported) | 90 if (packedDepthStencilSupported) |
| 92 extensionsUtil.ensureExtensionEnabled("GL_OES_packed_depth_stencil"); | 91 extensionsUtil.ensureExtensionEnabled("GL_OES_packed_depth_stencil"); |
| 93 | 92 |
| 94 RefPtr<DrawingBuffer> drawingBuffer = adoptRef(new DrawingBuffer(context, mu
ltisampleSupported, packedDepthStencilSupported, preserve, contextEvictionManage
r)); | 93 RefPtr<DrawingBuffer> drawingBuffer = adoptRef(new DrawingBuffer(context, si
ze, multisampleSupported, packedDepthStencilSupported, preserve, contextEviction
Manager)); |
| 95 if (!drawingBuffer->initialize(size)) | |
| 96 return PassRefPtr<DrawingBuffer>(); | |
| 97 return drawingBuffer.release(); | 94 return drawingBuffer.release(); |
| 98 } | 95 } |
| 99 | 96 |
| 100 DrawingBuffer::DrawingBuffer(PassOwnPtr<blink::WebGraphicsContext3D> context, | 97 DrawingBuffer::DrawingBuffer(blink::WebGraphicsContext3D* context, |
| 98 const IntSize& size, |
| 101 bool multisampleExtensionSupported, | 99 bool multisampleExtensionSupported, |
| 102 bool packedDepthStencilExtensionSupported, | 100 bool packedDepthStencilExtensionSupported, |
| 103 PreserveDrawingBuffer preserve, | 101 PreserveDrawingBuffer preserve, |
| 104 PassRefPtr<ContextEvictionManager> contextEvictionManager) | 102 PassRefPtr<ContextEvictionManager> contextEvictionManager) |
| 105 : m_preserveDrawingBuffer(preserve) | 103 : m_preserveDrawingBuffer(preserve) |
| 106 , m_scissorEnabled(false) | 104 , m_scissorEnabled(false) |
| 107 , m_texture2DBinding(0) | 105 , m_texture2DBinding(0) |
| 108 , m_framebufferBinding(0) | 106 , m_framebufferBinding(0) |
| 109 , m_activeTextureUnit(GL_TEXTURE0) | 107 , m_activeTextureUnit(GL_TEXTURE0) |
| 110 , m_context(context) | 108 , m_context(context) |
| 111 , m_size(-1, -1) | 109 , m_size(-1, -1) |
| 112 , m_multisampleExtensionSupported(multisampleExtensionSupported) | 110 , m_multisampleExtensionSupported(multisampleExtensionSupported) |
| 113 , m_packedDepthStencilExtensionSupported(packedDepthStencilExtensionSupporte
d) | 111 , m_packedDepthStencilExtensionSupported(packedDepthStencilExtensionSupporte
d) |
| 114 , m_fbo(0) | 112 , m_fbo(0) |
| 115 , m_colorBuffer(0) | 113 , m_colorBuffer(0) |
| 116 , m_frontColorBuffer(0) | 114 , m_frontColorBuffer(0) |
| 117 , m_depthStencilBuffer(0) | 115 , m_depthStencilBuffer(0) |
| 118 , m_depthBuffer(0) | 116 , m_depthBuffer(0) |
| 119 , m_stencilBuffer(0) | 117 , m_stencilBuffer(0) |
| 120 , m_multisampleFBO(0) | 118 , m_multisampleFBO(0) |
| 121 , m_multisampleColorBuffer(0) | 119 , m_multisampleColorBuffer(0) |
| 122 , m_contentsChanged(true) | 120 , m_contentsChanged(true) |
| 123 , m_contentsChangeCommitted(false) | 121 , m_contentsChangeCommitted(false) |
| 124 , m_layerComposited(false) | 122 , m_layerComposited(false) |
| 125 , m_internalColorFormat(0) | 123 , m_internalColorFormat(0) |
| 126 , m_colorFormat(0) | 124 , m_colorFormat(0) |
| 127 , m_internalRenderbufferFormat(0) | 125 , m_internalRenderbufferFormat(0) |
| 128 , m_maxTextureSize(0) | 126 , m_maxTextureSize(0) |
| 129 , m_sampleCount(0) | |
| 130 , m_packAlignment(4) | 127 , m_packAlignment(4) |
| 131 , m_contextEvictionManager(contextEvictionManager) | 128 , m_contextEvictionManager(contextEvictionManager) |
| 132 { | 129 { |
| 133 // Used by browser tests to detect the use of a DrawingBuffer. | 130 // Used by browser tests to detect the use of a DrawingBuffer. |
| 134 TRACE_EVENT_INSTANT0("test_gpu", "DrawingBufferCreation"); | 131 TRACE_EVENT_INSTANT0("test_gpu", "DrawingBufferCreation"); |
| 132 initialize(size); |
| 135 } | 133 } |
| 136 | 134 |
| 137 DrawingBuffer::~DrawingBuffer() | 135 DrawingBuffer::~DrawingBuffer() |
| 138 { | 136 { |
| 139 releaseResources(); | 137 releaseResources(); |
| 140 } | 138 } |
| 141 | 139 |
| 142 void DrawingBuffer::markContentsChanged() | 140 void DrawingBuffer::markContentsChanged() |
| 143 { | 141 { |
| 144 m_contentsChanged = true; | 142 m_contentsChanged = true; |
| 145 m_contentsChangeCommitted = false; | 143 m_contentsChangeCommitted = false; |
| 146 m_layerComposited = false; | 144 m_layerComposited = false; |
| 147 } | 145 } |
| 148 | 146 |
| 149 bool DrawingBuffer::layerComposited() const | 147 bool DrawingBuffer::layerComposited() const |
| 150 { | 148 { |
| 151 return m_layerComposited; | 149 return m_layerComposited; |
| 152 } | 150 } |
| 153 | 151 |
| 154 void DrawingBuffer::markLayerComposited() | 152 void DrawingBuffer::markLayerComposited() |
| 155 { | 153 { |
| 156 m_layerComposited = true; | 154 m_layerComposited = true; |
| 157 } | 155 } |
| 158 | 156 |
| 159 blink::WebGraphicsContext3D* DrawingBuffer::context() | 157 blink::WebGraphicsContext3D* DrawingBuffer::context() |
| 160 { | 158 { |
| 161 return m_context.get(); | 159 return m_context; |
| 162 } | 160 } |
| 163 | 161 |
| 164 bool DrawingBuffer::prepareMailbox(blink::WebExternalTextureMailbox* outMailbox,
blink::WebExternalBitmap* bitmap) | 162 bool DrawingBuffer::prepareMailbox(blink::WebExternalTextureMailbox* outMailbox,
blink::WebExternalBitmap* bitmap) |
| 165 { | 163 { |
| 166 if (!m_contentsChanged) | 164 if (!m_context || !m_contentsChanged) |
| 167 return false; | 165 return false; |
| 168 | 166 |
| 169 m_context->makeContextCurrent(); | 167 m_context->makeContextCurrent(); |
| 170 | 168 |
| 171 // Resolve the multisampled buffer into m_colorBuffer texture. | 169 // Resolve the multisampled buffer into m_colorBuffer texture. |
| 172 if (m_multisampleMode != None) | 170 if (m_multisampleMode != None) |
| 173 commit(); | 171 commit(); |
| 174 | 172 |
| 175 if (bitmap) { | 173 if (bitmap) { |
| 176 bitmap->setSize(size()); | 174 bitmap->setSize(size()); |
| 177 | 175 |
| 178 unsigned char* pixels = bitmap->pixels(); | 176 unsigned char* pixels = bitmap->pixels(); |
| 179 bool needPremultiply = m_attributes.alpha && !m_attributes.premultiplied
Alpha; | 177 bool needPremultiply = m_attributes.alpha && !m_attributes.premultiplied
Alpha; |
| 180 WebGLImageConversion::AlphaOp op = needPremultiply ? WebGLImageConversio
n::AlphaDoPremultiply : WebGLImageConversion::AlphaDoNothing; | 178 WebGLImageConversion::AlphaOp op = needPremultiply ? WebGLImageConversio
n::AlphaDoPremultiply : WebGLImageConversion::AlphaDoNothing; |
| 181 if (pixels) | 179 if (pixels) |
| 182 readBackFramebuffer(pixels, size().width(), size().height(), Readbac
kSkia, op); | 180 readBackFramebuffer(pixels, size().width(), size().height(), Readbac
kSkia, op); |
| 183 } | 181 } |
| 184 | 182 |
| 185 // We must restore the texture binding since creating new textures, | 183 // We must restore the texture binding since creating new textures, |
| 186 // consuming and producing mailboxes changes it. | 184 // consuming and producing mailboxes changes it. |
| 187 ScopedTextureUnit0BindingRestorer restorer(m_context.get(), m_activeTextureU
nit, m_texture2DBinding); | 185 ScopedTextureUnit0BindingRestorer restorer(m_context, m_activeTextureUnit, m
_texture2DBinding); |
| 188 | 186 |
| 189 // First try to recycle an old buffer. | 187 // First try to recycle an old buffer. |
| 190 RefPtr<MailboxInfo> frontColorBufferMailbox = recycledMailbox(); | 188 RefPtr<MailboxInfo> frontColorBufferMailbox = recycledMailbox(); |
| 191 | 189 |
| 192 // No buffer available to recycle, create a new one. | 190 // No buffer available to recycle, create a new one. |
| 193 if (!frontColorBufferMailbox) { | 191 if (!frontColorBufferMailbox) { |
| 194 unsigned newColorBuffer = createColorTexture(m_size); | 192 unsigned newColorBuffer = createColorTexture(m_size); |
| 195 // Bad things happened, abandon ship. | 193 // Bad things happened, abandon ship. |
| 196 if (!newColorBuffer) | 194 if (!newColorBuffer) |
| 197 return false; | 195 return false; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 mailboxInfo->mailbox.syncPoint = mailbox.syncPoint; | 238 mailboxInfo->mailbox.syncPoint = mailbox.syncPoint; |
| 241 m_recycledMailboxes.prepend(mailboxInfo.release()); | 239 m_recycledMailboxes.prepend(mailboxInfo.release()); |
| 242 return; | 240 return; |
| 243 } | 241 } |
| 244 } | 242 } |
| 245 ASSERT_NOT_REACHED(); | 243 ASSERT_NOT_REACHED(); |
| 246 } | 244 } |
| 247 | 245 |
| 248 PassRefPtr<DrawingBuffer::MailboxInfo> DrawingBuffer::recycledMailbox() | 246 PassRefPtr<DrawingBuffer::MailboxInfo> DrawingBuffer::recycledMailbox() |
| 249 { | 247 { |
| 250 if (m_recycledMailboxes.isEmpty()) | 248 if (!m_context || m_recycledMailboxes.isEmpty()) |
| 251 return PassRefPtr<MailboxInfo>(); | 249 return PassRefPtr<MailboxInfo>(); |
| 252 | 250 |
| 253 RefPtr<MailboxInfo> mailboxInfo = m_recycledMailboxes.last().release(); | 251 RefPtr<MailboxInfo> mailboxInfo = m_recycledMailboxes.last().release(); |
| 254 m_recycledMailboxes.removeLast(); | 252 m_recycledMailboxes.removeLast(); |
| 255 | 253 |
| 256 if (mailboxInfo->mailbox.syncPoint) { | 254 if (mailboxInfo->mailbox.syncPoint) { |
| 257 m_context->waitSyncPoint(mailboxInfo->mailbox.syncPoint); | 255 m_context->waitSyncPoint(mailboxInfo->mailbox.syncPoint); |
| 258 mailboxInfo->mailbox.syncPoint = 0; | 256 mailboxInfo->mailbox.syncPoint = 0; |
| 259 } | 257 } |
| 260 | 258 |
| 261 if (mailboxInfo->size != m_size) { | 259 if (mailboxInfo->size != m_size) { |
| 262 m_context->bindTexture(GL_TEXTURE_2D, mailboxInfo->textureId); | 260 m_context->bindTexture(GL_TEXTURE_2D, mailboxInfo->textureId); |
| 263 texImage2DResourceSafe(GL_TEXTURE_2D, 0, m_internalColorFormat, m_size.w
idth(), m_size.height(), 0, m_colorFormat, GL_UNSIGNED_BYTE); | 261 texImage2DResourceSafe(GL_TEXTURE_2D, 0, m_internalColorFormat, m_size.w
idth(), m_size.height(), 0, m_colorFormat, GL_UNSIGNED_BYTE); |
| 264 mailboxInfo->size = m_size; | 262 mailboxInfo->size = m_size; |
| 265 } | 263 } |
| 266 | 264 |
| 267 return mailboxInfo.release(); | 265 return mailboxInfo.release(); |
| 268 } | 266 } |
| 269 | 267 |
| 270 PassRefPtr<DrawingBuffer::MailboxInfo> DrawingBuffer::createNewMailbox(unsigned
textureId) | 268 PassRefPtr<DrawingBuffer::MailboxInfo> DrawingBuffer::createNewMailbox(unsigned
textureId) |
| 271 { | 269 { |
| 272 RefPtr<MailboxInfo> returnMailbox = adoptRef(new MailboxInfo()); | 270 RefPtr<MailboxInfo> returnMailbox = adoptRef(new MailboxInfo()); |
| 273 m_context->genMailboxCHROMIUM(returnMailbox->mailbox.name); | 271 m_context->genMailboxCHROMIUM(returnMailbox->mailbox.name); |
| 274 returnMailbox->textureId = textureId; | 272 returnMailbox->textureId = textureId; |
| 275 returnMailbox->size = m_size; | 273 returnMailbox->size = m_size; |
| 276 m_textureMailboxes.append(returnMailbox); | 274 m_textureMailboxes.append(returnMailbox); |
| 277 return returnMailbox.release(); | 275 return returnMailbox.release(); |
| 278 } | 276 } |
| 279 | 277 |
| 280 bool DrawingBuffer::initialize(const IntSize& size) | 278 void DrawingBuffer::initialize(const IntSize& size) |
| 281 { | 279 { |
| 280 ASSERT(m_context); |
| 282 m_attributes = m_context->getContextAttributes(); | 281 m_attributes = m_context->getContextAttributes(); |
| 283 Extensions3DUtil extensionsUtil(m_context.get()); | 282 Extensions3DUtil extensionsUtil(m_context); |
| 284 | 283 |
| 285 if (m_attributes.alpha) { | 284 if (m_attributes.alpha) { |
| 286 m_internalColorFormat = GL_RGBA; | 285 m_internalColorFormat = GL_RGBA; |
| 287 m_colorFormat = GL_RGBA; | 286 m_colorFormat = GL_RGBA; |
| 288 m_internalRenderbufferFormat = GL_RGBA8_OES; | 287 m_internalRenderbufferFormat = GL_RGBA8_OES; |
| 289 } else { | 288 } else { |
| 290 m_internalColorFormat = GL_RGB; | 289 m_internalColorFormat = GL_RGB; |
| 291 m_colorFormat = GL_RGB; | 290 m_colorFormat = GL_RGB; |
| 292 m_internalRenderbufferFormat = GL_RGB8_OES; | 291 m_internalRenderbufferFormat = GL_RGB8_OES; |
| 293 } | 292 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 306 | 305 |
| 307 m_fbo = m_context->createFramebuffer(); | 306 m_fbo = m_context->createFramebuffer(); |
| 308 | 307 |
| 309 m_context->bindFramebuffer(GL_FRAMEBUFFER, m_fbo); | 308 m_context->bindFramebuffer(GL_FRAMEBUFFER, m_fbo); |
| 310 m_colorBuffer = createColorTexture(); | 309 m_colorBuffer = createColorTexture(); |
| 311 if (m_multisampleMode == ImplicitResolve) | 310 if (m_multisampleMode == ImplicitResolve) |
| 312 m_context->framebufferTexture2DMultisampleEXT(GL_FRAMEBUFFER, GL_COLOR_A
TTACHMENT0, GL_TEXTURE_2D, m_colorBuffer, 0, m_sampleCount); | 311 m_context->framebufferTexture2DMultisampleEXT(GL_FRAMEBUFFER, GL_COLOR_A
TTACHMENT0, GL_TEXTURE_2D, m_colorBuffer, 0, m_sampleCount); |
| 313 else | 312 else |
| 314 m_context->framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL
_TEXTURE_2D, m_colorBuffer, 0); | 313 m_context->framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL
_TEXTURE_2D, m_colorBuffer, 0); |
| 315 createSecondaryBuffers(); | 314 createSecondaryBuffers(); |
| 316 return reset(size); | 315 reset(size); |
| 317 } | 316 } |
| 318 | 317 |
| 319 bool DrawingBuffer::copyToPlatformTexture(blink::WebGraphicsContext3D* context,
Platform3DObject texture, GLenum internalFormat, GLenum destType, GLint level, b
ool premultiplyAlpha, bool flipY) | 318 bool DrawingBuffer::copyToPlatformTexture(blink::WebGraphicsContext3D* context,
Platform3DObject texture, GLenum internalFormat, GLenum destType, GLint level, b
ool premultiplyAlpha, bool flipY) |
| 320 { | 319 { |
| 321 if (!m_context->makeContextCurrent()) | 320 if (!m_context || !m_context->makeContextCurrent()) |
| 322 return false; | 321 return false; |
| 323 if (m_contentsChanged) { | 322 if (m_contentsChanged) { |
| 324 if (m_multisampleMode != None) { | 323 if (m_multisampleMode != None) { |
| 325 commit(); | 324 commit(); |
| 326 if (!m_framebufferBinding) | 325 if (!m_framebufferBinding) |
| 327 bind(); | 326 bind(); |
| 328 else | 327 else |
| 329 restoreFramebufferBinding(); | 328 restoreFramebufferBinding(); |
| 330 } | 329 } |
| 331 m_context->flush(); | 330 m_context->flush(); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 357 return true; | 356 return true; |
| 358 } | 357 } |
| 359 | 358 |
| 360 Platform3DObject DrawingBuffer::framebuffer() const | 359 Platform3DObject DrawingBuffer::framebuffer() const |
| 361 { | 360 { |
| 362 return m_fbo; | 361 return m_fbo; |
| 363 } | 362 } |
| 364 | 363 |
| 365 blink::WebLayer* DrawingBuffer::platformLayer() | 364 blink::WebLayer* DrawingBuffer::platformLayer() |
| 366 { | 365 { |
| 366 if (!m_context) |
| 367 return 0; |
| 368 |
| 367 if (!m_layer) { | 369 if (!m_layer) { |
| 368 m_layer = adoptPtr(blink::Platform::current()->compositorSupport()->crea
teExternalTextureLayer(this)); | 370 m_layer = adoptPtr(blink::Platform::current()->compositorSupport()->crea
teExternalTextureLayer(this)); |
| 369 | 371 |
| 370 m_layer->setOpaque(!m_attributes.alpha); | 372 m_layer->setOpaque(!m_attributes.alpha); |
| 371 m_layer->setBlendBackgroundColor(m_attributes.alpha); | 373 m_layer->setBlendBackgroundColor(m_attributes.alpha); |
| 372 m_layer->setPremultipliedAlpha(m_attributes.premultipliedAlpha); | 374 m_layer->setPremultipliedAlpha(m_attributes.premultipliedAlpha); |
| 373 GraphicsLayer::registerContentsLayer(m_layer->layer()); | 375 GraphicsLayer::registerContentsLayer(m_layer->layer()); |
| 374 } | 376 } |
| 375 | 377 |
| 376 return m_layer->layer(); | 378 return m_layer->layer(); |
| 377 } | 379 } |
| 378 | 380 |
| 379 void DrawingBuffer::paintCompositedResultsToCanvas(ImageBuffer* imageBuffer) | 381 void DrawingBuffer::paintCompositedResultsToCanvas(ImageBuffer* imageBuffer) |
| 380 { | 382 { |
| 381 if (!m_context->makeContextCurrent() || m_context->getGraphicsResetStatusARB
() != GL_NO_ERROR) | 383 if (!m_context || !m_context->makeContextCurrent() || m_context->getGraphics
ResetStatusARB() != GL_NO_ERROR) |
| 382 return; | 384 return; |
| 383 | 385 |
| 384 if (!imageBuffer) | 386 if (!imageBuffer) |
| 385 return; | 387 return; |
| 386 Platform3DObject tex = imageBuffer->getBackingTexture(); | 388 Platform3DObject tex = imageBuffer->getBackingTexture(); |
| 387 if (tex) { | 389 if (tex) { |
| 388 m_context->copyTextureCHROMIUM(GL_TEXTURE_2D, m_frontColorBuffer, | 390 m_context->copyTextureCHROMIUM(GL_TEXTURE_2D, m_frontColorBuffer, |
| 389 tex, 0, GL_RGBA, GL_UNSIGNED_BYTE); | 391 tex, 0, GL_RGBA, GL_UNSIGNED_BYTE); |
| 390 return; | 392 return; |
| 391 } | 393 } |
| (...skipping 20 matching lines...) Expand all Loading... |
| 412 m_context->deleteTexture(sourceTexture); | 414 m_context->deleteTexture(sourceTexture); |
| 413 | 415 |
| 414 m_context->bindFramebuffer(GL_FRAMEBUFFER, previousFramebuffer); | 416 m_context->bindFramebuffer(GL_FRAMEBUFFER, previousFramebuffer); |
| 415 } | 417 } |
| 416 | 418 |
| 417 void DrawingBuffer::clearPlatformLayer() | 419 void DrawingBuffer::clearPlatformLayer() |
| 418 { | 420 { |
| 419 if (m_layer) | 421 if (m_layer) |
| 420 m_layer->clearTexture(); | 422 m_layer->clearTexture(); |
| 421 | 423 |
| 422 m_context->flush(); | 424 if (m_context) |
| 425 m_context->flush(); |
| 423 } | 426 } |
| 424 | 427 |
| 425 void DrawingBuffer::releaseResources() | 428 void DrawingBuffer::releaseResources() |
| 426 { | 429 { |
| 427 m_context->makeContextCurrent(); | 430 if (m_context) { |
| 431 m_context->makeContextCurrent(); |
| 428 | 432 |
| 429 clearPlatformLayer(); | 433 clearPlatformLayer(); |
| 430 | 434 |
| 431 for (size_t i = 0; i < m_textureMailboxes.size(); i++) | 435 for (size_t i = 0; i < m_textureMailboxes.size(); i++) |
| 432 m_context->deleteTexture(m_textureMailboxes[i]->textureId); | 436 m_context->deleteTexture(m_textureMailboxes[i]->textureId); |
| 433 | 437 |
| 434 if (m_multisampleColorBuffer) | 438 if (m_multisampleColorBuffer) |
| 435 m_context->deleteRenderbuffer(m_multisampleColorBuffer); | 439 m_context->deleteRenderbuffer(m_multisampleColorBuffer); |
| 436 | 440 |
| 437 if (m_depthStencilBuffer) | 441 if (m_depthStencilBuffer) |
| 438 m_context->deleteRenderbuffer(m_depthStencilBuffer); | 442 m_context->deleteRenderbuffer(m_depthStencilBuffer); |
| 439 | 443 |
| 440 if (m_depthBuffer) | 444 if (m_depthBuffer) |
| 441 m_context->deleteRenderbuffer(m_depthBuffer); | 445 m_context->deleteRenderbuffer(m_depthBuffer); |
| 442 | 446 |
| 443 if (m_stencilBuffer) | 447 if (m_stencilBuffer) |
| 444 m_context->deleteRenderbuffer(m_stencilBuffer); | 448 m_context->deleteRenderbuffer(m_stencilBuffer); |
| 445 | 449 |
| 446 if (m_multisampleFBO) | 450 if (m_multisampleFBO) |
| 447 m_context->deleteFramebuffer(m_multisampleFBO); | 451 m_context->deleteFramebuffer(m_multisampleFBO); |
| 448 | 452 |
| 449 if (m_fbo) | 453 if (m_fbo) |
| 450 m_context->deleteFramebuffer(m_fbo); | 454 m_context->deleteFramebuffer(m_fbo); |
| 451 | 455 |
| 452 m_context.clear(); | 456 m_context = 0; |
| 457 } |
| 453 | 458 |
| 454 setSize(IntSize()); | 459 setSize(IntSize()); |
| 455 | 460 |
| 456 m_colorBuffer = 0; | 461 m_colorBuffer = 0; |
| 457 m_frontColorBuffer = 0; | 462 m_frontColorBuffer = 0; |
| 458 m_multisampleColorBuffer = 0; | 463 m_multisampleColorBuffer = 0; |
| 459 m_depthStencilBuffer = 0; | 464 m_depthStencilBuffer = 0; |
| 460 m_depthBuffer = 0; | 465 m_depthBuffer = 0; |
| 461 m_stencilBuffer = 0; | 466 m_stencilBuffer = 0; |
| 462 m_multisampleFBO = 0; | 467 m_multisampleFBO = 0; |
| 463 m_fbo = 0; | 468 m_fbo = 0; |
| 464 m_contextEvictionManager.clear(); | 469 m_contextEvictionManager.clear(); |
| 465 | 470 |
| 466 m_recycledMailboxes.clear(); | 471 m_recycledMailboxes.clear(); |
| 467 m_textureMailboxes.clear(); | 472 m_textureMailboxes.clear(); |
| 468 | 473 |
| 469 if (m_layer) { | 474 if (m_layer) { |
| 470 GraphicsLayer::unregisterContentsLayer(m_layer->layer()); | 475 GraphicsLayer::unregisterContentsLayer(m_layer->layer()); |
| 471 m_layer.clear(); | 476 m_layer.clear(); |
| 472 } | 477 } |
| 473 } | 478 } |
| 474 | 479 |
| 475 unsigned DrawingBuffer::createColorTexture(const IntSize& size) | 480 unsigned DrawingBuffer::createColorTexture(const IntSize& size) |
| 476 { | 481 { |
| 482 if (!m_context) |
| 483 return 0; |
| 484 |
| 477 unsigned offscreenColorTexture = m_context->createTexture(); | 485 unsigned offscreenColorTexture = m_context->createTexture(); |
| 478 if (!offscreenColorTexture) | 486 if (!offscreenColorTexture) |
| 479 return 0; | 487 return 0; |
| 480 | 488 |
| 481 m_context->bindTexture(GL_TEXTURE_2D, offscreenColorTexture); | 489 m_context->bindTexture(GL_TEXTURE_2D, offscreenColorTexture); |
| 482 m_context->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); | 490 m_context->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
| 483 m_context->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | 491 m_context->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
| 484 m_context->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)
; | 492 m_context->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)
; |
| 485 m_context->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)
; | 493 m_context->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)
; |
| 486 if (!size.isEmpty()) | 494 if (!size.isEmpty()) |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 583 m_context->framebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACH
MENT, GL_RENDERBUFFER, m_stencilBuffer); | 591 m_context->framebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACH
MENT, GL_RENDERBUFFER, m_stencilBuffer); |
| 584 } | 592 } |
| 585 } | 593 } |
| 586 m_context->bindRenderbuffer(GL_RENDERBUFFER, 0); | 594 m_context->bindRenderbuffer(GL_RENDERBUFFER, 0); |
| 587 } | 595 } |
| 588 | 596 |
| 589 | 597 |
| 590 | 598 |
| 591 void DrawingBuffer::clearFramebuffers(GLbitfield clearMask) | 599 void DrawingBuffer::clearFramebuffers(GLbitfield clearMask) |
| 592 { | 600 { |
| 601 if (!m_context) |
| 602 return; |
| 603 |
| 593 // We will clear the multisample FBO, but we also need to clear the non-mult
isampled buffer. | 604 // We will clear the multisample FBO, but we also need to clear the non-mult
isampled buffer. |
| 594 if (m_multisampleFBO) { | 605 if (m_multisampleFBO) { |
| 595 m_context->bindFramebuffer(GL_FRAMEBUFFER, m_fbo); | 606 m_context->bindFramebuffer(GL_FRAMEBUFFER, m_fbo); |
| 596 m_context->clear(GL_COLOR_BUFFER_BIT); | 607 m_context->clear(GL_COLOR_BUFFER_BIT); |
| 597 } | 608 } |
| 598 | 609 |
| 599 m_context->bindFramebuffer(GL_FRAMEBUFFER, m_multisampleFBO ? m_multisampleF
BO : m_fbo); | 610 m_context->bindFramebuffer(GL_FRAMEBUFFER, m_multisampleFBO ? m_multisampleF
BO : m_fbo); |
| 600 m_context->clear(clearMask); | 611 m_context->clear(clearMask); |
| 601 } | 612 } |
| 602 | 613 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 650 int pixelDelta = oldestSize.width() * oldestSize.height(); | 661 int pixelDelta = oldestSize.width() * oldestSize.height(); |
| 651 | 662 |
| 652 s_currentResourceUsePixels -= pixelDelta; | 663 s_currentResourceUsePixels -= pixelDelta; |
| 653 adjustedSize = adjustSize(size); | 664 adjustedSize = adjustSize(size); |
| 654 s_currentResourceUsePixels += pixelDelta; | 665 s_currentResourceUsePixels += pixelDelta; |
| 655 | 666 |
| 656 evictContext = !adjustedSize.isEmpty(); | 667 evictContext = !adjustedSize.isEmpty(); |
| 657 return adjustedSize; | 668 return adjustedSize; |
| 658 } | 669 } |
| 659 | 670 |
| 660 bool DrawingBuffer::reset(const IntSize& newSize) | 671 void DrawingBuffer::reset(const IntSize& newSize) |
| 661 { | 672 { |
| 662 ASSERT(!newSize.isEmpty()); | 673 if (!m_context) |
| 674 return; |
| 675 |
| 663 IntSize adjustedSize; | 676 IntSize adjustedSize; |
| 664 bool evictContext = false; | 677 bool evictContext = false; |
| 665 bool isNewContext = m_size.isEmpty(); | 678 bool isNewContext = m_size.isEmpty(); |
| 666 if (s_allowContextEvictionOnCreate && isNewContext) | 679 if (s_allowContextEvictionOnCreate && isNewContext) |
| 667 adjustedSize = adjustSizeWithContextEviction(newSize, evictContext); | 680 adjustedSize = adjustSizeWithContextEviction(newSize, evictContext); |
| 668 else | 681 else |
| 669 adjustedSize = adjustSize(newSize); | 682 adjustedSize = adjustSize(newSize); |
| 670 | 683 |
| 671 if (adjustedSize.isEmpty()) | 684 if (adjustedSize.isEmpty()) |
| 672 return false; | 685 return; |
| 673 | 686 |
| 674 if (evictContext) | 687 if (evictContext) |
| 675 m_contextEvictionManager->forciblyLoseOldestContext("WARNING: WebGL cont
exts have exceeded the maximum allowed backbuffer area. Oldest context will be l
ost."); | 688 m_contextEvictionManager->forciblyLoseOldestContext("WARNING: WebGL cont
exts have exceeded the maximum allowed backbuffer area. Oldest context will be l
ost."); |
| 676 | 689 |
| 677 if (adjustedSize != m_size) { | 690 if (adjustedSize != m_size) { |
| 678 do { | 691 do { |
| 679 // resize multisample FBO | 692 // resize multisample FBO |
| 680 if (!resizeMultisampleFramebuffer(adjustedSize) || !resizeFramebuffe
r(adjustedSize)) { | 693 if (!resizeMultisampleFramebuffer(adjustedSize) || !resizeFramebuffe
r(adjustedSize)) { |
| 681 adjustedSize.scale(s_resourceAdjustedRatio); | 694 adjustedSize.scale(s_resourceAdjustedRatio); |
| 682 continue; | 695 continue; |
| 683 } | 696 } |
| 684 break; | 697 break; |
| 685 } while (!adjustedSize.isEmpty()); | 698 } while (!adjustedSize.isEmpty()); |
| 686 | 699 |
| 687 setSize(adjustedSize); | 700 setSize(adjustedSize); |
| 688 | 701 |
| 689 if (adjustedSize.isEmpty()) | 702 if (adjustedSize.isEmpty()) |
| 690 return false; | 703 return; |
| 691 } | 704 } |
| 692 | 705 |
| 693 m_context->disable(GL_SCISSOR_TEST); | 706 m_context->disable(GL_SCISSOR_TEST); |
| 694 m_context->clearColor(0, 0, 0, 0); | 707 m_context->clearColor(0, 0, 0, 0); |
| 695 m_context->colorMask(true, true, true, true); | 708 m_context->colorMask(true, true, true, true); |
| 696 | 709 |
| 697 GLbitfield clearMask = GL_COLOR_BUFFER_BIT; | 710 GLbitfield clearMask = GL_COLOR_BUFFER_BIT; |
| 698 if (m_attributes.depth) { | 711 if (m_attributes.depth) { |
| 699 m_context->clearDepth(1.0f); | 712 m_context->clearDepth(1.0f); |
| 700 clearMask |= GL_DEPTH_BUFFER_BIT; | 713 clearMask |= GL_DEPTH_BUFFER_BIT; |
| 701 m_context->depthMask(true); | 714 m_context->depthMask(true); |
| 702 } | 715 } |
| 703 if (m_attributes.stencil) { | 716 if (m_attributes.stencil) { |
| 704 m_context->clearStencil(0); | 717 m_context->clearStencil(0); |
| 705 clearMask |= GL_STENCIL_BUFFER_BIT; | 718 clearMask |= GL_STENCIL_BUFFER_BIT; |
| 706 m_context->stencilMaskSeparate(GL_FRONT, 0xFFFFFFFF); | 719 m_context->stencilMaskSeparate(GL_FRONT, 0xFFFFFFFF); |
| 707 } | 720 } |
| 708 | 721 |
| 709 clearFramebuffers(clearMask); | 722 clearFramebuffers(clearMask); |
| 710 return true; | |
| 711 } | 723 } |
| 712 | 724 |
| 713 void DrawingBuffer::commit(long x, long y, long width, long height) | 725 void DrawingBuffer::commit(long x, long y, long width, long height) |
| 714 { | 726 { |
| 727 if (!m_context) |
| 728 return; |
| 729 |
| 715 if (width < 0) | 730 if (width < 0) |
| 716 width = m_size.width(); | 731 width = m_size.width(); |
| 717 if (height < 0) | 732 if (height < 0) |
| 718 height = m_size.height(); | 733 height = m_size.height(); |
| 719 | 734 |
| 720 m_context->makeContextCurrent(); | 735 m_context->makeContextCurrent(); |
| 721 | 736 |
| 722 if (m_multisampleFBO && !m_contentsChangeCommitted) { | 737 if (m_multisampleFBO && !m_contentsChangeCommitted) { |
| 723 m_context->bindFramebuffer(GL_READ_FRAMEBUFFER_ANGLE, m_multisampleFBO); | 738 m_context->bindFramebuffer(GL_READ_FRAMEBUFFER_ANGLE, m_multisampleFBO); |
| 724 m_context->bindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, m_fbo); | 739 m_context->bindFramebuffer(GL_DRAW_FRAMEBUFFER_ANGLE, m_fbo); |
| 725 | 740 |
| 726 if (m_scissorEnabled) | 741 if (m_scissorEnabled) |
| 727 m_context->disable(GL_SCISSOR_TEST); | 742 m_context->disable(GL_SCISSOR_TEST); |
| 728 | 743 |
| 729 // Use NEAREST, because there is no scale performed during the blit. | 744 // Use NEAREST, because there is no scale performed during the blit. |
| 730 m_context->blitFramebufferCHROMIUM(x, y, width, height, x, y, width, hei
ght, GL_COLOR_BUFFER_BIT, GL_NEAREST); | 745 m_context->blitFramebufferCHROMIUM(x, y, width, height, x, y, width, hei
ght, GL_COLOR_BUFFER_BIT, GL_NEAREST); |
| 731 | 746 |
| 732 if (m_scissorEnabled) | 747 if (m_scissorEnabled) |
| 733 m_context->enable(GL_SCISSOR_TEST); | 748 m_context->enable(GL_SCISSOR_TEST); |
| 734 } | 749 } |
| 735 | 750 |
| 736 m_context->bindFramebuffer(GL_FRAMEBUFFER, m_fbo); | 751 m_context->bindFramebuffer(GL_FRAMEBUFFER, m_fbo); |
| 737 m_contentsChangeCommitted = true; | 752 m_contentsChangeCommitted = true; |
| 738 } | 753 } |
| 739 | 754 |
| 740 void DrawingBuffer::restoreFramebufferBinding() | 755 void DrawingBuffer::restoreFramebufferBinding() |
| 741 { | 756 { |
| 742 if (!m_framebufferBinding) | 757 if (!m_context || !m_framebufferBinding) |
| 743 return; | 758 return; |
| 744 | 759 |
| 745 m_context->bindFramebuffer(GL_FRAMEBUFFER, m_framebufferBinding); | 760 m_context->bindFramebuffer(GL_FRAMEBUFFER, m_framebufferBinding); |
| 746 } | 761 } |
| 747 | 762 |
| 748 bool DrawingBuffer::multisample() const | 763 bool DrawingBuffer::multisample() const |
| 749 { | 764 { |
| 750 return m_multisampleMode != None; | 765 return m_multisampleMode != None; |
| 751 } | 766 } |
| 752 | 767 |
| 753 void DrawingBuffer::bind() | 768 void DrawingBuffer::bind() |
| 754 { | 769 { |
| 770 if (!m_context) |
| 771 return; |
| 772 |
| 755 m_context->bindFramebuffer(GL_FRAMEBUFFER, m_multisampleFBO ? m_multisampleF
BO : m_fbo); | 773 m_context->bindFramebuffer(GL_FRAMEBUFFER, m_multisampleFBO ? m_multisampleF
BO : m_fbo); |
| 756 } | 774 } |
| 757 | 775 |
| 758 void DrawingBuffer::setPackAlignment(GLint param) | 776 void DrawingBuffer::setPackAlignment(GLint param) |
| 759 { | 777 { |
| 760 m_packAlignment = param; | 778 m_packAlignment = param; |
| 761 } | 779 } |
| 762 | 780 |
| 763 void DrawingBuffer::paintRenderingResultsToCanvas(ImageBuffer* imageBuffer) | 781 void DrawingBuffer::paintRenderingResultsToCanvas(ImageBuffer* imageBuffer) |
| 764 { | 782 { |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 876 } | 894 } |
| 877 } | 895 } |
| 878 | 896 |
| 879 void DrawingBuffer::texImage2DResourceSafe(GLenum target, GLint level, GLenum in
ternalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum
type, GLint unpackAlignment) | 897 void DrawingBuffer::texImage2DResourceSafe(GLenum target, GLint level, GLenum in
ternalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum
type, GLint unpackAlignment) |
| 880 { | 898 { |
| 881 ASSERT(unpackAlignment == 1 || unpackAlignment == 2 || unpackAlignment == 4
|| unpackAlignment == 8); | 899 ASSERT(unpackAlignment == 1 || unpackAlignment == 2 || unpackAlignment == 4
|| unpackAlignment == 8); |
| 882 m_context->texImage2D(target, level, internalformat, width, height, border,
format, type, 0); | 900 m_context->texImage2D(target, level, internalformat, width, height, border,
format, type, 0); |
| 883 } | 901 } |
| 884 | 902 |
| 885 } // namespace WebCore | 903 } // namespace WebCore |
| OLD | NEW |