net cleanup: Remove unnecessary namespace prefixes.
[chromium-blink-merge.git] / cc / layers / surface_layer.cc
blob1a690b6eb025e21522f9b76813c8e9ee914d077f
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "cc/layers/surface_layer.h"
7 #include "cc/layers/surface_layer_impl.h"
8 #include "cc/output/swap_promise.h"
9 #include "cc/trees/layer_tree_host.h"
11 namespace cc {
13 class SatisfySwapPromise : public SwapPromise {
14 public:
15 SatisfySwapPromise(SurfaceSequence sequence,
16 const SurfaceLayer::SatisfyCallback& satisfy_callback)
17 : sequence_(sequence), satisfy_callback_(satisfy_callback) {}
19 ~SatisfySwapPromise() override {}
21 private:
22 void DidSwap(CompositorFrameMetadata* metadata) override {
23 metadata->satisfies_sequences.push_back(sequence_.sequence);
26 void DidNotSwap(DidNotSwapReason reason) override {
27 satisfy_callback_.Run(sequence_);
29 int64 TraceId() const override { return 0; }
31 SurfaceSequence sequence_;
32 SurfaceLayer::SatisfyCallback satisfy_callback_;
34 DISALLOW_COPY_AND_ASSIGN(SatisfySwapPromise);
37 scoped_refptr<SurfaceLayer> SurfaceLayer::Create(
38 const SatisfyCallback& satisfy_callback,
39 const RequireCallback& require_callback) {
40 return make_scoped_refptr(
41 new SurfaceLayer(satisfy_callback, require_callback));
44 SurfaceLayer::SurfaceLayer(const SatisfyCallback& satisfy_callback,
45 const RequireCallback& require_callback)
46 : Layer(),
47 surface_scale_(1.f),
48 satisfy_callback_(satisfy_callback),
49 require_callback_(require_callback) {
52 SurfaceLayer::~SurfaceLayer() {
53 DCHECK(!layer_tree_host());
54 DCHECK(destroy_sequence_.is_null());
57 void SurfaceLayer::SetSurfaceId(SurfaceId surface_id,
58 float scale,
59 const gfx::Size& size) {
60 SatisfyDestroySequence();
61 surface_id_ = surface_id;
62 surface_size_ = size;
63 surface_scale_ = scale;
64 CreateNewDestroySequence();
66 UpdateDrawsContent(HasDrawableContent());
67 SetNeedsPushProperties();
70 scoped_ptr<LayerImpl> SurfaceLayer::CreateLayerImpl(LayerTreeImpl* tree_impl) {
71 return SurfaceLayerImpl::Create(tree_impl, id());
74 bool SurfaceLayer::HasDrawableContent() const {
75 return !surface_id_.is_null() && Layer::HasDrawableContent();
78 void SurfaceLayer::SetLayerTreeHost(LayerTreeHost* host) {
79 if (layer_tree_host() == host) {
80 Layer::SetLayerTreeHost(host);
81 return;
84 SatisfyDestroySequence();
85 Layer::SetLayerTreeHost(host);
86 CreateNewDestroySequence();
89 void SurfaceLayer::PushPropertiesTo(LayerImpl* layer) {
90 Layer::PushPropertiesTo(layer);
91 SurfaceLayerImpl* layer_impl = static_cast<SurfaceLayerImpl*>(layer);
93 layer_impl->SetSurfaceId(surface_id_);
96 void SurfaceLayer::CalculateContentsScale(float ideal_contents_scale,
97 float* contents_scale_x,
98 float* contents_scale_y,
99 gfx::Size* content_bounds) {
100 *content_bounds = surface_size_;
101 *contents_scale_x = surface_scale_;
102 *contents_scale_y = surface_scale_;
105 void SurfaceLayer::CreateNewDestroySequence() {
106 DCHECK(destroy_sequence_.is_null());
107 if (layer_tree_host()) {
108 destroy_sequence_ = layer_tree_host()->CreateSurfaceSequence();
109 require_callback_.Run(surface_id_, destroy_sequence_);
113 void SurfaceLayer::SatisfyDestroySequence() {
114 if (!layer_tree_host())
115 return;
116 DCHECK(!destroy_sequence_.is_null());
117 scoped_ptr<SatisfySwapPromise> satisfy(
118 new SatisfySwapPromise(destroy_sequence_, satisfy_callback_));
119 layer_tree_host()->QueueSwapPromise(satisfy.Pass());
120 destroy_sequence_ = SurfaceSequence();
123 } // namespace cc