Changeset 100032 in webkit
- Timestamp:
- Nov 11, 2011 2:55:11 PM (12 years ago)
- Location:
- trunk/Source
- Files:
-
- 19 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r100030 r100032 1 2011-11-11 Jeff Timanus <twiz@chromium.org> 2 3 [chromium] Patch that implementing the changes required to allow WebGL 4 to share its backing store directly with the compositor. 5 WebGL rendering contexts create and render to FBOs managed by a 6 DrawingBuffer instance. All PlatformLayer lifetime management is 7 performed by the DrawingBuffer. 8 Changes are only relevant to Chromium ports. Functionality is 9 unchanged for other ports. 10 https://bugs.webkit.org/show_bug.cgi?id=53201 11 12 Reviewed by Stephen White. 13 14 * html/canvas/WebGLRenderingContext.cpp: Construct a DrawingBuffer 15 during initialization, and forward all framebuffer management calls to 16 it. 17 (WebCore::WebGLRenderingContext::create): 18 (WebCore::WebGLRenderingContext::WebGLRenderingContext): 19 (WebCore::WebGLRenderingContext::initializeNewContext): 20 (WebCore::WebGLRenderingContext::markContextChanged): 21 (WebCore::WebGLRenderingContext::clearIfComposited): 22 (WebCore::WebGLRenderingContext::paintRenderingResultsToCanvas): 23 (WebCore::WebGLRenderingContext::paintRenderingResultsToImageData): 24 (WebCore::WebGLRenderingContext::reshape): 25 (WebCore::WebGLRenderingContext::drawingBufferWidth): 26 (WebCore::WebGLRenderingContext::drawingBufferHeight): 27 (WebCore::WebGLRenderingContext::bindFramebuffer): 28 (WebCore::WebGLRenderingContext::copyTexImage2D): 29 (WebCore::WebGLRenderingContext::copyTexSubImage2D): 30 (WebCore::WebGLRenderingContext::deleteFramebuffer): 31 (WebCore::WebGLRenderingContext::disable): 32 (WebCore::WebGLRenderingContext::enable): 33 (WebCore::WebGLRenderingContext::readPixels): 34 (WebCore::WebGLRenderingContext::platformLayer): 35 (WebCore::WebGLRenderingContext::getBoundFramebufferWidth): 36 (WebCore::WebGLRenderingContext::getBoundFramebufferHeight): 37 (WebCore::WebGLRenderingContext::maybeRestoreContext): 38 * html/canvas/WebGLRenderingContext.h: 39 * platform/graphics/GraphicsContext3D.cpp: 40 * platform/graphics/GraphicsContext3D.h: WebGLLayerChromium instances 41 are no longer tracked by GraphicsContext3D. Callers can now pass a 42 DrawingBuffer instance to provide access to the WebGLLayerChromium data. 43 * platform/graphics/chromium/DrawingBufferChromium.cpp: 44 (WebCore::generateColorTexture): 45 (WebCore::DrawingBuffer::DrawingBuffer): 46 (WebCore::DrawingBuffer::initialize): 47 (WebCore::DrawingBuffer::publishToPlatformLayer): 48 (WebCore::DrawingBuffer::platformLayer): 49 (WebCore::DrawingBuffer::platformColorBuffer): 50 (WebCore::DrawingBuffer::framebuffer): 51 (WebCore::DrawingBuffer::markContextChanged): 52 (WebCore::DrawingBuffer::paintCompositedResultsToCanvas): 53 * platform/graphics/chromium/WebGLLayerChromium.cpp: 54 (WebCore::WebGLLayerChromium::WebGLLayerChromium): 55 (WebCore::WebGLLayerChromium::~WebGLLayerChromium): 56 (WebCore::WebGLLayerChromium::drawsContent): 57 (WebCore::WebGLLayerChromium::updateCompositorResources): 58 (WebCore::WebGLLayerChromium::paintRenderedResultsToCanvas): 59 (WebCore::WebGLLayerChromium::contentChanged): 60 (WebCore::WebGLLayerChromium::setDrawingBuffer): 61 (WebCore::WebGLLayerChromium::context): 62 * platform/graphics/chromium/WebGLLayerChromium.h: WebGLLayerChromium instances 63 have a raw reference to their owning DrawingBuffer. This reference is set to NULL on 64 destruction of the DrawingBuffer. This follows the old code, which had the WebGLLayerChromium 65 refer rawly to a GraphicsContext3D instance, which was also revoked during tear-down of the 66 GraphicsContext3D. 67 (WebCore::WebGLLayerChromium::drawingBuffer): 68 * platform/graphics/efl/GraphicsContext3DEfl.cpp: 69 (WebCore::GraphicsContext3D::paintRenderingResultsToCanvas): 70 (WebCore::GraphicsContext3D::paintRenderingResultsToImageData): 71 * platform/graphics/gpu/DrawingBuffer.cpp: The DrawingBuffer is now the 72 central point between the GraphicsContext3D, WebGLRenderingContext, and 73 WebGLLayerChromium classes. GraphicsContext3D, and WebGLLayerChromium only 74 depend on the DrawingBuffer interface. 75 (WebCore::DrawingBuffer::create): 76 (WebCore::DrawingBuffer::clear): 77 (WebCore::DrawingBuffer::clearFramebuffer): 78 (WebCore::DrawingBuffer::reset): 79 (WebCore::DrawingBuffer::commit): 80 (WebCore::DrawingBuffer::multisample): 81 (WebCore::DrawingBuffer::paintRenderingResultsToImageData): 82 (WebCore::DrawingBuffer::discardResources): 83 * platform/graphics/gpu/DrawingBuffer.h: 84 (WebCore::DrawingBuffer::setScissorEnabled): 85 * platform/graphics/gpu/mac/DrawingBufferMac.mm: 86 (WebCore::DrawingBuffer::DrawingBuffer): 87 * platform/graphics/gpu/qt/DrawingBufferQt.cpp: 88 (WebCore::DrawingBuffer::DrawingBuffer): 89 * platform/graphics/opengl/GraphicsContext3DOpenGL.cpp: 90 (WebCore::GraphicsContext3D::paintRenderingResultsToCanvas): 91 (WebCore::GraphicsContext3D::paintRenderingResultsToImageData): 92 * platform/graphics/qt/GraphicsContext3DQt.cpp: 93 (WebCore::GraphicsContext3D::paintRenderingResultsToCanvas): 94 (WebCore::GraphicsContext3D::paintRenderingResultsToImageData): 95 1 96 2011-11-11 Darin Adler <darin@apple.com> 2 97 -
trunk/Source/WebCore/html/canvas/WebGLRenderingContext.cpp
r99645 r100032 367 367 368 368 attributes.noExtensions = true; 369 #if PLATFORM(CHROMIUM) 370 attributes.shareResources = true; 371 #else 369 372 attributes.shareResources = false; 373 #endif 374 370 375 371 376 RefPtr<GraphicsContext3D> context(GraphicsContext3D::create(attributes, hostWindow)); … … 383 388 : CanvasRenderingContext(passedCanvas) 384 389 , m_context(context) 390 , m_drawingBuffer(0) 385 391 , m_restoreAllowed(false) 386 392 , m_restoreTimer(this) … … 390 396 { 391 397 ASSERT(m_context); 398 399 #if PLATFORM(CHROMIUM) 400 // Create the DrawingBuffer and initialize the platform layer. 401 m_drawingBuffer = DrawingBuffer::create(m_context.get(), IntSize(canvas()->width(), canvas()->height()), !m_attributes.preserveDrawingBuffer); 402 #endif 403 404 if (m_drawingBuffer) 405 m_drawingBuffer->bind(); 406 392 407 setupFlags(); 393 408 initializeNewContext(); … … 455 470 initVertexAttrib0(); 456 471 472 if (m_drawingBuffer) 473 m_drawingBuffer->reset(IntSize(canvas()->width(), canvas()->height())); 474 457 475 m_context->reshape(canvas()->width(), canvas()->height()); 458 476 m_context->viewport(0, 0, canvas()->width(), canvas()->height()); … … 495 513 if (m_framebufferBinding) 496 514 return; 515 497 516 m_context->markContextChanged(); 517 498 518 m_layerCleared = false; 499 519 #if USE(ACCELERATED_COMPOSITING) … … 525 545 bool combinedClear = mask && !m_scissorEnabled; 526 546 527 if (m_framebufferBinding) 528 m_context->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, 0); 547 if (m_framebufferBinding) { 548 if (m_drawingBuffer) 549 m_drawingBuffer->bind(); 550 else 551 m_context->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, 0); 552 } 529 553 m_context->disable(GraphicsContext3D::SCISSOR_TEST); 530 554 if (combinedClear && (mask & GraphicsContext3D::COLOR_BUFFER_BIT)) … … 582 606 if (m_context->layerComposited() && !m_attributes.preserveDrawingBuffer) { 583 607 m_context->paintCompositedResultsToCanvas(this); 608 609 #if USE(ACCELERATED_COMPOSITING) && PLATFORM(CHROMIUM) 610 if (m_drawingBuffer) 611 m_drawingBuffer->paintCompositedResultsToCanvas(this); 612 #endif 613 584 614 canvas()->makePresentationCopy(); 585 615 } else 586 616 canvas()->clearPresentationCopy(); 587 617 clearIfComposited(); 618 588 619 if (!m_markedCanvasDirty && !m_layerCleared) 589 620 return; 621 590 622 canvas()->clearCopiedImage(); 591 623 m_markedCanvasDirty = false; 592 m_context->paintRenderingResultsToCanvas(this); 624 625 if (m_drawingBuffer) 626 m_drawingBuffer->commit(); 627 m_context->paintRenderingResultsToCanvas(this, m_drawingBuffer.get()); 628 629 if (m_drawingBuffer) { 630 if (m_framebufferBinding) 631 m_context->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, objectOrZero(m_framebufferBinding.get())); 632 else 633 m_drawingBuffer->bind(); 634 } 593 635 } 594 636 … … 596 638 { 597 639 clearIfComposited(); 598 return m_context->paintRenderingResultsToImageData(); 640 if (m_drawingBuffer) 641 m_drawingBuffer->commit(); 642 RefPtr<ImageData> imageData = m_context->paintRenderingResultsToImageData(m_drawingBuffer.get()); 643 644 if (m_drawingBuffer) { 645 if (m_framebufferBinding) 646 m_context->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, objectOrZero(m_framebufferBinding.get())); 647 else 648 m_drawingBuffer->bind(); 649 } 650 651 return imageData; 599 652 } 600 653 … … 628 681 // We don't have to mark the canvas as dirty, since the newly created image buffer will also start off 629 682 // clear (and this matches what reshape will do). 630 m_context->reshape(width, height); 683 if (m_drawingBuffer) 684 m_drawingBuffer->reset(IntSize(width, height)); 685 else 686 m_context->reshape(width, height); 631 687 } 632 688 633 689 int WebGLRenderingContext::drawingBufferWidth() const 634 690 { 691 if (m_drawingBuffer) 692 return m_drawingBuffer->size().width(); 693 635 694 return m_context->getInternalFramebufferSize().width(); 636 695 } … … 638 697 int WebGLRenderingContext::drawingBufferHeight() const 639 698 { 699 if (m_drawingBuffer) 700 return m_drawingBuffer->size().height(); 701 640 702 return m_context->getInternalFramebufferSize().height(); 641 703 } … … 759 821 } 760 822 m_framebufferBinding = buffer; 761 m_context->bindFramebuffer(target, objectOrZero(buffer)); 823 if (!m_framebufferBinding && m_drawingBuffer) { 824 // Instead of binding fb 0, bind the drawing buffer. 825 m_drawingBuffer->bind(); 826 } else 827 m_context->bindFramebuffer(target, objectOrZero(buffer)); 762 828 if (buffer) 763 829 buffer->setHasEverBeenBound(); … … 1098 1164 } 1099 1165 clearIfComposited(); 1100 if (isResourceSafe()) 1166 if (isResourceSafe()) { 1167 // Commit DrawingBuffer if needed (e.g., for multisampling) 1168 if (!m_framebufferBinding && m_drawingBuffer) 1169 m_drawingBuffer->commit(); 1170 1101 1171 m_context->copyTexImage2D(target, level, internalformat, x, y, width, height, border); 1102 else { 1172 1173 // Restore DrawingBuffer if needed 1174 if (!m_framebufferBinding && m_drawingBuffer) 1175 m_drawingBuffer->bind(); 1176 } else { 1177 // Commit DrawingBuffer if needed (e.g., for multisampling) 1178 if (!m_framebufferBinding && m_drawingBuffer) 1179 m_drawingBuffer->commit(); 1180 1103 1181 GC3Dint clippedX, clippedY; 1104 1182 GC3Dsizei clippedWidth, clippedHeight; … … 1112 1190 } else 1113 1191 m_context->copyTexImage2D(target, level, internalformat, x, y, width, height, border); 1192 1193 // Restore DrawingBuffer if needed 1194 if (!m_framebufferBinding && m_drawingBuffer) 1195 m_drawingBuffer->bind(); 1114 1196 } 1115 1197 // FIXME: if the framebuffer is not complete, none of the below should be executed. … … 1143 1225 clearIfComposited(); 1144 1226 if (isResourceSafe()) 1227 // Commit DrawingBuffer if needed (e.g., for multisampling) 1228 if (!m_framebufferBinding && m_drawingBuffer) 1229 m_drawingBuffer->commit(); 1230 1145 1231 m_context->copyTexSubImage2D(target, level, xoffset, yoffset, x, y, width, height); 1232 1233 // Restore DrawingBuffer if needed 1234 if (!m_framebufferBinding && m_drawingBuffer) 1235 m_drawingBuffer->bind(); 1146 1236 else { 1147 1237 GC3Dint clippedX, clippedY; … … 1167 1257 m_context->texSubImage2D(target, level, xoffset, yoffset, width, height, format, type, zero.get()); 1168 1258 if (clippedWidth > 0 && clippedHeight > 0) { 1259 // Commit DrawingBuffer if needed (e.g., for multisampling) 1260 if (!m_framebufferBinding && m_drawingBuffer) 1261 m_drawingBuffer->commit(); 1262 1169 1263 m_context->copyTexSubImage2D(target, level, xoffset + clippedX - x, yoffset + clippedY - y, 1170 1264 clippedX, clippedY, clippedWidth, clippedHeight); 1265 1266 // Restore DrawingBuffer if needed 1267 if (!m_framebufferBinding && m_drawingBuffer) 1268 m_drawingBuffer->bind(); 1171 1269 } 1172 } else 1270 } else { 1271 // Commit DrawingBuffer if needed (e.g., for multisampling) 1272 if (!m_framebufferBinding && m_drawingBuffer) 1273 m_drawingBuffer->commit(); 1274 1173 1275 m_context->copyTexSubImage2D(target, level, xoffset, yoffset, x, y, width, height); 1276 1277 // Restore DrawingBuffer if needed 1278 if (!m_framebufferBinding && m_drawingBuffer) 1279 m_drawingBuffer->bind(); 1280 } 1174 1281 } 1175 1282 cleanupAfterGraphicsCall(false); … … 1288 1395 m_framebufferBinding = 0; 1289 1396 // Have to call bindFramebuffer here to bind back to internal fbo. 1290 m_context->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, 0); 1397 if (m_drawingBuffer) 1398 m_drawingBuffer->bind(); 1399 else 1400 m_context->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, 0); 1291 1401 } 1292 1402 } … … 1375 1485 if (isContextLost() || !validateCapability(cap)) 1376 1486 return; 1377 if (cap == GraphicsContext3D::SCISSOR_TEST) 1487 if (cap == GraphicsContext3D::SCISSOR_TEST) { 1378 1488 m_scissorEnabled = false; 1489 if (m_drawingBuffer) 1490 m_drawingBuffer->setScissorEnabled(m_scissorEnabled); 1491 } 1379 1492 m_context->disable(cap); 1380 1493 cleanupAfterGraphicsCall(false); … … 1717 1830 if (isContextLost() || !validateCapability(cap)) 1718 1831 return; 1719 if (cap == GraphicsContext3D::SCISSOR_TEST) 1832 if (cap == GraphicsContext3D::SCISSOR_TEST) { 1720 1833 m_scissorEnabled = true; 1834 if (m_drawingBuffer) 1835 m_drawingBuffer->setScissorEnabled(m_scissorEnabled); 1836 } 1721 1837 m_context->enable(cap); 1722 1838 cleanupAfterGraphicsCall(false); … … 2925 3041 clearIfComposited(); 2926 3042 void* data = pixels->baseAddress(); 3043 3044 // Commit DrawingBuffer if needed (e.g., for multisampling) 3045 if (!m_framebufferBinding && m_drawingBuffer) 3046 m_drawingBuffer->commit(); 3047 2927 3048 m_context->readPixels(x, y, width, height, format, type, data); 3049 3050 // Restore DrawingBuffer if needed 3051 if (!m_framebufferBinding && m_drawingBuffer) 3052 m_drawingBuffer->bind(); 3053 2928 3054 #if OS(DARWIN) 2929 3055 // FIXME: remove this section when GL driver bug on Mac is fixed, i.e., … … 3976 4102 maybeRestoreContext(SyntheticLostContext); 3977 4103 } 4104 4105 #if USE(ACCELERATED_COMPOSITING) 4106 PlatformLayer* WebGLRenderingContext::platformLayer() const 4107 { 4108 #if PLATFORM(CHROMIUM) 4109 if (m_drawingBuffer) 4110 return m_drawingBuffer->platformLayer(); 4111 #endif 4112 4113 return m_context->platformLayer(); 4114 } 4115 #endif 3978 4116 3979 4117 void WebGLRenderingContext::removeObject(WebGLObject* object) … … 4168 4306 if (m_framebufferBinding && m_framebufferBinding->object()) 4169 4307 return m_framebufferBinding->getWidth(); 4170 return m_ context->getInternalFramebufferSize().width();4308 return m_drawingBuffer ? m_drawingBuffer->size().width() : m_context->getInternalFramebufferSize().width(); 4171 4309 } 4172 4310 … … 4175 4313 if (m_framebufferBinding && m_framebufferBinding->object()) 4176 4314 return m_framebufferBinding->getHeight(); 4177 return m_ context->getInternalFramebufferSize().height();4315 return m_drawingBuffer ? m_drawingBuffer->size().height() : m_context->getInternalFramebufferSize().height(); 4178 4316 } 4179 4317 … … 4881 5019 } 4882 5020 5021 // Construct a new drawing buffer with the new GraphicsContext3D. 5022 if (m_drawingBuffer) { 5023 m_drawingBuffer->discardResources(); 5024 m_drawingBuffer = DrawingBuffer::create(m_context.get(), m_drawingBuffer->size(), !m_attributes.preserveDrawingBuffer); 5025 } 5026 4883 5027 m_context = context; 4884 5028 m_contextLost = false; -
trunk/Source/WebCore/html/canvas/WebGLRenderingContext.h
r99645 r100032 28 28 29 29 #include "CanvasRenderingContext.h" 30 #include "DrawingBuffer.h" 30 31 #include "Float32Array.h" 31 32 #include "GraphicsContext3D.h" … … 294 295 GraphicsContext3D* graphicsContext3D() const { return m_context.get(); } 295 296 #if USE(ACCELERATED_COMPOSITING) 296 virtual PlatformLayer* platformLayer() const { return m_context->platformLayer(); }297 virtual PlatformLayer* platformLayer() const; 297 298 #endif 298 299 … … 359 360 360 361 RefPtr<GraphicsContext3D> m_context; 362 363 // Optional structure for rendering to a DrawingBuffer, instead of directly 364 // to the back-buffer of m_context. 365 RefPtr<DrawingBuffer> m_drawingBuffer; 361 366 362 367 class WebGLRenderingContextRestoreTimer : public TimerBase { -
trunk/Source/WebCore/platform/graphics/GraphicsContext3D.cpp
r95901 r100032 57 57 58 58 } // anonymous namespace 59 60 61 PassRefPtr<DrawingBuffer> GraphicsContext3D::createDrawingBuffer(const IntSize& size)62 {63 return DrawingBuffer::create(this, size);64 }65 59 66 60 bool GraphicsContext3D::texImage2DResourceSafe(GC3Denum target, GC3Dint level, GC3Denum internalformat, GC3Dsizei width, GC3Dsizei height, GC3Dint border, GC3Denum format, GC3Denum type, GC3Dint unpackAlignment) -
trunk/Source/WebCore/platform/graphics/GraphicsContext3D.h
r95901 r100032 501 501 void makeContextCurrent(); 502 502 503 PassRefPtr<DrawingBuffer> createDrawingBuffer(const IntSize& = IntSize());504 505 503 #if PLATFORM(MAC) || PLATFORM(CHROMIUM) || PLATFORM(GTK) || PLATFORM(QT) 506 504 // With multisampling on, blit from multisampleFBO to regular FBO. … … 792 790 bool layerComposited() const; 793 791 794 void paintRenderingResultsToCanvas(CanvasRenderingContext* );795 PassRefPtr<ImageData> paintRenderingResultsToImageData( );792 void paintRenderingResultsToCanvas(CanvasRenderingContext*, DrawingBuffer*); 793 PassRefPtr<ImageData> paintRenderingResultsToImageData(DrawingBuffer*); 796 794 bool paintCompositedResultsToCanvas(CanvasRenderingContext*); 797 795 -
trunk/Source/WebCore/platform/graphics/chromium/DrawingBufferChromium.cpp
r95901 r100032 33 33 #include "DrawingBuffer.h" 34 34 35 #include "CanvasRenderingContext.h" 36 #include "Extensions3DChromium.h" 35 37 #include "GraphicsContext3D.h" 38 #include "WebGLLayerChromium.h" 36 39 37 40 namespace WebCore { … … 49 52 context->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_WRAP_T, GraphicsContext3D::CLAMP_TO_EDGE); 50 53 context->texImage2DResourceSafe(GraphicsContext3D::TEXTURE_2D, 0, GraphicsContext3D::RGBA, size.width(), size.height(), 0, GraphicsContext3D::RGBA, GraphicsContext3D::UNSIGNED_BYTE); 51 context->framebufferTexture2D(GraphicsContext3D::FRAMEBUFFER, GraphicsContext3D::COLOR_ATTACHMENT0, GraphicsContext3D::TEXTURE_2D, offscreenColorTexture, 0);52 54 53 55 return offscreenColorTexture; … … 57 59 const IntSize& size, 58 60 bool multisampleExtensionSupported, 59 bool packedDepthStencilExtensionSupported) 60 : m_context(context) 61 bool packedDepthStencilExtensionSupported, 62 bool separateBackingTexture) 63 : m_separateBackingTexture(separateBackingTexture) 64 , m_scissorEnabled(false) 65 , m_context(context) 61 66 , m_size(-1, -1) 62 67 , m_multisampleExtensionSupported(multisampleExtensionSupported) … … 64 69 , m_fbo(0) 65 70 , m_colorBuffer(0) 71 , m_backingColorBuffer(0) 66 72 , m_depthStencilBuffer(0) 67 73 , m_depthBuffer(0) … … 70 76 , m_multisampleColorBuffer(0) 71 77 { 72 m_fbo = context->createFramebuffer(); 73 context->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, m_fbo); 74 m_colorBuffer = generateColorTexture(context, size); 78 initialize(size); 79 } 80 81 DrawingBuffer::~DrawingBuffer() 82 { 83 if (m_platformLayer) 84 m_platformLayer->setDrawingBuffer(0); 85 86 if (!m_context) 87 return; 88 89 clear(); 90 } 91 92 void DrawingBuffer::initialize(const IntSize& size) 93 { 94 m_fbo = m_context->createFramebuffer(); 95 96 if (m_separateBackingTexture) 97 m_backingColorBuffer = generateColorTexture(m_context.get(), size); 98 99 m_context->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, m_fbo); 100 m_colorBuffer = generateColorTexture(m_context.get(), size); 101 m_context->framebufferTexture2D(GraphicsContext3D::FRAMEBUFFER, GraphicsContext3D::COLOR_ATTACHMENT0, GraphicsContext3D::TEXTURE_2D, m_colorBuffer, 0); 75 102 createSecondaryBuffers(); 76 103 if (!reset(size)) { … … 78 105 return; 79 106 } 80 }81 82 DrawingBuffer::~DrawingBuffer()83 {84 if (!m_context)85 return;86 87 clear();88 107 } 89 108 … … 94 113 return; 95 114 115 m_context->makeContextCurrent(); 96 116 if (multisample()) 97 117 commit(); 98 m_context->makeContextCurrent(); 118 119 if (m_separateBackingTexture) { 120 m_context->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, m_fbo); 121 m_context->bindTexture(GraphicsContext3D::TEXTURE_2D, m_backingColorBuffer); 122 unsigned colorFormat = m_context->getContextAttributes().alpha ? GraphicsContext3D::RGBA : GraphicsContext3D::RGB; 123 m_context->copyTexImage2D(GraphicsContext3D::TEXTURE_2D, 0, colorFormat, 0, 0, size().width(), size().height(), 0); 124 } 125 126 if (multisample()) 127 bind(); 128 99 129 m_context->flush(); 100 130 } … … 104 134 PlatformLayer* DrawingBuffer::platformLayer() 105 135 { 106 return 0; 136 if (!m_platformLayer) { 137 m_platformLayer = WebGLLayerChromium::create(0); 138 m_platformLayer->setDrawingBuffer(this); 139 } 140 141 return m_platformLayer.get(); 107 142 } 108 143 #endif … … 110 145 Platform3DObject DrawingBuffer::platformColorBuffer() const 111 146 { 112 return m_ colorBuffer;147 return m_separateBackingTexture ? m_backingColorBuffer : m_colorBuffer; 113 148 } 114 149 150 Platform3DObject DrawingBuffer::framebuffer() const 151 { 152 return m_fbo; 115 153 } 154 155 #if USE(ACCELERATED_COMPOSITING) 156 void DrawingBuffer::paintCompositedResultsToCanvas(CanvasRenderingContext* context) 157 { 158 if (m_platformLayer) 159 m_platformLayer->paintRenderedResultsToCanvas(context->canvas()->buffer()); 160 } 161 #endif 162 163 } -
trunk/Source/WebCore/platform/graphics/chromium/WebGLLayerChromium.cpp
r98471 r100032 35 35 #include "WebGLLayerChromium.h" 36 36 37 #include "DrawingBuffer.h" 37 38 #include "Extensions3DChromium.h" 38 39 #include "GraphicsContext3D.h" … … 49 50 WebGLLayerChromium::WebGLLayerChromium(CCLayerDelegate* delegate) 50 51 : CanvasLayerChromium(delegate) 51 , m_context(0)52 52 , m_textureChanged(true) 53 53 , m_textureUpdated(false) … … 57 57 WebGLLayerChromium::~WebGLLayerChromium() 58 58 { 59 if ( m_context&& layerTreeHost())60 layerTreeHost()->stopRateLimiter( m_context);59 if (context() && layerTreeHost()) 60 layerTreeHost()->stopRateLimiter(context()); 61 61 } 62 62 63 63 bool WebGLLayerChromium::drawsContent() const 64 64 { 65 return ( m_context && m_context->getExtensions()->getGraphicsResetStatusARB() == GraphicsContext3D::NO_ERROR);65 return (context() && context()->getExtensions()->getGraphicsResetStatusARB() == GraphicsContext3D::NO_ERROR); 66 66 } 67 67 … … 86 86 // Update the contents of the texture used by the compositor. 87 87 if (!m_dirtyRect.isEmpty() && m_textureUpdated) { 88 // prepareTexture copies the contents of the off-screen render target into the texture 89 // used by the compositor. 90 // 91 m_context->prepareTexture(); 92 m_context->markLayerComposited(); 88 // publishToPlatformLayer prepares the contents of the off-screen render target for use by the compositor. 89 drawingBuffer()->publishToPlatformLayer(); 90 context()->markLayerComposited(); 93 91 m_updateRect = FloatRect(FloatPoint(), bounds()); 94 92 resetNeedsDisplay(); … … 102 100 return false; 103 101 104 IntSize framebufferSize = m_context->getInternalFramebufferSize();102 IntSize framebufferSize = context()->getInternalFramebufferSize(); 105 103 ASSERT(layerRendererContext()); 106 104 … … 111 109 112 110 Extensions3DChromium* extensions = static_cast<Extensions3DChromium*>(layerRendererContext()->getExtensions()); 113 extensions->paintFramebufferToCanvas(framebuffer, framebufferSize.width(), framebufferSize.height(), ! m_context->getContextAttributes().premultipliedAlpha, imageBuffer);111 extensions->paintFramebufferToCanvas(framebuffer, framebufferSize.width(), framebufferSize.height(), !context()->getContextAttributes().premultipliedAlpha, imageBuffer); 114 112 layerRendererContext()->deleteFramebuffer(framebuffer); 115 113 return true; … … 122 120 // call rateLimitOffscreenContextCHROMIUM() to keep the context from getting too far ahead. 123 121 if (layerTreeHost()) 124 layerTreeHost()->startRateLimiter( m_context);122 layerTreeHost()->startRateLimiter(context()); 125 123 } 126 124 127 void WebGLLayerChromium::set Context(const GraphicsContext3D* context)125 void WebGLLayerChromium::setDrawingBuffer(DrawingBuffer* drawingBuffer) 128 126 { 129 bool contextChanged = (m_context != context); 127 bool drawingBufferChanged = (m_drawingBuffer != drawingBuffer); 128 m_drawingBuffer = drawingBuffer; 130 129 131 if (layerTreeHost() && contextChanged)132 layerTreeHost()->stopRateLimiter( m_context);130 if (layerTreeHost() && drawingBufferChanged) 131 layerTreeHost()->stopRateLimiter(context()); 133 132 134 m_context = const_cast<GraphicsContext3D*>(context); 135 136 if (!m_context) 133 if (!m_drawingBuffer) 137 134 return; 138 135 139 unsigned int textureId = m_ context->platformTexture();140 if (textureId != m_textureId || contextChanged) {136 unsigned int textureId = m_drawingBuffer->platformColorBuffer(); 137 if (textureId != m_textureId || drawingBufferChanged) { 141 138 m_textureChanged = true; 142 139 m_textureUpdated = true; 143 140 } 144 141 m_textureId = textureId; 145 GraphicsContext3D::Attributes attributes = m_context->getContextAttributes();142 GraphicsContext3D::Attributes attributes = context()->getContextAttributes(); 146 143 m_hasAlpha = attributes.alpha; 147 144 m_premultipliedAlpha = attributes.premultipliedAlpha; 145 } 146 147 GraphicsContext3D* WebGLLayerChromium::context() const 148 { 149 if (drawingBuffer()) 150 return drawingBuffer()->graphicsContext3D().get(); 151 152 return 0; 148 153 } 149 154 … … 158 163 159 164 } 165 160 166 #endif // USE(ACCELERATED_COMPOSITING) -
trunk/Source/WebCore/platform/graphics/chromium/WebGLLayerChromium.h
r98471 r100032 36 36 37 37 #include "CanvasLayerChromium.h" 38 #include "DrawingBuffer.h" 38 39 39 40 namespace WebCore { … … 54 55 bool paintRenderedResultsToCanvas(ImageBuffer*); 55 56 56 void setContext(const GraphicsContext3D* context); 57 GraphicsContext3D* context() { return m_context; } 57 GraphicsContext3D* context() const; 58 58 59 void setDrawingBuffer(DrawingBuffer*); 60 DrawingBuffer* drawingBuffer() const { return m_drawingBuffer; } 59 61 private: 60 62 explicit WebGLLayerChromium(CCLayerDelegate*); … … 63 65 GraphicsContext3D* layerRendererContext(); 64 66 65 // GraphicsContext3D::platformLayer has a side-effect of assigning itself66 // to the layer. Because of that GraphicsContext3D's destructor will reset67 // layer's context to 0.68 GraphicsContext3D* m_context;69 67 bool m_textureChanged; 70 68 bool m_textureUpdated; 69 70 // The DrawingBuffer holding the WebGL contents for this layer. 71 // A reference is not held here, because the DrawingBuffer already holds 72 // a reference to the WebGLLayerChromium. 73 DrawingBuffer* m_drawingBuffer; 71 74 }; 72 75 -
trunk/Source/WebCore/platform/graphics/efl/GraphicsContext3DEfl.cpp
r95901 r100032 727 727 } 728 728 729 void GraphicsContext3D::paintRenderingResultsToCanvas(CanvasRenderingContext* context) 730 { 731 notImplemented(); 732 } 733 734 PassRefPtr<ImageData> GraphicsContext3D::paintRenderingResultsToImageData() 735 { 729 void GraphicsContext3D::paintRenderingResultsToCanvas(CanvasRenderingContext* context, DrawingBuffer* drawingBuffer) 730 { 731 // DrawingBuffer support only implemented in Chromium ports. 732 ASSERT(!drawingBuffer); 733 notImplemented(); 734 } 735 736 PassRefPtr<ImageData> GraphicsContext3D::paintRenderingResultsToImageData(DrawingBuffer* drawingBuffer) 737 { 738 // DrawingBuffer support only implemented in Chromium ports. 739 ASSERT(!drawingBuffer); 736 740 notImplemented(); 737 741 RefPtr<ImageData> imageData = ImageData::create(IntSize(1, 1)); -
trunk/Source/WebCore/platform/graphics/gpu/DrawingBuffer.cpp
r95901 r100032 36 36 37 37 #include "Extensions3D.h" 38 #include "GraphicsContext3D.h" 39 #include "ImageData.h" 38 40 39 41 namespace WebCore { … … 49 51 static int s_currentResourceUsePixels = 0; 50 52 51 PassRefPtr<DrawingBuffer> DrawingBuffer::create(GraphicsContext3D* context, const IntSize& size )53 PassRefPtr<DrawingBuffer> DrawingBuffer::create(GraphicsContext3D* context, const IntSize& size, bool separateBackingTexture) 52 54 { 53 55 Extensions3D* extensions = context->getExtensions(); … … 61 63 if (packedDepthStencilSupported) 62 64 extensions->ensureEnabled("GL_OES_packed_depth_stencil"); 63 RefPtr<DrawingBuffer> drawingBuffer = adoptRef(new DrawingBuffer(context, size, multisampleSupported, packedDepthStencilSupported ));65 RefPtr<DrawingBuffer> drawingBuffer = adoptRef(new DrawingBuffer(context, size, multisampleSupported, packedDepthStencilSupported, separateBackingTexture)); 64 66 return (drawingBuffer->m_context) ? drawingBuffer.release() : 0; 65 67 } … … 77 79 m_context->deleteTexture(m_colorBuffer); 78 80 m_colorBuffer = 0; 81 } 82 83 if (m_backingColorBuffer) { 84 m_context->deleteTexture(m_backingColorBuffer); 85 m_backingColorBuffer = 0; 79 86 } 80 87 … … 167 174 unsigned int stencilMask = 0xffffffff; 168 175 unsigned char isScissorEnabled = false; 169 unsigned longclearMask = GraphicsContext3D::COLOR_BUFFER_BIT;176 unsigned clearMask = GraphicsContext3D::COLOR_BUFFER_BIT; 170 177 if (attributes.depth) { 171 178 m_context->getFloatv(GraphicsContext3D::DEPTH_CLEAR_VALUE, &clearDepth); … … 189 196 m_context->clearColor(0, 0, 0, 0); 190 197 m_context->clear(clearMask); 198 199 // The multisample fbo was just cleared, but we also need to clear the non-multisampled buffer too. 200 if (m_multisampleFBO) { 201 m_context->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, m_fbo); 202 m_context->clear(GraphicsContext3D::COLOR_BUFFER_BIT); 203 m_context->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, m_multisampleFBO); 204 } 205 191 206 m_context->clearColor(clearColor[0], clearColor[1], clearColor[2], clearColor[3]); 192 207 … … 234 249 m_size = newSize; 235 250 236 unsigned longinternalColorFormat, colorFormat, internalRenderbufferFormat;251 unsigned internalColorFormat, colorFormat, internalRenderbufferFormat; 237 252 if (attributes.alpha) { 238 253 internalColorFormat = GraphicsContext3D::RGBA; … … 251 266 252 267 m_context->getIntegerv(Extensions3D::MAX_SAMPLES, &maxSampleCount); 253 int sampleCount = std::min( 8, maxSampleCount);268 int sampleCount = std::min(4, maxSampleCount); 254 269 255 270 m_context->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, m_multisampleFBO); … … 270 285 271 286 m_context->bindTexture(GraphicsContext3D::TEXTURE_2D, m_colorBuffer); 272 273 287 m_context->texImage2D(GraphicsContext3D::TEXTURE_2D, 0, internalColorFormat, m_size.width(), m_size.height(), 0, colorFormat, GraphicsContext3D::UNSIGNED_BYTE, 0); 274 288 275 289 m_context->framebufferTexture2D(GraphicsContext3D::FRAMEBUFFER, GraphicsContext3D::COLOR_ATTACHMENT0, GraphicsContext3D::TEXTURE_2D, m_colorBuffer, 0); 290 291 // resize the backing color buffer 292 if (m_separateBackingTexture) { 293 m_context->bindTexture(GraphicsContext3D::TEXTURE_2D, m_backingColorBuffer); 294 m_context->texImage2D(GraphicsContext3D::TEXTURE_2D, 0, internalColorFormat, m_size.width(), m_size.height(), 0, colorFormat, GraphicsContext3D::UNSIGNED_BYTE, 0); 295 } 296 276 297 m_context->bindTexture(GraphicsContext3D::TEXTURE_2D, 0); 277 298 … … 294 315 if (!m_context) 295 316 return; 296 317 297 318 if (width < 0) 298 319 width = m_size.width(); 299 320 if (height < 0) 300 321 height = m_size.height(); 301 322 302 323 m_context->makeContextCurrent(); 303 324 304 325 if (m_multisampleFBO) { 305 326 m_context->bindFramebuffer(Extensions3D::READ_FRAMEBUFFER, m_multisampleFBO); 306 327 m_context->bindFramebuffer(Extensions3D::DRAW_FRAMEBUFFER, m_fbo); 307 m_context->getExtensions()->blitFramebuffer(x, y, width, height, x, y, width, height, GraphicsContext3D::COLOR_BUFFER_BIT, GraphicsContext3D::LINEAR); 308 } 309 328 329 if (m_scissorEnabled) 330 m_context->disable(GraphicsContext3D::SCISSOR_TEST); 331 332 // Use NEAREST, because there is no scale performed during the blit. 333 m_context->getExtensions()->blitFramebuffer(x, y, width, height, x, y, width, height, GraphicsContext3D::COLOR_BUFFER_BIT, GraphicsContext3D::NEAREST); 334 335 if (m_scissorEnabled) 336 m_context->enable(GraphicsContext3D::SCISSOR_TEST); 337 } 338 310 339 m_context->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, m_fbo); 340 } 341 342 bool DrawingBuffer::multisample() const 343 { 344 return m_context && m_context->getContextAttributes().antialias && m_multisampleExtensionSupported; 345 } 346 347 PassRefPtr<ImageData> DrawingBuffer::paintRenderingResultsToImageData() 348 { 349 return m_context->paintRenderingResultsToImageData(this); 350 } 351 352 void DrawingBuffer::discardResources() 353 { 354 m_colorBuffer = 0; 355 m_backingColorBuffer = 0; 356 m_multisampleColorBuffer = 0; 357 358 m_depthStencilBuffer = 0; 359 m_depthBuffer = 0; 360 361 m_stencilBuffer = 0; 362 363 m_multisampleFBO = 0; 364 m_fbo = 0; 311 365 } 312 366 -
trunk/Source/WebCore/platform/graphics/gpu/DrawingBuffer.h
r95901 r100032 34 34 #include "GraphicsContext3D.h" 35 35 #include "GraphicsLayer.h" 36 #include "GraphicsTypes3D.h" 36 37 #include "IntSize.h" 37 38 … … 44 45 45 46 namespace WebCore { 46 47 #if PLATFORM(CHROMIUM) && USE(ACCELERATED_COMPOSITING) 48 class Canvas2DLayerChromium; 47 class CanvasRenderingContext; 48 class GraphicsContext3D; 49 class ImageData; 50 #if PLATFORM(CHROMIUM) 51 class WebGLLayerChromium; 49 52 #endif 50 53 … … 53 56 class DrawingBuffer : public RefCounted<DrawingBuffer> { 54 57 public: 58 static PassRefPtr<DrawingBuffer> create(GraphicsContext3D*, const IntSize&, bool); 55 59 friend class GraphicsContext3D; 56 60 … … 76 80 // Copies the multisample color buffer to the normal color buffer and leaves m_fbo bound 77 81 void commit(long x = 0, long y = 0, long width = -1, long height = -1); 78 79 bool multisample() const { return m_context && m_context->getContextAttributes().antialias && m_multisampleExtensionSupported; } 80 82 83 // commit should copy the full multisample buffer, and not respect the 84 // current scissor bounds. Track the state of the scissor test so that it 85 // can be disabled during calls to commit. 86 void setScissorEnabled(bool scissorEnabled) { m_scissorEnabled = scissorEnabled; } 87 88 bool multisample() const; 89 81 90 Platform3DObject platformColorBuffer() const; 91 Platform3DObject framebuffer() const; 92 93 PassRefPtr<ImageData> paintRenderingResultsToImageData(); 94 95 // Immediately releases ownership of all resources. Call upon loss of the 96 // graphics context to prevent freeing invalid resources. 97 void discardResources(); 82 98 83 99 #if USE(ACCELERATED_COMPOSITING) 84 100 PlatformLayer* platformLayer(); 85 101 void publishToPlatformLayer(); 102 void paintCompositedResultsToCanvas(CanvasRenderingContext*); 86 103 #endif 87 104 … … 89 106 90 107 private: 91 static PassRefPtr<DrawingBuffer> create(GraphicsContext3D*, const IntSize&); 92 93 DrawingBuffer(GraphicsContext3D*, const IntSize&, bool multisampleExtensionSupported, bool packedDepthStencilExtensionSupported); 108 DrawingBuffer(GraphicsContext3D*, const IntSize&, bool multisampleExtensionSupported, 109 bool packedDepthStencilExtensionSupported, bool separateBackingTexture); 110 111 void initialize(const IntSize&); 112 113 bool m_separateBackingTexture; 114 bool m_scissorEnabled; 94 115 95 116 RefPtr<GraphicsContext3D> m_context; … … 99 120 Platform3DObject m_fbo; 100 121 Platform3DObject m_colorBuffer; 122 Platform3DObject m_backingColorBuffer; 101 123 102 124 // This is used when we have OES_packed_depth_stencil. … … 111 133 Platform3DObject m_multisampleColorBuffer; 112 134 135 #if PLATFORM(CHROMIUM) 136 RefPtr<WebGLLayerChromium> m_platformLayer; 137 #endif 138 113 139 #if PLATFORM(MAC) 114 140 RetainPtr<WebGLLayer> m_platformLayer; -
trunk/Source/WebCore/platform/graphics/gpu/mac/DrawingBufferMac.mm
r95901 r100032 40 40 const IntSize& size, 41 41 bool multisampleExtensionSupported, 42 bool packedDepthStencilExtensionSupported) 43 : m_context(context) 42 bool packedDepthStencilExtensionSupported, 43 bool separateBackingTexture) 44 : m_separateBackingTexture(separateBackingTexture) 45 , m_scissorEnabled(false) 46 , m_context(context) 44 47 , m_size(-1, -1) 45 48 , m_multisampleExtensionSupported(multisampleExtensionSupported) … … 53 56 , m_multisampleColorBuffer(0) 54 57 { 58 // Support for a separate backing texture has only been enabled for 59 // the chromium port. 60 ASSERT(!m_separateBackingTexture); 55 61 ASSERT(m_fbo); 56 62 if (!m_fbo) { -
trunk/Source/WebCore/platform/graphics/gpu/qt/DrawingBufferQt.cpp
r95901 r100032 35 35 const IntSize& size, 36 36 bool multisampleExtensionSupported, 37 bool packedDepthStencilExtensionSupported) 38 : m_context(context) 37 bool packedDepthStencilExtensionSupported, 38 bool separateBackingTexture) 39 : m_separateBackingTexture(separateBackingTexture) 40 , m_scissorEnabled(false) 41 , m_context(context) 39 42 , m_size(-1, -1) 40 43 , m_multisampleExtensionSupported(multisampleExtensionSupported) … … 48 51 , m_multisampleColorBuffer(0) 49 52 { 53 // Support for a separate backing texture has only been enabled for 54 // the chromium port. 55 ASSERT(!m_separateBackingTexture); 50 56 ASSERT(m_fbo); 51 57 if (!m_fbo) { … … 84 90 } 85 91 92 #if USE(ACCELERATED_COMPOSITING) 93 void DrawingBuffer::paintCompositedResultsToCanvas(CanvasRenderingContext* context) 94 { 95 } 96 #endif 97 86 98 } 87 99 -
trunk/Source/WebCore/platform/graphics/gtk/DrawingBufferGtk.cpp
r95901 r100032 77 77 } 78 78 79 #if USE(ACCELERATED_COMPOSITING) 80 void DrawingBuffer::paintCompositedResultsToCanvas(CanvasRenderingContext* context) 81 { 82 } 83 #endif 84 79 85 } 80 86 -
trunk/Source/WebCore/platform/graphics/opengl/GraphicsContext3DOpenGL.cpp
r95901 r100032 129 129 130 130 #if !PLATFORM(QT) 131 void GraphicsContext3D::paintRenderingResultsToCanvas(CanvasRenderingContext* context )131 void GraphicsContext3D::paintRenderingResultsToCanvas(CanvasRenderingContext* context, DrawingBuffer*) 132 132 { 133 133 HTMLCanvasElement* canvas = context->canvas(); … … 163 163 } 164 164 165 PassRefPtr<ImageData> GraphicsContext3D::paintRenderingResultsToImageData( )165 PassRefPtr<ImageData> GraphicsContext3D::paintRenderingResultsToImageData(DrawingBuffer*) 166 166 { 167 167 // Reading premultiplied alpha would involve unpremultiplying, which is -
trunk/Source/WebCore/platform/graphics/qt/GraphicsContext3DQt.cpp
r95901 r100032 421 421 } 422 422 423 void GraphicsContext3D::paintRenderingResultsToCanvas(CanvasRenderingContext* context )423 void GraphicsContext3D::paintRenderingResultsToCanvas(CanvasRenderingContext* context, DrawingBuffer*) 424 424 { 425 425 m_private->m_glWidget->makeCurrent(); … … 431 431 432 432 #if defined(QT_OPENGL_ES_2) 433 PassRefPtr<ImageData> GraphicsContext3D::paintRenderingResultsToImageData( )433 PassRefPtr<ImageData> GraphicsContext3D::paintRenderingResultsToImageData(DrawingBuffer*) 434 434 { 435 435 // FIXME: This needs to be implemented for proper non-premultiplied-alpha -
trunk/Source/WebKit/chromium/ChangeLog
r100011 r100032 1 2011-11-11 Jeff Timanus <twiz@chromium.org> 2 3 [chromium] Patch that implementing the changes required to allow WebGL 4 to share its backing store directly with the compositor. 5 WebGL rendering contexts create and render to FBOs managed by a 6 DrawingBuffer instance. All PlatformLayer lifetime management is 7 performed by the DrawingBuffer. 8 Changes are only relevant to Chromium ports. Functionality is 9 unchanged for other ports. 10 https://bugs.webkit.org/show_bug.cgi?id=53201 11 12 Reviewed by Stephen White. 13 14 * src/GraphicsContext3DChromium.cpp: GraphicsContext3DPrivate no longer caches 15 the WebGLLayerChromium instance. Instead, it is accessed via DrawingBuffer instances 16 passed as arguments to the necessary routines. 17 (WebCore::GraphicsContext3DPrivate::paintRenderingResultsToCanvas): 18 (WebCore::GraphicsContext3DPrivate::paintCompositedResultsToCanvas): 19 (WebCore::GraphicsContext3DPrivate::paintRenderingResultsToImageData): 20 (WebCore::GraphicsContext3D::~GraphicsContext3D): 21 (WebCore::GraphicsContext3D::platformLayer): 22 (WebCore::GraphicsContext3D::paintRenderingResultsToCanvas): 23 (WebCore::GraphicsContext3D::paintRenderingResultsToImageData): 24 * src/GraphicsContext3DPrivate.h: 25 1 26 2011-11-11 Sheriff Bot <webkit.review.bot@gmail.com> 2 27 -
trunk/Source/WebKit/chromium/src/GraphicsContext3DChromium.cpp
r99648 r100032 36 36 37 37 #include "CachedImage.h" 38 #include "WebGLLayerChromium.h"39 38 #include "CanvasRenderingContext.h" 40 39 #include "Chrome.h" 41 40 #include "ChromeClientImpl.h" 41 #include "DrawingBuffer.h" 42 42 #include "Extensions3DChromium.h" 43 43 #include "GraphicsContext3DPrivate.h" … … 164 164 } 165 165 166 void getDrawingParameters(DrawingBuffer* drawingBuffer, WebKit::WebGraphicsContext3D* graphicsContext3D, 167 Platform3DObject* frameBufferId, int* width, int* height) 168 { 169 if (drawingBuffer) { 170 *frameBufferId = drawingBuffer->framebuffer(); 171 *width = drawingBuffer->size().width(); 172 *height = drawingBuffer->size().height(); 173 } else { 174 *frameBufferId = 0; 175 *width = graphicsContext3D->width(); 176 *height = graphicsContext3D->height(); 177 } 178 } 179 166 180 } // anonymous namespace 167 181 … … 212 226 m_impl->prepareTexture(); 213 227 } 214 215 #if USE(ACCELERATED_COMPOSITING)216 WebGLLayerChromium* GraphicsContext3DPrivate::platformLayer()217 {218 #if USE(ACCELERATED_COMPOSITING)219 if (!m_compositingLayer)220 m_compositingLayer = WebGLLayerChromium::create(0);221 #endif222 return m_compositingLayer.get();223 }224 #endif225 228 226 229 void GraphicsContext3DPrivate::markContextChanged() … … 306 309 } 307 310 308 void GraphicsContext3DPrivate::paintRenderingResultsToCanvas(CanvasRenderingContext* context )311 void GraphicsContext3DPrivate::paintRenderingResultsToCanvas(CanvasRenderingContext* context, DrawingBuffer* drawingBuffer) 309 312 { 310 313 ImageBuffer* imageBuffer = context->canvas()->buffer(); 311 paintFramebufferToCanvas(0, m_impl->width(), m_impl->height(), !m_impl->getContextAttributes().premultipliedAlpha, imageBuffer); 314 Platform3DObject framebufferId; 315 int width, height; 316 getDrawingParameters(drawingBuffer, m_impl.get(), &framebufferId, &width, &height); 317 paintFramebufferToCanvas(framebufferId, width, height, !m_impl->getContextAttributes().premultipliedAlpha, imageBuffer); 312 318 } 313 319 314 320 bool GraphicsContext3DPrivate::paintCompositedResultsToCanvas(CanvasRenderingContext* context) 315 321 { 316 #if USE(ACCELERATED_COMPOSITING)317 if (platformLayer())318 return platformLayer()->paintRenderedResultsToCanvas(context->canvas()->buffer());319 #endif320 322 return false; 321 323 } 322 324 323 PassRefPtr<ImageData> GraphicsContext3DPrivate::paintRenderingResultsToImageData( )325 PassRefPtr<ImageData> GraphicsContext3DPrivate::paintRenderingResultsToImageData(DrawingBuffer* drawingBuffer) 324 326 { 325 327 if (m_impl->getContextAttributes().premultipliedAlpha) 326 328 return 0; 327 328 RefPtr<ImageData> imageData = ImageData::create(IntSize(m_impl->width(), m_impl->height())); 329 330 Platform3DObject framebufferId; 331 int width, height; 332 getDrawingParameters(drawingBuffer, m_impl.get(), &framebufferId, &width, &height); 333 334 RefPtr<ImageData> imageData = ImageData::create(IntSize(width, height)); 329 335 unsigned char* pixels = imageData->data()->data()->data(); 330 size_t bufferSize = 4 * m_impl->width() * m_impl->height();331 332 m_impl->readBackFramebuffer(pixels, bufferSize, 0, m_impl->width(), m_impl->height());336 size_t bufferSize = 4 * width * height; 337 338 m_impl->readBackFramebuffer(pixels, bufferSize, framebufferId, width, height); 333 339 334 340 for (size_t i = 0; i < bufferSize; i += 4) … … 1013 1019 GraphicsContext3D::~GraphicsContext3D() 1014 1020 { 1015 WebGLLayerChromium* canvasLayer = m_private->platformLayer();1016 if (canvasLayer)1017 canvasLayer->setContext(0);1018 1021 m_private->setContextLostCallback(nullptr); 1019 1022 m_private->setSwapBuffersCompleteCallbackCHROMIUM(nullptr); … … 1060 1063 PlatformLayer* GraphicsContext3D::platformLayer() const 1061 1064 { 1062 WebGLLayerChromium* canvasLayer = m_private->platformLayer(); 1063 canvasLayer->setContext(this); 1064 return canvasLayer; 1065 return 0; 1065 1066 } 1066 1067 #endif … … 1218 1219 } 1219 1220 1220 DELEGATE_TO_INTERNAL_1(paintRenderingResultsToCanvas, CanvasRenderingContext*) 1221 DELEGATE_TO_INTERNAL_R(paintRenderingResultsToImageData, PassRefPtr<ImageData>) 1221 void GraphicsContext3D::paintRenderingResultsToCanvas(CanvasRenderingContext* context, DrawingBuffer* drawingBuffer) 1222 { 1223 return m_private->paintRenderingResultsToCanvas(context, drawingBuffer); 1224 } 1225 1226 PassRefPtr<ImageData> GraphicsContext3D::paintRenderingResultsToImageData(DrawingBuffer* drawingBuffer) 1227 { 1228 return m_private->paintRenderingResultsToImageData(drawingBuffer); 1229 } 1230 1222 1231 DELEGATE_TO_INTERNAL_1R(paintCompositedResultsToCanvas, CanvasRenderingContext*, bool) 1223 1232 -
trunk/Source/WebKit/chromium/src/GraphicsContext3DPrivate.h
r98185 r100032 47 47 namespace WebCore { 48 48 49 class DrawingBuffer; 49 50 class Extensions3DChromium; 50 #if USE(ACCELERATED_COMPOSITING)51 class WebGLLayerChromium;52 #endif53 51 class GraphicsContextLostCallbackAdapter; 54 52 class GraphicsContext3DSwapBuffersCompleteCallbackAdapter; … … 96 94 void markLayerComposited(); 97 95 98 void paintRenderingResultsToCanvas(CanvasRenderingContext* );96 void paintRenderingResultsToCanvas(CanvasRenderingContext*, DrawingBuffer*); 99 97 void paintFramebufferToCanvas(int framebuffer, int width, int height, bool premultiplyAlpha, ImageBuffer*); 100 PassRefPtr<ImageData> paintRenderingResultsToImageData( );98 PassRefPtr<ImageData> paintRenderingResultsToImageData(DrawingBuffer*); 101 99 bool paintsIntoCanvasBuffer() const; 102 100 bool paintCompositedResultsToCanvas(CanvasRenderingContext*); … … 104 102 void prepareTexture(); 105 103 106 #if USE(ACCELERATED_COMPOSITING)107 WebGLLayerChromium* platformLayer();108 #endif109 104 bool isGLES2Compliant() const; 110 105 … … 331 326 ResourceSafety m_resourceSafety; 332 327 333 #if USE(ACCELERATED_COMPOSITING)334 RefPtr<WebGLLayerChromium> m_compositingLayer;335 #endif336 328 #if USE(SKIA) 337 329 // If the width and height of the Canvas's backing store don't
Note: See TracChangeset
for help on using the changeset viewer.