OLD | NEW |
---|---|
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/surfaces/surface_id.h" | |
9 #include "cc/surfaces/surface_sequence.h" | |
8 #include "platform/graphics/GraphicsLayer.h" | 10 #include "platform/graphics/GraphicsLayer.h" |
11 #include "platform/mojo/MojoHelper.h" | |
9 #include "public/platform/Platform.h" | 12 #include "public/platform/Platform.h" |
13 #include "public/platform/ServiceRegistry.h" | |
10 #include "public/platform/WebCompositorSupport.h" | 14 #include "public/platform/WebCompositorSupport.h" |
11 #include "public/platform/WebLayer.h" | 15 #include "public/platform/WebLayer.h" |
16 #include "ui/gfx/geometry/size.h" | |
17 #include "wtf/Functional.h" | |
12 | 18 |
13 namespace blink { | 19 namespace blink { |
14 | 20 |
15 CanvasSurfaceLayerBridge::CanvasSurfaceLayerBridge() | 21 CanvasSurfaceLayerBridge::CanvasSurfaceLayerBridge() |
16 { | 22 { |
17 m_solidColorLayer = cc::SolidColorLayer::Create(); | 23 DCHECK(!m_service.is_bound()); |
18 m_solidColorLayer->SetBackgroundColor(SK_ColorBLUE); | 24 Platform::current()->serviceRegistry()->connectToRemoteService(mojo::GetProx y(&m_service)); |
danakj
2016/06/13 21:30:40
It occured to me another way to deal with testing
| |
19 m_webLayer = adoptPtr(Platform::current()->compositorSupport()->createLayerF romCCLayer(m_solidColorLayer.get())); | |
20 GraphicsLayer::registerContentsLayer(m_webLayer.get()); | |
21 } | 25 } |
22 | 26 |
23 CanvasSurfaceLayerBridge::~CanvasSurfaceLayerBridge() | 27 CanvasSurfaceLayerBridge::~CanvasSurfaceLayerBridge() |
24 { | 28 { |
25 } | 29 } |
26 | 30 |
31 bool CanvasSurfaceLayerBridge::createSurfaceLayer(int canvasWidth, int canvasHei ght) | |
32 { | |
33 // Get SurfaceId from browser. | |
34 bool success = this->syncGetServiceId(); | |
35 if (!success) | |
36 return false; | |
37 | |
38 // Immediately send an Async message to browser to request Surface creation. | |
39 this->asyncRequestSurfaceCreation(); | |
40 | |
41 // Create SurfaceLayer. | |
42 const cc::SurfaceLayer::SatisfyCallback& satisfyCallback = createBaseCallbac k(bind<cc::SurfaceSequence>(&CanvasSurfaceLayerBridge::satisfyCallback, this)); | |
danakj
2016/06/13 20:53:39
don't use a const& here for the lvalue, you're sto
xlai (Olivia)
2016/06/14 21:10:17
Done.
| |
43 const cc::SurfaceLayer::RequireCallback& requireCallback = createBaseCallbac k(bind<cc::SurfaceId, cc::SurfaceSequence>(&CanvasSurfaceLayerBridge::requireCal lback, this)); | |
44 m_surfaceLayer = cc::SurfaceLayer::Create(satisfyCallback, requireCallback); | |
danakj
2016/06/13 20:53:39
you can std::move the callbacks here, to drop the
xlai (Olivia)
2016/06/14 21:10:17
Done.
| |
45 m_surfaceLayer->SetSurfaceId(m_surfaceId, 1.f, gfx::Size(canvasWidth, canvas Height)); | |
danakj
2016/06/13 20:53:39
How are you going to handle resizing (do you need
| |
46 | |
47 // Convert SurfaceLayer to WebLayer and register it. | |
danakj
2016/06/13 20:53:39
style: This type of comment that just says what th
xlai (Olivia)
2016/06/14 21:10:17
Done. Removed superficial comments.
| |
48 m_webLayer = adoptPtr(Platform::current()->compositorSupport()->createLayerF romCCLayer(m_surfaceLayer.get())); | |
danakj
2016/06/13 20:53:38
Maybe you don't need to go through Platform etc an
xlai (Olivia)
2016/06/14 21:10:17
I tried this and find that it can only be done by
| |
49 GraphicsLayer::registerContentsLayer(m_webLayer.get()); | |
50 return true; | |
27 } | 51 } |
52 | |
53 void CanvasSurfaceLayerBridge::satisfyCallback(cc::SurfaceSequence sequence) | |
54 { | |
55 m_service->Satisfy(sequence); | |
56 } | |
57 | |
58 void CanvasSurfaceLayerBridge::requireCallback(cc::SurfaceId surfaceId, cc::Surf aceSequence sequence) | |
59 { | |
60 m_service->Require(surfaceId, sequence); | |
61 } | |
62 | |
63 bool CanvasSurfaceLayerBridge::syncGetServiceId() | |
danakj
2016/06/13 20:53:39
do you mean GetSurfaceId?
xlai (Olivia)
2016/06/14 21:10:17
The function name style in Blink starts with small
danakj
2016/06/14 22:07:00
Oh oops, I was referring to Service vs Surface.
| |
64 { | |
65 return m_service->GetSurfaceId(&m_surfaceId); | |
66 } | |
67 | |
68 void CanvasSurfaceLayerBridge::asyncRequestSurfaceCreation() | |
69 { | |
70 m_service->RequestSurfaceCreation(m_surfaceId); | |
71 } | |
72 | |
73 } // namespace blink | |
OLD | NEW |