Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(962)

Unified Diff: third_party/WebKit/Source/platform/graphics/CanvasSurfaceLayerBridge.cpp

Issue 2584643002: Revamp OffscreenCanvas commit flow (Closed)
Patch Set: more fix Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/platform/graphics/CanvasSurfaceLayerBridge.cpp
diff --git a/third_party/WebKit/Source/platform/graphics/CanvasSurfaceLayerBridge.cpp b/third_party/WebKit/Source/platform/graphics/CanvasSurfaceLayerBridge.cpp
index 4355caed2a27dd712a886705e5bd9e97539d3cf5..1edcc3c6cda895282a62f7d9ae24faa89797c174 100644
--- a/third_party/WebKit/Source/platform/graphics/CanvasSurfaceLayerBridge.cpp
+++ b/third_party/WebKit/Source/platform/graphics/CanvasSurfaceLayerBridge.cpp
@@ -4,45 +4,77 @@
#include "platform/graphics/CanvasSurfaceLayerBridge.h"
+#include "cc/layers/layer.h"
+#include "cc/layers/solid_color_layer.h"
#include "cc/layers/surface_layer.h"
#include "cc/surfaces/surface_id.h"
#include "cc/surfaces/surface_sequence.h"
#include "platform/graphics/GraphicsLayer.h"
#include "platform/mojo/MojoHelper.h"
+#include "public/platform/InterfaceProvider.h"
#include "public/platform/Platform.h"
#include "public/platform/WebCompositorSupport.h"
#include "public/platform/WebLayer.h"
+#include "public/platform/modules/offscreencanvas/offscreen_canvas_surface.mojom-blink.h"
#include "ui/gfx/geometry/size.h"
#include "wtf/Functional.h"
namespace blink {
CanvasSurfaceLayerBridge::CanvasSurfaceLayerBridge(
- mojom::blink::OffscreenCanvasSurfacePtr service)
- : m_service(std::move(service)) {}
-
-CanvasSurfaceLayerBridge::~CanvasSurfaceLayerBridge() {}
-
-bool CanvasSurfaceLayerBridge::createSurfaceLayer(int canvasWidth,
- int canvasHeight) {
- if (!m_service->GetSurfaceId(&m_surfaceId))
- return false;
-
- cc::SurfaceLayer::SatisfyCallback satisfyCallback =
- convertToBaseCallback(WTF::bind(
- &CanvasSurfaceLayerBridge::satisfyCallback, WTF::unretained(this)));
- cc::SurfaceLayer::RequireCallback requireCallback =
- convertToBaseCallback(WTF::bind(
- &CanvasSurfaceLayerBridge::requireCallback, WTF::unretained(this)));
- m_surfaceLayer = cc::SurfaceLayer::Create(std::move(satisfyCallback),
- std::move(requireCallback));
- m_surfaceLayer->SetSurfaceId(m_surfaceId, 1.f,
- gfx::Size(canvasWidth, canvasHeight));
+ CanvasSurfaceLayerBridgeObserver* observer)
+ : m_observer(observer),
+ m_binding(this),
+ m_frameSinkId(Platform::current()->generateFrameSinkId()) {
+ DCHECK(!m_service.is_bound());
+ mojom::blink::OffscreenCanvasSurfaceFactoryPtr serviceFactory;
+ Platform::current()->interfaceProvider()->getInterface(
+ mojo::GetProxy(&serviceFactory));
+ serviceFactory->CreateOffscreenCanvasSurface(
+ m_frameSinkId, m_binding.CreateInterfacePtrAndBind(),
+ mojo::GetProxy(&m_service));
+}
+
+CanvasSurfaceLayerBridge::~CanvasSurfaceLayerBridge() {
+ m_observer = nullptr;
+}
+void CanvasSurfaceLayerBridge::createSolidColorLayer() {
+ m_CCLayer = cc::SolidColorLayer::Create();
+ m_CCLayer->SetBackgroundColor(SK_ColorTRANSPARENT);
m_webLayer = Platform::current()->compositorSupport()->createLayerFromCCLayer(
- m_surfaceLayer.get());
+ m_CCLayer.get());
GraphicsLayer::registerContentsLayer(m_webLayer.get());
- return true;
+}
+
+void CanvasSurfaceLayerBridge::OnSurfaceCreated(const cc::SurfaceId& surfaceId,
+ int32_t width,
jbauman 2016/12/16 02:19:26 I guess this could still glitch if the surface cre
xlai (Olivia) 2016/12/16 21:34:06 Nope this is impossible to happen. Only when the f
+ int32_t height,
+ float deviceScaleFactor) {
+ if (!m_currentSurfaceId.is_valid() && surfaceId.is_valid()) {
+ m_currentSurfaceId = surfaceId;
+ GraphicsLayer::unregisterContentsLayer(m_webLayer.get());
+ m_webLayer->removeFromParent();
+
+ cc::SurfaceLayer::SatisfyCallback satisfyCallback =
+ convertToBaseCallback(WTF::bind(
+ &CanvasSurfaceLayerBridge::satisfyCallback, WTF::unretained(this)));
+ cc::SurfaceLayer::RequireCallback requireCallback =
+ convertToBaseCallback(WTF::bind(
+ &CanvasSurfaceLayerBridge::requireCallback, WTF::unretained(this)));
+ scoped_refptr<cc::SurfaceLayer> surfaceLayer = cc::SurfaceLayer::Create(
+ std::move(satisfyCallback), std::move(requireCallback));
+ surfaceLayer->SetSurfaceId(m_currentSurfaceId, deviceScaleFactor,
Fady Samuel 2016/12/15 22:55:51 nit: TODO(xlai): Update this on resize.
xlai (Olivia) 2016/12/16 21:34:06 Done.
+ gfx::Size(width, height));
+ m_CCLayer = surfaceLayer;
+
+ m_webLayer =
+ Platform::current()->compositorSupport()->createLayerFromCCLayer(
+ m_CCLayer.get());
+ GraphicsLayer::registerContentsLayer(m_webLayer.get());
+
+ m_observer->OnWebLayerReplaced();
+ }
}
void CanvasSurfaceLayerBridge::satisfyCallback(

Powered by Google App Engine
This is Rietveld 408576698