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

Side by Side Diff: third_party/WebKit/Source/platform/graphics/CanvasSurfaceLayerBridge.cpp

Issue 2584643002: Revamp OffscreenCanvas commit flow (Closed)
Patch Set: fix based on fsamuel feedback 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "platform/graphics/CanvasSurfaceLayerBridge.h" 5 #include "platform/graphics/CanvasSurfaceLayerBridge.h"
6 6
7 #include "cc/layers/solid_color_layer.h"
7 #include "cc/layers/surface_layer.h" 8 #include "cc/layers/surface_layer.h"
8 #include "cc/surfaces/surface_id.h" 9 #include "cc/surfaces/surface_id.h"
9 #include "cc/surfaces/surface_sequence.h" 10 #include "cc/surfaces/surface_sequence.h"
10 #include "platform/graphics/GraphicsLayer.h" 11 #include "platform/graphics/GraphicsLayer.h"
11 #include "platform/mojo/MojoHelper.h" 12 #include "platform/mojo/MojoHelper.h"
13 #include "public/platform/InterfaceProvider.h"
12 #include "public/platform/Platform.h" 14 #include "public/platform/Platform.h"
13 #include "public/platform/WebCompositorSupport.h" 15 #include "public/platform/WebCompositorSupport.h"
14 #include "public/platform/WebLayer.h" 16 #include "public/platform/WebLayer.h"
17 #include "public/platform/modules/offscreencanvas/offscreen_canvas_surface.mojom -blink.h"
15 #include "ui/gfx/geometry/size.h" 18 #include "ui/gfx/geometry/size.h"
16 #include "wtf/Functional.h" 19 #include "wtf/Functional.h"
17 20
18 namespace blink { 21 namespace blink {
19 22
20 CanvasSurfaceLayerBridge::CanvasSurfaceLayerBridge( 23 CanvasSurfaceLayerBridge::CanvasSurfaceLayerBridge(
21 mojom::blink::OffscreenCanvasSurfacePtr service) 24 CanvasSurfaceLayerBridgeObserver* observer)
22 : m_service(std::move(service)) {} 25 : m_observer(observer),
26 m_binding(this),
27 m_frameSinkId(Platform::current()->generateFrameSinkId()) {
28 DCHECK(!m_service.is_bound());
29 mojom::blink::OffscreenCanvasSurfaceFactoryPtr serviceFactory;
30 Platform::current()->interfaceProvider()->getInterface(
31 mojo::GetProxy(&serviceFactory));
32 serviceFactory->CreateOffscreenCanvasSurface(
33 m_frameSinkId, m_binding.CreateInterfacePtrAndBind(),
34 mojo::GetProxy(&m_service));
35 }
23 36
24 CanvasSurfaceLayerBridge::~CanvasSurfaceLayerBridge() {} 37 CanvasSurfaceLayerBridge::~CanvasSurfaceLayerBridge() {
38 m_observer = nullptr;
39 }
25 40
26 bool CanvasSurfaceLayerBridge::createSurfaceLayer(int canvasWidth, 41 void CanvasSurfaceLayerBridge::createSolidColorLayer() {
27 int canvasHeight) { 42 m_solidColorLayer = cc::SolidColorLayer::Create();
28 if (!m_service->GetSurfaceId(&m_surfaceId)) 43 m_solidColorLayer->SetBackgroundColor(SK_ColorTRANSPARENT);
29 return false; 44 m_webLayer = Platform::current()->compositorSupport()->createLayerFromCCLayer(
45 m_solidColorLayer.get());
46 GraphicsLayer::registerContentsLayer(m_webLayer.get());
47 }
30 48
31 cc::SurfaceLayer::SatisfyCallback satisfyCallback = 49 void CanvasSurfaceLayerBridge::OnSurfaceCreated(const cc::SurfaceId& surfaceId,
32 convertToBaseCallback(WTF::bind( 50 int32_t width,
33 &CanvasSurfaceLayerBridge::satisfyCallback, WTF::unretained(this))); 51 int32_t height,
34 cc::SurfaceLayer::RequireCallback requireCallback = 52 float deviceScaleFactor) {
35 convertToBaseCallback(WTF::bind( 53 if (!m_currentSurfaceId.is_valid() && surfaceId.is_valid()) {
36 &CanvasSurfaceLayerBridge::requireCallback, WTF::unretained(this))); 54 m_currentSurfaceId = surfaceId;
37 m_surfaceLayer = cc::SurfaceLayer::Create(std::move(satisfyCallback),
38 std::move(requireCallback));
39 m_surfaceLayer->SetSurfaceId(m_surfaceId, 1.f,
40 gfx::Size(canvasWidth, canvasHeight));
41 55
42 m_webLayer = Platform::current()->compositorSupport()->createLayerFromCCLayer( 56 cc::SurfaceLayer::SatisfyCallback satisfyCallback =
43 m_surfaceLayer.get()); 57 convertToBaseCallback(WTF::bind(
44 GraphicsLayer::registerContentsLayer(m_webLayer.get()); 58 &CanvasSurfaceLayerBridge::satisfyCallback, WTF::unretained(this)));
45 return true; 59 cc::SurfaceLayer::RequireCallback requireCallback =
60 convertToBaseCallback(WTF::bind(
61 &CanvasSurfaceLayerBridge::requireCallback, WTF::unretained(this)));
62 m_surfaceLayer = cc::SurfaceLayer::Create(std::move(satisfyCallback),
63 std::move(requireCallback));
64 m_surfaceLayer->SetSurfaceId(m_currentSurfaceId, deviceScaleFactor,
65 gfx::Size(width, height));
66
67 GraphicsLayer::unregisterContentsLayer(m_webLayer.get());
68 m_webLayer->removeFromParent();
69
70 m_webLayer =
71 Platform::current()->compositorSupport()->createLayerFromCCLayer(
72 m_surfaceLayer.get());
73 GraphicsLayer::registerContentsLayer(m_webLayer.get());
74
75 m_observer->OnWebLayerReplaced();
76 }
46 } 77 }
47 78
48 void CanvasSurfaceLayerBridge::satisfyCallback( 79 void CanvasSurfaceLayerBridge::satisfyCallback(
49 const cc::SurfaceSequence& sequence) { 80 const cc::SurfaceSequence& sequence) {
50 m_service->Satisfy(sequence); 81 m_service->Satisfy(sequence);
51 } 82 }
52 83
53 void CanvasSurfaceLayerBridge::requireCallback( 84 void CanvasSurfaceLayerBridge::requireCallback(
54 const cc::SurfaceId& surfaceId, 85 const cc::SurfaceId& surfaceId,
55 const cc::SurfaceSequence& sequence) { 86 const cc::SurfaceSequence& sequence) {
56 m_service->Require(surfaceId, sequence); 87 m_service->Require(surfaceId, sequence);
57 } 88 }
58 89
59 } // namespace blink 90 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698