| Index: Source/core/platform/graphics/chromium/Canvas2DLayerBridge.cpp
|
| diff --git a/Source/core/platform/graphics/chromium/Canvas2DLayerBridge.cpp b/Source/core/platform/graphics/chromium/Canvas2DLayerBridge.cpp
|
| index 8dc281fa16fec3e68dbf961c6abcfa40d73e32c0..f6bfa152be233d92be36caf9584cc7950993a918 100644
|
| --- a/Source/core/platform/graphics/chromium/Canvas2DLayerBridge.cpp
|
| +++ b/Source/core/platform/graphics/chromium/Canvas2DLayerBridge.cpp
|
| @@ -34,6 +34,7 @@
|
| #include "core/platform/graphics/GraphicsContext3D.h"
|
| #include "core/platform/graphics/GraphicsLayer.h"
|
| #include "core/platform/graphics/chromium/Canvas2DLayerManager.h"
|
| +#include "core/platform/graphics/gpu/SharedGraphicsContext3D.h"
|
| #include "public/platform/Platform.h"
|
| #include "public/platform/WebCompositorSupport.h"
|
| #include "public/platform/WebGraphicsContext3D.h"
|
| @@ -44,11 +45,38 @@ using WebKit::WebTextureUpdater;
|
|
|
| namespace WebCore {
|
|
|
| +static SkSurface* createSurface(GraphicsContext3D* context3D, const IntSize& size)
|
| +{
|
| + ASSERT(!context3D->webContext()->isContextLost());
|
| + GrContext* gr = context3D->grContext();
|
| + if (!gr)
|
| + return 0;
|
| + gr->resetContext();
|
| + SkImage::Info info;
|
| + info.fWidth = size.width();
|
| + info.fHeight = size.height();
|
| + info.fColorType = SkImage::kPMColor_ColorType;
|
| + info.fAlphaType = SkImage::kPremul_AlphaType;
|
| + return SkSurface::NewRenderTarget(gr, info);
|
| +}
|
| +
|
| +PassOwnPtr<Canvas2DLayerBridge> Canvas2DLayerBridge::create(PassRefPtr<GraphicsContext3D> context, const IntSize& size, OpacityMode opacityMode, ThreadMode threading)
|
| +{
|
| + TRACE_EVENT_INSTANT0("test_gpu", "Canvas2DLayerBridgeCreation");
|
| + SkAutoTUnref<SkSurface> surface(createSurface(context.get(), size));
|
| + if (!surface.get())
|
| + return PassOwnPtr<Canvas2DLayerBridge>();
|
| + SkDeferredCanvas* canvas = new SkDeferredCanvas(surface);
|
| + OwnPtr<Canvas2DLayerBridge> layerBridge = adoptPtr(new Canvas2DLayerBridge(context, canvas, opacityMode, threading));
|
| + return layerBridge.release();
|
| +}
|
| +
|
| Canvas2DLayerBridge::Canvas2DLayerBridge(PassRefPtr<GraphicsContext3D> context, SkDeferredCanvas* canvas, OpacityMode opacityMode, ThreadMode threadMode)
|
| : m_canvas(canvas)
|
| , m_context(context)
|
| , m_bytesAllocated(0)
|
| , m_didRecordDrawCommand(false)
|
| + , m_surfaceIsValid(true)
|
| , m_framesPending(0)
|
| , m_next(0)
|
| , m_prev(0)
|
| @@ -58,8 +86,6 @@ Canvas2DLayerBridge::Canvas2DLayerBridge(PassRefPtr<GraphicsContext3D> context,
|
| {
|
| ASSERT(m_canvas);
|
| // Used by browser tests to detect the use of a Canvas2DLayerBridge.
|
| - TRACE_EVENT_INSTANT0("test_gpu", "Canvas2DLayerBridgeCreation");
|
| - m_canvas->setNotificationClient(this);
|
| #if ENABLE(CANVAS_USES_MAILBOX)
|
| m_layer = adoptPtr(WebKit::Platform::current()->compositorSupport()->createExternalTextureLayerForMailbox(this));
|
| #else
|
| @@ -72,6 +98,7 @@ Canvas2DLayerBridge::Canvas2DLayerBridge(PassRefPtr<GraphicsContext3D> context,
|
| #endif
|
| m_layer->setOpaque(opacityMode == Opaque);
|
| GraphicsLayer::registerContentsLayer(m_layer->layer());
|
| + m_canvas->setNotificationClient(this);
|
| }
|
|
|
| Canvas2DLayerBridge::~Canvas2DLayerBridge()
|
| @@ -79,11 +106,10 @@ Canvas2DLayerBridge::~Canvas2DLayerBridge()
|
| GraphicsLayer::unregisterContentsLayer(m_layer->layer());
|
| Canvas2DLayerManager::get().layerToBeDestroyed(this);
|
| m_canvas->setNotificationClient(0);
|
| - m_layer->clearTexture();
|
| - m_layer.clear();
|
| #if ENABLE(CANVAS_USES_MAILBOX)
|
| m_mailboxes.clear();
|
| #endif
|
| + m_layer->clearTexture();
|
| }
|
|
|
| void Canvas2DLayerBridge::limitPendingFrames()
|
| @@ -98,6 +124,14 @@ void Canvas2DLayerBridge::limitPendingFrames()
|
|
|
| void Canvas2DLayerBridge::prepareForDraw()
|
| {
|
| + ASSERT(m_layer);
|
| + if (!isValid()) {
|
| + if (m_canvas) {
|
| + // drop pending commands because there is no surface to draw to
|
| + m_canvas->silentFlush();
|
| + }
|
| + return;
|
| + }
|
| #if !ENABLE(CANVAS_USES_MAILBOX)
|
| m_layer->willModifyTexture();
|
| #endif
|
| @@ -144,6 +178,8 @@ void Canvas2DLayerBridge::flush()
|
|
|
| unsigned Canvas2DLayerBridge::prepareTexture(WebTextureUpdater& updater)
|
| {
|
| + if (!isValid())
|
| + return 0;
|
| #if ENABLE(CANVAS_USES_MAILBOX)
|
| ASSERT_NOT_REACHED();
|
| return 0;
|
| @@ -167,12 +203,48 @@ unsigned Canvas2DLayerBridge::prepareTexture(WebTextureUpdater& updater)
|
|
|
| WebGraphicsContext3D* Canvas2DLayerBridge::context()
|
| {
|
| - return m_context->webContext();
|
| + return isValid() ? m_context->webContext() : 0;
|
| +}
|
| +
|
| +bool Canvas2DLayerBridge::isValid()
|
| +{
|
| + ASSERT(m_layer);
|
| + if (m_context->webContext()->isContextLost() || !m_surfaceIsValid) {
|
| + // Attempt to recover.
|
| + m_layer->clearTexture();
|
| + RefPtr<GraphicsContext3D> sharedContext = SharedGraphicsContext3D::get();
|
| + if (!sharedContext || sharedContext->webContext()->isContextLost()) {
|
| + m_surfaceIsValid = false;
|
| + return false;
|
| + }
|
| + m_context = sharedContext;
|
| + IntSize size(m_canvas->getTopDevice()->width(), m_canvas->getTopDevice()->height());
|
| + SkAutoTUnref<SkSurface> surface(createSurface(m_context.get(), size));
|
| + if (surface.get()) {
|
| + m_canvas->setSurface(surface.get());
|
| + m_surfaceIsValid = true;
|
| + // FIXME: draw sad canvas picture into new buffer crbug.com/243842
|
| + } else {
|
| + // Surface allocation failed. Set m_surfaceIsValid to false to
|
| + // trigger subsequent retry.
|
| + m_surfaceIsValid = false;
|
| + return false;
|
| + }
|
| +#if !ENABLE(CANVAS_USES_MAILBOX)
|
| + GrRenderTarget* renderTarget = reinterpret_cast<GrRenderTarget*>(m_canvas->getDevice()->accessRenderTarget());
|
| + if (renderTarget)
|
| + m_layer->setTextureId(renderTarget->asTexture()->getTextureHandle());
|
| +#endif
|
| + }
|
| + return true;
|
| +
|
| }
|
|
|
| bool Canvas2DLayerBridge::prepareMailbox(WebKit::WebExternalTextureMailbox* outMailbox)
|
| {
|
| #if ENABLE(CANVAS_USES_MAILBOX)
|
| + if (!isValid())
|
| + return false;
|
| // Release to skia textures that were previouosly released by the
|
| // compositor. We do this before acquiring the next snapshot in
|
| // order to cap maximum gpu memory consumption.
|
| @@ -274,6 +346,7 @@ void Canvas2DLayerBridge::mailboxReleased(const WebKit::WebExternalTextureMailbo
|
|
|
| WebKit::WebLayer* Canvas2DLayerBridge::layer()
|
| {
|
| + ASSERT(m_layer);
|
| return m_layer->layer();
|
| }
|
|
|
| @@ -285,6 +358,8 @@ void Canvas2DLayerBridge::contextAcquired()
|
|
|
| unsigned Canvas2DLayerBridge::backBufferTexture()
|
| {
|
| + if (!isValid())
|
| + return 0;
|
| contextAcquired();
|
| m_canvas->flush();
|
| m_context->flush();
|
|
|