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