Source/WebCore/ChangeLog

 12011-08-16 Jeff Timanus <twiz@chromium.org>
 2
 3 [Chromium] Rough patch that demonstrates the changes required to unify both WebGL and Canvas2D rendering contexts to use a DrawingBuffer for backing store management.
 4
 5 WebGL rendering contexts create and render to FBOs managed by a DrawingBuffer instance. All PlatformLayer lifetime management is performed by the DrawingBuffer.
 6 Because different layer types are required for Canvas2D and WebGL compositor layers, an agrument is passed to the DrawingBuffer to indicate its usage pattern.
 7
 8 Because WebGL content is now rendered to a DrawingBuffer, all of the routines that previously read from the back-buffer now must read from the FBO managed by the DrawingBuffer.
 9 A temporary solution is proposed: Add an extra argument to readBackFramebuffer to conditionally specify if fb 0 should be bound before the read, or if the read should happen from the currently bound fbo.
 10 A parallel Chrome change is required to implement the logic associated with the new argument. See CL: http://codereview.chromium.org/7669002
 11
 12 This change should only affect the chromium port.
 13 https://bugs.webkit.org/show_bug.cgi?id=53201
 14
 15 Reviewed by NOBODY (OOPS!).
 16
 17 * html/canvas/CanvasRenderingContext2D.cpp:
 18 (WebCore::CanvasRenderingContext2D::resetAcceleration):
 19 * html/canvas/WebGLRenderingContext.cpp:
 20 (WebCore::WebGLRenderingContext::WebGLRenderingContext):
 21 (WebCore::WebGLRenderingContext::initializeNewContext):
 22 (WebCore::WebGLRenderingContext::markContextChanged):
 23 (WebCore::WebGLRenderingContext::clearIfComposited):
 24 (WebCore::WebGLRenderingContext::paintRenderingResultsToCanvas):
 25 (WebCore::WebGLRenderingContext::paintRenderingResultsToImageData):
 26 (WebCore::WebGLRenderingContext::platformLayer):
 27 (WebCore::WebGLRenderingContext::reshape):
 28 (WebCore::WebGLRenderingContext::drawingBufferWidth):
 29 (WebCore::WebGLRenderingContext::drawingBufferHeight):
 30 (WebCore::WebGLRenderingContext::bindFramebuffer):
 31 (WebCore::WebGLRenderingContext::copyTexImage2D):
 32 (WebCore::WebGLRenderingContext::deleteFramebuffer):
 33 (WebCore::WebGLRenderingContext::disable):
 34 (WebCore::WebGLRenderingContext::enable):
 35 (WebCore::WebGLRenderingContext::readPixels):
 36 (WebCore::WebGLRenderingContext::getBoundFramebufferWidth):
 37 (WebCore::WebGLRenderingContext::getBoundFramebufferHeight):
 38 (WebCore::WebGLRenderingContext::maybeRestoreContext):
 39 * html/canvas/WebGLRenderingContext.h:
 40 * platform/graphics/GraphicsContext3D.cpp:
 41 * platform/graphics/GraphicsContext3D.h:
 42 (WebCore::GraphicsContext3D::platformLayer):
 43 * platform/graphics/chromium/Canvas2DLayerChromium.cpp:
 44 (WebCore::Canvas2DLayerChromium::Canvas2DLayerChromium):
 45 (WebCore::Canvas2DLayerChromium::updateCompositorResources):
 46 * platform/graphics/chromium/Canvas2DLayerChromium.h:
 47 * platform/graphics/chromium/CanvasLayerChromium.cpp:
 48 (WebCore::CanvasLayerChromium::CanvasLayerChromium):
 49 (WebCore::CanvasLayerChromium::setDrawingBuffer):
 50 (WebCore::CanvasLayerChromium::setTextureChanged):
 51 (WebCore::CanvasLayerChromium::textureId):
 52 (WebCore::CanvasLayerChromium::setLayerRenderer):
 53 (WebCore::CanvasLayerChromium::updatePlatformTexture):
 54 * platform/graphics/chromium/CanvasLayerChromium.h:
 55 (WebCore::CanvasLayerChromium::setTextureUpdated):
 56 (WebCore::CanvasLayerChromium::getDrawingBuffer):
 57 * platform/graphics/chromium/DrawingBufferChromium.cpp:
 58 (WebCore::DrawingBuffer::DrawingBuffer):
 59 (WebCore::DrawingBuffer::initialize):
 60 (WebCore::DrawingBuffer::publishToPlatformLayer):
 61 (WebCore::DrawingBuffer::platformLayer):
 62 (WebCore::DrawingBuffer::platformColorBuffer):
 63 (WebCore::DrawingBuffer::markContextChanged):
 64 * platform/graphics/chromium/WebGLLayerChromium.cpp:
 65 (WebCore::WebGLLayerChromium::WebGLLayerChromium):
 66 (WebCore::WebGLLayerChromium::~WebGLLayerChromium):
 67 (WebCore::WebGLLayerChromium::drawsContent):
 68 (WebCore::WebGLLayerChromium::updateCompositorResources):
 69 (WebCore::WebGLLayerChromium::context):
 70 (WebCore::WebGLLayerChromium::setDrawingBuffer):
 71 (WebCore::WebGLLayerChromium::setTextureChanged):
 72 (WebCore::WebGLLayerChromium::rateLimitContext):
 73 * platform/graphics/chromium/WebGLLayerChromium.h:
 74 (WebCore::WebGLLayerChromium::textureId):
 75 * platform/graphics/gpu/DrawingBuffer.cpp:
 76 (WebCore::DrawingBuffer::create):
 77 (WebCore::DrawingBuffer::resetOnNewContext):
 78 (WebCore::DrawingBuffer::commit): ANGLE does not support LINEAR when doing a fbo blit. Because no scaling is performed, we can use NEAREST.
 79 (WebCore::DrawingBuffer::multisample):
 80 (WebCore::DrawingBuffer::paintRenderingResultsToImageData):
 81 * platform/graphics/gpu/DrawingBuffer.h:
 82 (WebCore::DrawingBuffer::setScissorEnabled):
 83
1842011-08-16 Joseph Pecoraro <joepeck@webkit.org>
285
386 Unreviewed Chromium Windows build fix after r93140.
93149

Source/WebCore/html/canvas/CanvasRenderingContext2D.cpp

@@void CanvasRenderingContext2D::resetAcce
20612061 return;
20622062 }
20632063 } else {
2064  m_drawingBuffer = m_context3D->context()->createDrawingBuffer(canvas()->size());
 2064 m_drawingBuffer = DrawingBuffer::create(m_context3D->context(), IntSize(canvas()->width(), canvas()->height()), DrawingBuffer::DrawingBufferUsageCanvas2D);
20652065 if (!m_drawingBuffer) {
20662066 clearAcceleration();
20672067 return;
92837

Source/WebCore/html/canvas/WebGLRenderingContext.cpp

@@WebGLRenderingContext::WebGLRenderingCon
382382 , m_videoCache(4)
383383 , m_contextLost(false)
384384 , m_attributes(attributes)
 385 , m_drawingBuffer(0)
385386{
386387 ASSERT(m_context);
 388
 389#if PLATFORM(CHROMIUM)
 390 // Create the DrawingBuffer
 391 m_drawingBuffer = DrawingBuffer::create(m_context.get(), IntSize(canvas()->width(), canvas()->height()), DrawingBuffer::DrawingBufferUsageWebGL);
 392#endif
 393
 394 if (m_drawingBuffer)
 395 m_drawingBuffer->bind();
 396
387397 setupFlags();
388398 initializeNewContext();
389399}

@@void WebGLRenderingContext::initializeNe
449459 if (!isGLES2Compliant())
450460 initVertexAttrib0();
451461
 462 if (m_drawingBuffer)
 463 m_drawingBuffer->reset(IntSize(canvas()->width(), canvas()->height()));
 464
452465 m_context->reshape(canvas()->width(), canvas()->height());
453466 m_context->viewport(0, 0, canvas()->width(), canvas()->height());
454467

@@void WebGLRenderingContext::markContextC
481494{
482495 if (m_framebufferBinding)
483496 return;
484  m_context->markContextChanged();
 497
 498 if (m_drawingBuffer)
 499 m_drawingBuffer->markContextChanged();
 500 else
 501 m_context->markContextChanged();
 502
485503 m_layerCleared = false;
486504#if USE(ACCELERATED_COMPOSITING)
487505 RenderBox* renderBox = canvas()->renderBox();

@@bool WebGLRenderingContext::clearIfCompo
511529 // Determine if it's possible to combine the clear the user asked for and this clear.
512530 bool combinedClear = mask && !m_scissorEnabled;
513531
514  if (m_framebufferBinding)
515  m_context->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, 0);
 532 if (m_framebufferBinding) {
 533 if (m_drawingBuffer)
 534 m_drawingBuffer->bind();
 535 else
 536 m_context->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, 0);
 537 }
516538 m_context->disable(GraphicsContext3D::SCISSOR_TEST);
517539 if (combinedClear && (mask & GraphicsContext3D::COLOR_BUFFER_BIT))
518540 m_context->clearColor(m_colorMask[0] ? m_clearColor[0] : 0,

@@void WebGLRenderingContext::paintRenderi
571593 else
572594 canvas()->clearPresentationCopy();
573595 clearIfComposited();
 596#if 0 // TODO: Why is this code here?
574597 if (!m_markedCanvasDirty && !m_layerCleared)
575598 return;
 599#endif
576600 canvas()->clearCopiedImage();
577601 m_markedCanvasDirty = false;
578  m_context->paintRenderingResultsToCanvas(this);
 602
 603 if (m_drawingBuffer)
 604 m_drawingBuffer->commit();
 605 m_context->paintRenderingResultsToCanvas(this, m_drawingBuffer ? false : true);
 606 if (m_drawingBuffer)
 607 m_drawingBuffer->bind();
579608}
580609
581610PassRefPtr<ImageData> WebGLRenderingContext::paintRenderingResultsToImageData()
582611{
583612 clearIfComposited();
584  return m_context->paintRenderingResultsToImageData();
 613 if (m_drawingBuffer)
 614 m_drawingBuffer->commit();
 615 RefPtr<ImageData> imageData = m_context->paintRenderingResultsToImageData(m_drawingBuffer ? false : true);
 616 if (m_drawingBuffer)
 617 m_drawingBuffer->bind();
 618 return imageData;
585619}
586620
587621bool WebGLRenderingContext::paintsIntoCanvasBuffer() const

@@bool WebGLRenderingContext::paintsIntoCa
589623 return m_context->paintsIntoCanvasBuffer();
590624}
591625
 626#if USE(ACCELERATED_COMPOSITING)
 627PlatformLayer* WebGLRenderingContext::platformLayer() const
 628{
 629 if (m_drawingBuffer)
 630 return m_drawingBuffer->platformLayer();
 631
 632 return m_context->platformLayer();
 633}
 634#endif
 635
592636void WebGLRenderingContext::reshape(int width, int height)
593637{
594638 // This is an approximation because at WebGLRenderingContext level we don't

@@void WebGLRenderingContext::reshape(int
613657
614658 // We don't have to mark the canvas as dirty, since the newly created image buffer will also start off
615659 // clear (and this matches what reshape will do).
616  m_context->reshape(width, height);
 660 if (m_drawingBuffer)
 661 m_drawingBuffer->reset(IntSize(width, height));
 662 else
 663 m_context->reshape(width, height);
617664}
618665
619666int WebGLRenderingContext::drawingBufferWidth() const
620667{
 668 if (m_drawingBuffer)
 669 return m_drawingBuffer->size().width();
 670
621671 return m_context->getInternalFramebufferSize().width();
622672}
623673
624674int WebGLRenderingContext::drawingBufferHeight() const
625675{
 676 if (m_drawingBuffer)
 677 return m_drawingBuffer->size().height();
 678
626679 return m_context->getInternalFramebufferSize().height();
627680}
628681

@@void WebGLRenderingContext::bindFramebuf
742795 return;
743796 }
744797 m_framebufferBinding = buffer;
745  m_context->bindFramebuffer(target, objectOrZero(buffer));
 798 if (!m_framebufferBinding && m_drawingBuffer) {
 799 // Instead of binding fb 0, bind the drawing buffer.
 800 m_drawingBuffer->bind();
 801 } else
 802 m_context->bindFramebuffer(target, objectOrZero(buffer));
746803 if (buffer)
747804 buffer->setHasEverBeenBound();
748805 cleanupAfterGraphicsCall(false);

@@void WebGLRenderingContext::copyTexImage
10811138 return;
10821139 }
10831140 clearIfComposited();
1084  if (isResourceSafe())
 1141 if (isResourceSafe()) {
 1142 // Commit DrawingBuffer if needed (e.g., for multisampling)
 1143 if (!m_framebufferBinding && m_drawingBuffer)
 1144 m_drawingBuffer->commit();
 1145
10851146 m_context->copyTexImage2D(target, level, internalformat, x, y, width, height, border);
1086  else {
 1147
 1148 // Restore DrawingBuffer if needed
 1149 if (!m_framebufferBinding && m_drawingBuffer)
 1150 m_drawingBuffer->bind();
 1151 } else {
 1152 // Commit DrawingBuffer if needed (e.g., for multisampling)
 1153 if (!m_framebufferBinding && m_drawingBuffer)
 1154 m_drawingBuffer->commit();
 1155
10871156 GC3Dint clippedX, clippedY;
10881157 GC3Dsizei clippedWidth, clippedHeight;
10891158 if (clip2D(x, y, width, height, getBoundFramebufferWidth(), getBoundFramebufferHeight(), &clippedX, &clippedY, &clippedWidth, &clippedHeight)) {

@@void WebGLRenderingContext::copyTexImage
10951164 }
10961165 } else
10971166 m_context->copyTexImage2D(target, level, internalformat, x, y, width, height, border);
 1167
 1168 // Restore DrawingBuffer if needed
 1169 if (!m_framebufferBinding && m_drawingBuffer)
 1170 m_drawingBuffer->bind();
10981171 }
10991172 // FIXME: if the framebuffer is not complete, none of the below should be executed.
11001173 tex->setLevelInfo(target, level, internalformat, width, height, GraphicsContext3D::UNSIGNED_BYTE);

@@void WebGLRenderingContext::deleteFrameb
12711344 if (framebuffer == m_framebufferBinding) {
12721345 m_framebufferBinding = 0;
12731346 // Have to call bindFramebuffer here to bind back to internal fbo.
1274  m_context->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, 0);
 1347 if (m_drawingBuffer)
 1348 m_drawingBuffer->bind();
 1349 else
 1350 m_context->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, 0);
12751351 }
12761352}
12771353

@@void WebGLRenderingContext::disable(GC3D
13581434{
13591435 if (isContextLost() || !validateCapability(cap))
13601436 return;
1361  if (cap == GraphicsContext3D::SCISSOR_TEST)
 1437 if (cap == GraphicsContext3D::SCISSOR_TEST) {
13621438 m_scissorEnabled = false;
 1439 if (m_drawingBuffer)
 1440 m_drawingBuffer->setScissorEnabled(m_scissorEnabled);
 1441 }
13631442 m_context->disable(cap);
13641443 cleanupAfterGraphicsCall(false);
13651444}

@@void WebGLRenderingContext::enable(GC3De
17001779{
17011780 if (isContextLost() || !validateCapability(cap))
17021781 return;
1703  if (cap == GraphicsContext3D::SCISSOR_TEST)
 1782 if (cap == GraphicsContext3D::SCISSOR_TEST) {
17041783 m_scissorEnabled = true;
 1784 if (m_drawingBuffer)
 1785 m_drawingBuffer->setScissorEnabled(m_scissorEnabled);
 1786 }
17051787 m_context->enable(cap);
17061788 cleanupAfterGraphicsCall(false);
17071789}

@@void WebGLRenderingContext::readPixels(G
28732955 }
28742956 clearIfComposited();
28752957 void* data = pixels->baseAddress();
 2958
 2959 // Commit DrawingBuffer if needed (e.g., for multisampling)
 2960 if (!m_framebufferBinding && m_drawingBuffer)
 2961 m_drawingBuffer->commit();
 2962
28762963 m_context->readPixels(x, y, width, height, format, type, data);
 2964
 2965 // Restore DrawingBuffer if needed
 2966 if (!m_framebufferBinding && m_drawingBuffer)
 2967 m_drawingBuffer->bind();
 2968
28772969#if OS(DARWIN)
28782970 // FIXME: remove this section when GL driver bug on Mac is fixed, i.e.,
28792971 // when alpha is off, readPixels should set alpha to 255 instead of 0.

@@int WebGLRenderingContext::getBoundFrame
41244216{
41254217 if (m_framebufferBinding && m_framebufferBinding->object())
41264218 return m_framebufferBinding->getWidth();
4127  return m_context->getInternalFramebufferSize().width();
 4219 return m_drawingBuffer ? m_drawingBuffer->size().width() : m_context->getInternalFramebufferSize().width();
41284220}
41294221
41304222int WebGLRenderingContext::getBoundFramebufferHeight()
41314223{
41324224 if (m_framebufferBinding && m_framebufferBinding->object())
41334225 return m_framebufferBinding->getHeight();
4134  return m_context->getInternalFramebufferSize().height();
 4226 return m_drawingBuffer ? m_drawingBuffer->size().height() : m_context->getInternalFramebufferSize().height();
41354227}
41364228
41374229WebGLTexture* WebGLRenderingContext::validateTextureBinding(GC3Denum target, bool useSixEnumsForCubeMap)

@@void WebGLRenderingContext::maybeRestore
48274919 return;
48284920 }
48294921
 4922 m_drawingBuffer->resetOnNewContext(context);
 4923
48304924 m_context = context;
48314925 m_contextLost = false;
48324926 initializeNewContext();
92837

Source/WebCore/html/canvas/WebGLRenderingContext.h

2727#define WebGLRenderingContext_h
2828
2929#include "CanvasRenderingContext.h"
 30#include "DrawingBuffer.h"
3031#include "ExceptionCode.h"
3132#include "Float32Array.h"
3233#include "GraphicsContext3D.h"

@@public:
290291
291292 GraphicsContext3D* graphicsContext3D() const { return m_context.get(); }
292293#if USE(ACCELERATED_COMPOSITING)
293  virtual PlatformLayer* platformLayer() const { return m_context->platformLayer(); }
 294 virtual PlatformLayer* platformLayer() const;
294295#endif
295296
296297 void reshape(int width, int height);

@@public:
355356
356357 RefPtr<GraphicsContext3D> m_context;
357358
 359 // Optional structure for rendering to a DrawingBuffer, instead of directly
 360 // to the back-buffer of m_context.
 361 RefPtr<DrawingBuffer> m_drawingBuffer;
 362
358363 class WebGLRenderingContextRestoreTimer : public TimerBase {
359364 public:
360365 explicit WebGLRenderingContextRestoreTimer(WebGLRenderingContext* context) : m_context(context) { }
92837

Source/WebCore/platform/graphics/GraphicsContext3D.cpp

@@uint8_t convertColor16BigTo8(uint16_t va
5656
5757} // anonymous namespace
5858
59 
60 PassRefPtr<DrawingBuffer> GraphicsContext3D::createDrawingBuffer(const IntSize& size)
61 {
62  return DrawingBuffer::create(this, size);
63 }
64 
6559bool GraphicsContext3D::texImage2DResourceSafe(GC3Denum target, GC3Dint level, GC3Denum internalformat, GC3Dsizei width, GC3Dsizei height, GC3Dint border, GC3Denum format, GC3Denum type, GC3Dint unpackAlignment)
6660{
6761 ASSERT(unpackAlignment == 1 || unpackAlignment == 2 || unpackAlignment == 4 || unpackAlignment == 8);
92837

Source/WebCore/platform/graphics/GraphicsContext3D.h

@@const Platform3DObject NullPlatform3DObj
8686
8787namespace WebCore {
8888class CanvasRenderingContext;
89 class DrawingBuffer;
9089class Extensions3D;
9190#if PLATFORM(MAC) || PLATFORM(GTK) || PLATFORM(QT)
9291class Extensions3DOpenGL;

@@public:
475474 GrContext* grContext();
476475#endif
477476#if USE(ACCELERATED_COMPOSITING)
478  PlatformLayer* platformLayer() const;
 477 // The Chromium port manages PlatformLayer instaces via the DrawingBuffer
 478 // class.
 479 PlatformLayer* platformLayer() const { return 0; }
479480#endif
 481
480482#elif PLATFORM(QT)
481483 PlatformGraphicsContext3D platformGraphicsContext3D();
482484 Platform3DObject platformTexture() const;

@@public:
500502#endif
501503 void makeContextCurrent();
502504
503  PassRefPtr<DrawingBuffer> createDrawingBuffer(const IntSize& = IntSize());
504 
505505#if PLATFORM(MAC) || PLATFORM(CHROMIUM) || PLATFORM(GTK) || PLATFORM(QT)
506506 // With multisampling on, blit from multisampleFBO to regular FBO.
507507 void prepareTexture();

@@public:
791791 void markLayerComposited();
792792 bool layerComposited() const;
793793
794  void paintRenderingResultsToCanvas(CanvasRenderingContext* context);
795  PassRefPtr<ImageData> paintRenderingResultsToImageData();
 794 void paintRenderingResultsToCanvas(CanvasRenderingContext* context, bool bindBackBuffer = true);
 795 PassRefPtr<ImageData> paintRenderingResultsToImageData(bool bindBackBuffer = true);
796796
797797#if PLATFORM(QT)
798798 bool paintsIntoCanvasBuffer() const { return true; }
92837

Source/WebCore/platform/graphics/chromium/Canvas2DLayerChromium.cpp

@@PassRefPtr<Canvas2DLayerChromium> Canvas
4848
4949Canvas2DLayerChromium::Canvas2DLayerChromium(DrawingBuffer* drawingBuffer, GraphicsLayerChromium* owner)
5050 : CanvasLayerChromium(owner)
51  , m_drawingBuffer(drawingBuffer)
5251{
 52 setDrawingBuffer(drawingBuffer);
5353}
5454
5555Canvas2DLayerChromium::~Canvas2DLayerChromium()

@@void Canvas2DLayerChromium::updateCompos
7070{
7171 if (!m_contentsDirty || !drawsContent())
7272 return;
 73
 74#if 0
 75 updatePlatformTexture();
 76#endif
 77
7378 // Update the contents of the texture used by the compositor.
7479 if (m_contentsDirty) {
7580 m_drawingBuffer->publishToPlatformLayer();

@@void Canvas2DLayerChromium::updateCompos
7782 }
7883}
7984
80 unsigned Canvas2DLayerChromium::textureId() const
81 {
82  return m_drawingBuffer ? m_drawingBuffer->platformColorBuffer() : 0;
83 }
84 
85 void Canvas2DLayerChromium::setDrawingBuffer(DrawingBuffer* drawingBuffer)
86 {
87  if (drawingBuffer != m_drawingBuffer) {
88  if (m_drawingBuffer && layerRenderer())
89  layerRenderer()->removeChildContext(m_drawingBuffer->graphicsContext3D().get());
90 
91  m_drawingBuffer = drawingBuffer;
92 
93  if (drawingBuffer && layerRenderer())
94  layerRenderer()->addChildContext(m_drawingBuffer->graphicsContext3D().get());
95  }
96 }
97 
98 void Canvas2DLayerChromium::setLayerRenderer(LayerRendererChromium* newLayerRenderer)
99 {
100  if (layerRenderer() != newLayerRenderer && m_drawingBuffer) {
101  if (m_drawingBuffer->graphicsContext3D()) {
102  if (layerRenderer())
103  layerRenderer()->removeChildContext(m_drawingBuffer->graphicsContext3D().get());
104  if (newLayerRenderer)
105  newLayerRenderer->addChildContext(m_drawingBuffer->graphicsContext3D().get());
106  }
107 
108  LayerChromium::setLayerRenderer(newLayerRenderer);
109  }
110 }
111 
11285}
11386#endif // USE(ACCELERATED_COMPOSITING)
92837

Source/WebCore/platform/graphics/chromium/Canvas2DLayerChromium.h

@@class Canvas2DLayerChromium : public Can
4545public:
4646 static PassRefPtr<Canvas2DLayerChromium> create(DrawingBuffer*, GraphicsLayerChromium* owner);
4747 virtual ~Canvas2DLayerChromium();
 48
4849 virtual bool drawsContent() const;
4950 virtual void updateCompositorResources();
5051
51  void setTextureChanged();
52  virtual unsigned textureId() const;
53  void setDrawingBuffer(DrawingBuffer*);
54 
55  virtual void setLayerRenderer(LayerRendererChromium*);
56 
5752private:
5853 explicit Canvas2DLayerChromium(DrawingBuffer*, GraphicsLayerChromium* owner);
59  DrawingBuffer* m_drawingBuffer;
6054};
6155
6256}
92837

Source/WebCore/platform/graphics/chromium/CanvasLayerChromium.cpp

3434
3535#include "CanvasLayerChromium.h"
3636
37 #include "cc/CCLayerImpl.h"
 37#include "DrawingBuffer.h"
3838#include "GraphicsContext3D.h"
3939#include "LayerRendererChromium.h"
 40#include "cc/CCLayerImpl.h"
4041
4142namespace WebCore {
4243

@@CanvasLayerChromium::CanvasLayerChromium
4445 : LayerChromium(owner)
4546 , m_hasAlpha(true)
4647 , m_premultipliedAlpha(true)
 48 , m_drawingBuffer(0)
4749{
4850}
4951

@@void CanvasLayerChromium::pushProperties
6668 canvasLayer->setPremultipliedAlpha(m_premultipliedAlpha);
6769}
6870
 71void CanvasLayerChromium::setDrawingBuffer(DrawingBuffer* drawingBuffer)
 72{
 73 if (drawingBuffer != m_drawingBuffer) {
 74 if (m_drawingBuffer && layerRenderer())
 75 layerRenderer()->removeChildContext(m_drawingBuffer->graphicsContext3D().get());
 76
 77 m_drawingBuffer = drawingBuffer;
 78
 79 if (drawingBuffer && layerRenderer())
 80 layerRenderer()->addChildContext(m_drawingBuffer->graphicsContext3D().get());
 81 }
 82}
 83
 84#if 0
 85void CanvasLayerChromium::setTextureChanged()
 86{
 87 m_textureChanged = true;
 88}
 89#endif
 90
 91unsigned CanvasLayerChromium::textureId() const
 92{
 93 return m_drawingBuffer ? m_drawingBuffer->platformColorBuffer() : 0;
 94}
 95
 96void CanvasLayerChromium::setLayerRenderer(LayerRendererChromium* newLayerRenderer)
 97{
 98 if (layerRenderer() != newLayerRenderer && m_drawingBuffer) {
 99 if (m_drawingBuffer->graphicsContext3D()) {
 100 if (layerRenderer())
 101 layerRenderer()->removeChildContext(m_drawingBuffer->graphicsContext3D().get());
 102 if (newLayerRenderer)
 103 newLayerRenderer->addChildContext(m_drawingBuffer->graphicsContext3D().get());
 104 }
 105
 106 LayerChromium::setLayerRenderer(newLayerRenderer);
 107 }
 108}
 109
 110#if 0
 111void CanvasLayerChromium::updatePlatformTexture()
 112{
 113 if (m_textureChanged) { // We have to generate a new backing texture.
 114 GraphicsContext3D* context = layerRendererContext();
 115 if (m_textureId)
 116 context->deleteTexture(m_textureId);
 117 m_textureId = context->createTexture();
 118 context->activeTexture(GraphicsContext3D::TEXTURE0);
 119 context->bindTexture(GraphicsContext3D::TEXTURE_2D, m_textureId);
 120 IntSize size = m_drawingBuffer->size();
 121 context->texImage2DResourceSafe(GraphicsContext3D::TEXTURE_2D, 0, GraphicsContext3D::RGBA, size.width(), size.height(), 0, GraphicsContext3D::RGBA, GraphicsContext3D::UNSIGNED_BYTE);
 122 // Set the min-mag filters to linear and wrap modes to GraphicsContext3D::CLAMP_TO_EDGE
 123 // to get around NPOT texture limitations of GLES.
 124 context->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_MIN_FILTER, GraphicsContext3D::LINEAR);
 125 context->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_MAG_FILTER, GraphicsContext3D::LINEAR);
 126 context->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_WRAP_S, GraphicsContext3D::CLAMP_TO_EDGE);
 127 context->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_WRAP_T, GraphicsContext3D::CLAMP_TO_EDGE);
 128 m_textureChanged = false;
 129 // FIXME: The finish() here is required because we have to make sure that the texture created in this
 130 // context (the compositor context) is actually created by the service side before the child context
 131 // attempts to use it (in publishToPlatformLayer). finish() is currently the only call with strong
 132 // enough semantics to promise this, but is actually much stronger. Ideally we'd do something like
 133 // inserting a fence here and waiting for it before trying to publish.
 134 context->finish();
 135 }
 136}
 137#endif
 138
69139}
70140#endif // USE(ACCELERATED_COMPOSITING)
92837

Source/WebCore/platform/graphics/chromium/CanvasLayerChromium.h

3838
3939namespace WebCore {
4040
 41class DrawingBuffer;
 42
4143// Base class for WebGL and accelerated 2d canvases.
4244class CanvasLayerChromium : public LayerChromium {
4345public:

@@public:
4749
4850 virtual void pushPropertiesTo(CCLayerImpl*);
4951
 52 virtual void setTextureUpdated() {}
 53
 54 virtual void setDrawingBuffer(DrawingBuffer*);
 55 DrawingBuffer* getDrawingBuffer() { return m_drawingBuffer; }
 56
 57 unsigned textureId() const;
 58#if 0
 59 void setTextureChanged();
 60 unsigned textureId() const;
 61#endif
 62
 63 virtual void setLayerRenderer(LayerRendererChromium*);
 64
5065protected:
5166 explicit CanvasLayerChromium(GraphicsLayerChromium* owner);
5267
53  virtual unsigned textureId() const = 0;
 68 // TODO: Remove me?
 69 //void updatePlatformTexture();
 70
5471 virtual const char* layerTypeAsString() const { return "CanvasLayer"; }
5572
5673 bool m_hasAlpha;
5774 bool m_premultipliedAlpha;
 75
 76 DrawingBuffer* m_drawingBuffer;
5877};
5978
6079}
92837

Source/WebCore/platform/graphics/chromium/DrawingBufferChromium.cpp

3232
3333#include "DrawingBuffer.h"
3434
 35#include "Extensions3DChromium.h"
3536#include "GraphicsContext3D.h"
3637#if USE(SKIA)
3738#include "GrContext.h"

3940
4041#if USE(ACCELERATED_COMPOSITING)
4142#include "Canvas2DLayerChromium.h"
 43#include "WebGLLayerChromium.h"
4244#endif
4345
4446namespace WebCore {

@@static unsigned generateColorTexture(Gra
6365DrawingBuffer::DrawingBuffer(GraphicsContext3D* context,
6466 const IntSize& size,
6567 bool multisampleExtensionSupported,
66  bool packedDepthStencilExtensionSupported)
67  : m_context(context)
 68 bool packedDepthStencilExtensionSupported,
 69 DrawingBufferUsage usage)
 70 : m_usage(usage)
 71 , m_scissorEnabled(false)
 72 , m_context(context)
6873 , m_size(-1, -1)
6974 , m_multisampleExtensionSupported(multisampleExtensionSupported)
7075 , m_packedDepthStencilExtensionSupported(packedDepthStencilExtensionSupported)

@@DrawingBuffer::DrawingBuffer(GraphicsCon
7984 , m_grContext(0)
8085#endif
8186{
82  m_fbo = context->createFramebuffer();
83  context->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, m_fbo);
84  m_colorBuffer = generateColorTexture(context, size);
85  createSecondaryBuffers();
86  if (!reset(size)) {
 87#if 0
 88 if (DrawingBufferUsageWebGL == m_usage
 89 && !m_context->getExtensions()->supports("GL_CHROMIUM_copy_texture_to_parent_texture")) {
8790 m_context.clear();
8891 return;
8992 }
 93#endif
 94
 95 initialize(size);
9096}
9197
9298DrawingBuffer::~DrawingBuffer()

@@DrawingBuffer::~DrawingBuffer()
102108 clear();
103109}
104110
 111void DrawingBuffer::initialize(const IntSize& size)
 112{
 113 m_fbo = m_context->createFramebuffer();
 114 m_context->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, m_fbo);
 115 m_colorBuffer = generateColorTexture(m_context.get(), size);
 116 createSecondaryBuffers();
 117 if (!reset(size)) {
 118 m_context.clear();
 119 return;
 120 }
 121}
 122
105123#if USE(ACCELERATED_COMPOSITING)
106124void DrawingBuffer::publishToPlatformLayer()
107125{
108126 if (!m_context)
109127 return;
110128
111  if (multisample())
 129 bool multisampleBound = false;
 130 if (multisample()) {
112131 commit();
 132 multisampleBound = true;
 133 }
 134
113135 m_context->makeContextCurrent();
114136#if USE(SKIA)
115137 if (m_grContext)
116138 m_grContext->flush(0);
117139#endif
118140 m_context->flush();
 141
 142 if (DrawingBufferUsageWebGL == m_usage) {
 143 unsigned parentTexture = m_platformLayer->textureId();
 144 m_context->activeTexture(GraphicsContext3D::TEXTURE0);
 145 m_context->bindTexture(GraphicsContext3D::TEXTURE_2D, parentTexture);
 146 m_context->copyTexImage2D(GraphicsContext3D::TEXTURE_2D,
 147 0, // level
 148 GraphicsContext3D::RGBA,
 149 0, 0, // x, y
 150 m_size.width(),
 151 m_size.height(),
 152 0); // border
 153 }
 154
 155 if (multisampleBound)
 156 bind();
119157}
120158#endif
121159
122160#if USE(ACCELERATED_COMPOSITING)
123161PlatformLayer* DrawingBuffer::platformLayer()
124162{
125  if (!m_platformLayer)
126  m_platformLayer = Canvas2DLayerChromium::create(this, 0);
 163 if (!m_platformLayer) {
 164 if (DrawingBufferUsageCanvas2D == m_usage)
 165 m_platformLayer = Canvas2DLayerChromium::create(this, 0);
 166 else
 167 m_platformLayer = WebGLLayerChromium::create(0);
 168 m_platformLayer->setDrawingBuffer(this);
 169 }
 170
127171 return m_platformLayer.get();
128172}
129173#endif

@@Platform3DObject DrawingBuffer::platform
133177 return m_colorBuffer;
134178}
135179
 180void DrawingBuffer::markContextChanged() {
 181 if (m_context)
 182 m_context->markContextChanged();
 183
 184 if (m_platformLayer)
 185 m_platformLayer->setTextureUpdated();
 186}
 187
136188#if USE(SKIA)
137189void DrawingBuffer::setGrContext(GrContext* context)
138190{
92837

Source/WebCore/platform/graphics/chromium/WebGLLayerChromium.cpp

3434
3535#include "WebGLLayerChromium.h"
3636
 37#include "DrawingBuffer.h"
3738#include "Extensions3DChromium.h"
3839#include "GraphicsContext3D.h"
3940#include "LayerRendererChromium.h"

@@PassRefPtr<WebGLLayerChromium> WebGLLaye
4849
4950WebGLLayerChromium::WebGLLayerChromium(GraphicsLayerChromium* owner)
5051 : CanvasLayerChromium(owner)
51  , m_context(0)
5252 , m_textureId(0)
5353 , m_textureChanged(true)
5454 , m_contextSupportsRateLimitingExtension(false)

@@WebGLLayerChromium::WebGLLayerChromium(G
5959
6060WebGLLayerChromium::~WebGLLayerChromium()
6161{
62  if (m_context && layerRenderer())
63  layerRenderer()->removeChildContext(m_context);
 62 if (context() && layerRenderer())
 63 layerRenderer()->removeChildContext(context());
6464}
6565
6666bool WebGLLayerChromium::drawsContent() const
6767{
68  return (m_context && m_context->getExtensions()->getGraphicsResetStatusARB() == GraphicsContext3D::NO_ERROR);
 68 GraphicsContext3D* context3D = context();
 69 return (context3D && context3D->getExtensions()->getGraphicsResetStatusARB() == GraphicsContext3D::NO_ERROR);
6970}
7071
7172void WebGLLayerChromium::updateCompositorResources()

@@void WebGLLayerChromium::updateComposito
7677 if (!m_contentsDirty)
7778 return;
7879
79  GraphicsContext3D* rendererContext = layerRendererContext();
80  if (m_textureChanged) {
81  rendererContext->bindTexture(GraphicsContext3D::TEXTURE_2D, m_textureId);
82  // Set the min-mag filters to linear and wrap modes to GL_CLAMP_TO_EDGE
 80 if (m_textureChanged) { // We have to generate a new backing texture.
 81 GraphicsContext3D* context = layerRendererContext();
 82 if (m_textureId)
 83 context->deleteTexture(m_textureId);
 84 m_textureId = context->createTexture();
 85 context->activeTexture(GraphicsContext3D::TEXTURE0);
 86 context->bindTexture(GraphicsContext3D::TEXTURE_2D, m_textureId);
 87 IntSize size = m_drawingBuffer->size();
 88 context->texImage2DResourceSafe(GraphicsContext3D::TEXTURE_2D, 0, GraphicsContext3D::RGBA, size.width(), size.height(), 0, GraphicsContext3D::RGBA, GraphicsContext3D::UNSIGNED_BYTE);
 89 // Set the min-mag filters to linear and wrap modes to GraphicsContext3D::CLAMP_TO_EDGE
8390 // to get around NPOT texture limitations of GLES.
84  rendererContext->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_MIN_FILTER, GraphicsContext3D::LINEAR);
85  rendererContext->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_MAG_FILTER, GraphicsContext3D::LINEAR);
86  rendererContext->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_WRAP_S, GraphicsContext3D::CLAMP_TO_EDGE);
87  rendererContext->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_WRAP_T, GraphicsContext3D::CLAMP_TO_EDGE);
 91 context->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_MIN_FILTER, GraphicsContext3D::LINEAR);
 92 context->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_MAG_FILTER, GraphicsContext3D::LINEAR);
 93 context->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_WRAP_S, GraphicsContext3D::CLAMP_TO_EDGE);
 94 context->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_WRAP_T, GraphicsContext3D::CLAMP_TO_EDGE);
8895 m_textureChanged = false;
 96 // FIXME: The finish() here is required because we have to make sure that the texture created in this
 97 // context (the compositor context) is actually created by the service side before the child context
 98 // attempts to use it (in publishToPlatformLayer). finish() is currently the only call with strong
 99 // enough semantics to promise this, but is actually much stronger. Ideally we'd do something like
 100 // inserting a fence here and waiting for it before trying to publish.
 101 context->finish();
89102 }
 103
 104#if 0
 105 updatePlatformTexture();
 106#endif
 107
90108 // Update the contents of the texture used by the compositor.
91  if (m_contentsDirty && m_textureUpdated) {
92  // prepareTexture copies the contents of the off-screen render target into the texture
93  // used by the compositor.
94  //
95  m_context->prepareTexture();
96  m_context->markLayerComposited();
 109 if (m_contentsDirty) {
 110 // publishToPlatformLayer copies the contents of the off-screen render
 111 // target into the texture used by the compositor.
 112 m_drawingBuffer->publishToPlatformLayer();
 113 context()->markLayerComposited();
97114 m_contentsDirty = false;
98115 m_textureUpdated = false;
99116 }

@@void WebGLLayerChromium::setTextureUpdat
108125 m_rateLimitingTimer.startOneShot(0);
109126}
110127
111 void WebGLLayerChromium::setContext(const GraphicsContext3D* context)
 128GraphicsContext3D* WebGLLayerChromium::context() const
112129{
113  bool contextChanged = (m_context != context);
114  if (contextChanged && layerRenderer()) {
115  if (m_context)
116  layerRenderer()->removeChildContext(m_context);
117  if (context)
118  layerRenderer()->addChildContext(const_cast<GraphicsContext3D*>(context));
119  }
 130 if (m_drawingBuffer)
 131 return m_drawingBuffer->graphicsContext3D().get();
 132
 133 return 0;
 134}
120135
121  m_context = const_cast<GraphicsContext3D*>(context);
 136void WebGLLayerChromium::setDrawingBuffer(DrawingBuffer* drawingBuffer)
 137{
 138 bool contextChanged = context() != (drawingBuffer ? drawingBuffer->graphicsContext3D() : 0);
 139 CanvasLayerChromium::setDrawingBuffer(drawingBuffer);
122140
123  if (!m_context)
 141 GraphicsContext3D* context3D = context();
 142 if (!context3D)
124143 return;
125144
126  unsigned int textureId = m_context->platformTexture();
 145 unsigned int textureId = context3D->platformTexture();
127146 if (textureId != m_textureId || contextChanged) {
128147 m_textureChanged = true;
129148 m_textureUpdated = true;
130149 }
131150 m_textureId = textureId;
132  GraphicsContext3D::Attributes attributes = m_context->getContextAttributes();
 151 GraphicsContext3D::Attributes attributes = context3D->getContextAttributes();
133152 m_hasAlpha = attributes.alpha;
134153 m_premultipliedAlpha = attributes.premultipliedAlpha;
135  m_contextSupportsRateLimitingExtension = m_context->getExtensions()->supports("GL_CHROMIUM_rate_limit_offscreen_context");
 154 m_contextSupportsRateLimitingExtension = context3D->getExtensions()->supports("GL_CHROMIUM_rate_limit_offscreen_context");
136155}
137156
138 void WebGLLayerChromium::setLayerRenderer(LayerRendererChromium* newLayerRenderer)
 157#if 1
 158void WebGLLayerChromium::setTextureChanged()
139159{
140  if (layerRenderer() != newLayerRenderer) {
141  if (m_context) {
142  if (layerRenderer())
143  layerRenderer()->removeChildContext(m_context);
144  if (newLayerRenderer)
145  newLayerRenderer->addChildContext(m_context);
146  }
147 
148  LayerChromium::setLayerRenderer(newLayerRenderer);
149  }
 160 m_textureChanged = true;
150161}
 162#endif
151163
152164void WebGLLayerChromium::rateLimitContext(Timer<WebGLLayerChromium>*)
153165{
154166 TRACE_EVENT("WebGLLayerChromium::rateLimitContext", this, 0);
155167
156  if (!m_context)
 168 if (!context())
157169 return;
158170
159  Extensions3DChromium* extensions = static_cast<Extensions3DChromium*>(m_context->getExtensions());
 171 Extensions3DChromium* extensions = static_cast<Extensions3DChromium*>(context()/*m_context*/->getExtensions());
160172 extensions->rateLimitOffscreenContextCHROMIUM();
161173}
162174
92837

Source/WebCore/platform/graphics/chromium/WebGLLayerChromium.h

@@public:
5252 virtual bool drawsContent() const;
5353 virtual void updateCompositorResources();
5454 void setTextureUpdated();
 55 virtual void setDrawingBuffer(DrawingBuffer* drawingBuffer);
5556
56  void setContext(const GraphicsContext3D* context);
57  GraphicsContext3D* context() { return m_context; }
58 
59  virtual void setLayerRenderer(LayerRendererChromium*);
 57 void setTextureChanged();
 58 virtual unsigned textureId() const { return m_textureId; }
6059
 60 GraphicsContext3D* context() const;
6161protected:
6262 virtual const char* layerTypeAsString() const { return "WebGLLayer"; }
6363

@@private:
6565 explicit WebGLLayerChromium(GraphicsLayerChromium* owner);
6666 friend class WebGLLayerChromiumRateLimitTask;
6767
68  virtual unsigned textureId() const { return m_textureId; }
 68
6969 void rateLimitContext(Timer<WebGLLayerChromium>*);
7070
71  // GraphicsContext3D::platformLayer has a side-effect of assigning itself
72  // to the layer. Because of that GraphicsContext3D's destructor will reset
73  // layer's context to 0.
74  GraphicsContext3D* m_context;
7571 unsigned m_textureId;
7672 bool m_textureChanged;
7773 bool m_contextSupportsRateLimitingExtension;
92837

Source/WebCore/platform/graphics/gpu/DrawingBuffer.cpp

3535#include "DrawingBuffer.h"
3636
3737#include "Extensions3D.h"
 38#include "GraphicsContext3D.h"
 39#include "ImageData.h"
3840
3941namespace WebCore {
4042

@@static int s_maximumResourceUsePixels =
4850#endif
4951static int s_currentResourceUsePixels = 0;
5052
51 PassRefPtr<DrawingBuffer> DrawingBuffer::create(GraphicsContext3D* context, const IntSize& size)
 53PassRefPtr<DrawingBuffer> DrawingBuffer::create(GraphicsContext3D* context, const IntSize& size, DrawingBufferUsage usage)
5254{
5355 Extensions3D* extensions = context->getExtensions();
5456 bool multisampleSupported = extensions->supports("GL_ANGLE_framebuffer_blit") && extensions->supports("GL_ANGLE_framebuffer_multisample") && extensions->supports("GL_OES_rgb8_rgba8");

@@PassRefPtr<DrawingBuffer> DrawingBuffer:
6062 bool packedDepthStencilSupported = extensions->supports("GL_OES_packed_depth_stencil");
6163 if (packedDepthStencilSupported)
6264 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, usage));
6466 return (drawingBuffer->m_context) ? drawingBuffer.release() : 0;
6567}
6668
 69void DrawingBuffer::resetOnNewContext(PassRefPtr<GraphicsContext3D> graphicsContext)
 70{
 71 // Do not free any of the previously allocated resources, as the old context
 72 // has been lost.
 73 m_context = graphicsContext;
 74
 75 // Assign an invalid size to force the initializion routine to construct
 76 // new GPU resources.
 77 IntSize oldSize = m_size;
 78 m_size = IntSize(-1, -1);
 79 initialize(oldSize);
 80}
 81
6782void DrawingBuffer::clear()
6883{
6984 if (!m_context)

@@void DrawingBuffer::commit(long x, long
300315 height = m_size.height();
301316
302317 m_context->makeContextCurrent();
303 
 318
304319 if (m_multisampleFBO) {
305320 m_context->bindFramebuffer(Extensions3D::READ_FRAMEBUFFER, m_multisampleFBO);
306321 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);
 322
 323 if (m_scissorEnabled)
 324 m_context->disable(GraphicsContext3D::SCISSOR_TEST);
 325
 326 // Use NEAREST, because there is no scale performed during the blit.
 327 m_context->getExtensions()->blitFramebuffer(x, y, width, height, x, y, width, height, GraphicsContext3D::COLOR_BUFFER_BIT, GraphicsContext3D::NEAREST);
 328
 329 if (m_scissorEnabled)
 330 m_context->enable(GraphicsContext3D::SCISSOR_TEST);
308331 }
309 
 332
310333 m_context->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, m_fbo);
311334}
312335
 336bool DrawingBuffer::multisample() const
 337{
 338 return m_context && m_context->getContextAttributes().antialias && m_multisampleExtensionSupported;
 339}
 340
 341PassRefPtr<ImageData> DrawingBuffer::paintRenderingResultsToImageData()
 342{
 343 return m_context->paintRenderingResultsToImageData(false);
 344}
 345
313346void DrawingBuffer::bind()
314347{
315348 if (!m_context)
92837

Source/WebCore/platform/graphics/gpu/DrawingBuffer.h

3333
3434#include "GraphicsContext3D.h"
3535#include "GraphicsLayer.h"
 36#include "GraphicsTypes3D.h"
3637#include "IntSize.h"
3738
3839#include <wtf/Noncopyable.h>

@@struct GrPlatformSurfaceDesc;
4849#endif
4950
5051namespace WebCore {
51 
 52class GraphicsContext3D;
 53class ImageData;
5254#if PLATFORM(CHROMIUM) && USE(ACCELERATED_COMPOSITING)
53 class Canvas2DLayerChromium;
 55class CanvasLayerChromium;
5456#endif
5557
5658// Manages a rendering target (framebuffer + attachment) for a canvas. Can publish its rendering

@@public:
6163
6264 ~DrawingBuffer();
6365
 66 void resetOnNewContext(PassRefPtr<GraphicsContext3D> graphicsContext);
 67
6468 void clearFramebuffer();
6569
6670 // Returns true if the buffer was successfully resized.

@@public:
8084
8185 // Copies the multisample color buffer to the normal color buffer and leaves m_fbo bound
8286 void commit(long x = 0, long y = 0, long width = -1, long height = -1);
83 
84  bool multisample() const { return m_context && m_context->getContextAttributes().antialias && m_multisampleExtensionSupported; }
85 
 87
 88 // commit should copy the full multisample buffer, so the scissor test
 89 // setting is tracked so that the test can be safely disabled during
 90 // calls to commit.
 91 void setScissorEnabled(bool scissorEnabled) { m_scissorEnabled = scissorEnabled; }
 92
 93 bool multisample() const;
 94
8695 Platform3DObject platformColorBuffer() const;
8796
 97 PassRefPtr<ImageData> paintRenderingResultsToImageData();
 98
8899#if USE(ACCELERATED_COMPOSITING)
89100 PlatformLayer* platformLayer();
90101 void publishToPlatformLayer();
 102 void markContextChanged();
91103#endif
92104
93105#if USE(SKIA)

@@public:
97109
98110 PassRefPtr<GraphicsContext3D> graphicsContext3D() const { return m_context; }
99111
 112 enum DrawingBufferUsage {
 113 DrawingBufferUsageCanvas2D,
 114 DrawingBufferUsageWebGL,
 115 };
 116
 117 static PassRefPtr<DrawingBuffer> create(GraphicsContext3D*, const IntSize&, DrawingBufferUsage usage);
 118
100119private:
101  static PassRefPtr<DrawingBuffer> create(GraphicsContext3D*, const IntSize&);
102 
103  DrawingBuffer(GraphicsContext3D*, const IntSize&, bool multisampleExtensionSupported, bool packedDepthStencilExtensionSupported);
 120 DrawingBuffer(GraphicsContext3D*, const IntSize&, bool multisampleExtensionSupported,
 121 bool packedDepthStencilExtensionSupported, DrawingBufferUsage usage);
 122
 123 void initialize(const IntSize&);
 124
 125 DrawingBufferUsage m_usage;
 126 bool m_scissorEnabled;
104127
105128 RefPtr<GraphicsContext3D> m_context;
106129 IntSize m_size;

@@private:
122145
123146#if PLATFORM(CHROMIUM)
124147#if USE(ACCELERATED_COMPOSITING)
125  RefPtr<Canvas2DLayerChromium> m_platformLayer;
 148 RefPtr<CanvasLayerChromium> m_platformLayer;
126149#endif
127150#endif
128151
92837

Source/WebKit/chromium/ChangeLog

 12011-08-16 Jeff Timanus <twiz@chromium.org>
 2
 3 [Chromium] Rough patch that demonstrates the changes required to unify both WebGL and Canvas2D rendering contexts to use a DrawingBuffer for backing store management.
 4
 5 Because WebGL content is now rendered to a DrawingBuffer, all of the routines that previously read from the back-buffer now must read from the FBO managed by the DrawingBuffer.
 6 A temporary solution is proposed: Add an extra argument to readBackFramebuffer to conditionally specify if fb 0 should be bound before the read, or if the read should happen from the currently bound fbo.
 7 A parallel Chrome change is required to implement the logic associated with the new argument. See CL: http://codereview.chromium.org/7669002
 8 https://bugs.webkit.org/show_bug.cgi?id=53201
 9
 10 Reviewed by NOBODY (OOPS!).
 11
 12 * public/WebGraphicsContext3D.h:
 13 * src/GraphicsContext3DChromium.cpp:
 14 (WebCore::GraphicsContext3DInternal::initialize):
 15 (WebCore::GraphicsContext3DInternal::markContextChanged):
 16 (WebCore::GraphicsContext3DInternal::paintRenderingResultsToCanvas):
 17 (WebCore::GraphicsContext3DInternal::paintRenderingResultsToImageData):
 18 (WebCore::GraphicsContext3D::~GraphicsContext3D):
 19 * src/GraphicsContext3DInternal.h:
 20
1212011-08-16 Stephen White <senorblanco@chromium.org>
222
323 GraphicsContext3D should allow its hostWindow to be NULL
93149

Source/WebKit/chromium/public/WebGraphicsContext3D.h

@@public:
138138 // the memory region pointed to by "pixels" with size "bufferSize". It is
139139 // expected that the storage for "pixels" covers (4 * width * height) bytes.
140140 // Returns true on success.
141  virtual bool readBackFramebuffer(unsigned char* pixels, size_t bufferSize) = 0;
 141 virtual bool readBackFramebuffer(unsigned char* pixels, size_t bufferSize, bool bindDefaultBackBuffer) = 0;
142142
143143 // Returns the id of the texture which is used for storing the contents of
144144 // the framebuffer associated with this context. This texture is accessible
92837

Source/WebKit/chromium/src/GraphicsContext3DChromium.cpp

@@bool GraphicsContext3DInternal::initiali
134134 return false;
135135 m_impl = webContext.release();
136136
137 #if USE(ACCELERATED_COMPOSITING)
138  m_compositingLayer = WebGLLayerChromium::create(0);
139 #endif
140137 return true;
141138}
142139

@@void GraphicsContext3DInternal::prepareT
180177 m_impl->prepareTexture();
181178}
182179
183 #if USE(ACCELERATED_COMPOSITING)
184 WebGLLayerChromium* GraphicsContext3DInternal::platformLayer() const
185 {
186  return m_compositingLayer.get();
187 }
188 #endif
189 
190180void GraphicsContext3DInternal::markContextChanged()
191181{
192 #if USE(ACCELERATED_COMPOSITING)
193  platformLayer()->setTextureUpdated();
194 #endif
195182 m_layerComposited = false;
196183}
197184

@@bool GraphicsContext3DInternal::layerCom
205192 return m_layerComposited;
206193}
207194
208 void GraphicsContext3DInternal::paintRenderingResultsToCanvas(CanvasRenderingContext* context)
 195void GraphicsContext3DInternal::paintRenderingResultsToCanvas(CanvasRenderingContext* context, bool bindBackBuffer)
209196{
210197 HTMLCanvasElement* canvas = context->canvas();
211198 ImageBuffer* imageBuffer = canvas->buffer();

@@void GraphicsContext3DInternal::paintRen
243230#error Must port to your platform
244231#endif
245232
246  m_impl->readBackFramebuffer(pixels, 4 * m_impl->width() * m_impl->height());
 233 m_impl->readBackFramebuffer(pixels, 4 * m_impl->width() * m_impl->height(), bindBackBuffer);
247234
248235 if (!m_impl->getContextAttributes().premultipliedAlpha) {
249236 size_t bufferSize = 4 * m_impl->width() * m_impl->height();

@@void GraphicsContext3DInternal::paintRen
274261#endif
275262}
276263
277 PassRefPtr<ImageData> GraphicsContext3DInternal::paintRenderingResultsToImageData()
 264PassRefPtr<ImageData> GraphicsContext3DInternal::paintRenderingResultsToImageData(bool bindBackBuffer)
278265{
279266 if (m_impl->getContextAttributes().premultipliedAlpha)
280267 return 0;

@@PassRefPtr<ImageData> GraphicsContext3DI
283270 unsigned char* pixels = imageData->data()->data()->data();
284271 size_t bufferSize = 4 * m_impl->width() * m_impl->height();
285272
286  m_impl->readBackFramebuffer(pixels, bufferSize);
 273 m_impl->readBackFramebuffer(pixels, bufferSize, bindBackBuffer);
287274
288275 for (size_t i = 0; i < bufferSize; i += 4)
289276 std::swap(pixels[i], pixels[i + 2]);

@@GraphicsContext3D::GraphicsContext3D(Gra
959946
960947GraphicsContext3D::~GraphicsContext3D()
961948{
962  WebGLLayerChromium* canvasLayer = m_internal->platformLayer();
963  if (canvasLayer)
964  canvasLayer->setContext(0);
965949 m_internal->setContextLostCallback(nullptr);
966950 m_internal->setSwapBuffersCompleteCallbackCHROMIUM(nullptr);
967951}

@@IntSize GraphicsContext3D::getInternalFr
1005989 return m_internal->getInternalFramebufferSize();
1006990}
1007991
1008 #if USE(ACCELERATED_COMPOSITING)
1009 PlatformLayer* GraphicsContext3D::platformLayer() const
1010 {
1011  WebGLLayerChromium* canvasLayer = m_internal->platformLayer();
1012  canvasLayer->setContext(this);
1013  return canvasLayer;
1014 }
1015 #endif
1016 
1017992DELEGATE_TO_INTERNAL(makeContextCurrent)
1018993DELEGATE_TO_INTERNAL_2(reshape, int, int)
1019994

@@bool GraphicsContext3D::layerComposited(
11661141 return m_internal->layerComposited();
11671142}
11681143
1169 DELEGATE_TO_INTERNAL_1(paintRenderingResultsToCanvas, CanvasRenderingContext*)
1170 DELEGATE_TO_INTERNAL_R(paintRenderingResultsToImageData, PassRefPtr<ImageData>)
 1144DELEGATE_TO_INTERNAL_2(paintRenderingResultsToCanvas, CanvasRenderingContext*, bool)
 1145DELEGATE_TO_INTERNAL_1R(paintRenderingResultsToImageData, bool, PassRefPtr<ImageData>)
11711146
11721147bool GraphicsContext3D::paintsIntoCanvasBuffer() const
11731148{
92837

Source/WebKit/chromium/src/GraphicsContext3DInternal.h

@@public:
7979 bool layerComposited() const;
8080 void markLayerComposited();
8181
82  void paintRenderingResultsToCanvas(CanvasRenderingContext*);
83  PassRefPtr<ImageData> paintRenderingResultsToImageData();
 82 void paintRenderingResultsToCanvas(CanvasRenderingContext*, bool);
 83 PassRefPtr<ImageData> paintRenderingResultsToImageData(bool);
8484 bool paintsIntoCanvasBuffer() const;
8585
8686 void prepareTexture();
8787
88 #if USE(ACCELERATED_COMPOSITING)
89  WebGLLayerChromium* platformLayer() const;
90 #endif
9188 bool isGLES2Compliant() const;
9289
9390 void releaseShaderCompiler();

@@private:
295292 HashSet<String> m_enabledExtensions;
296293 HashSet<String> m_requestableExtensions;
297294 bool m_layerComposited;
298 #if USE(ACCELERATED_COMPOSITING)
299  RefPtr<WebGLLayerChromium> m_compositingLayer;
300 #endif
 295
301296#if USE(SKIA)
302297 // If the width and height of the Canvas's backing store don't
303298 // match those that we were given in the most recent call to
92837