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.
4 
5 #ifndef CC_LAYERS_SURFACE_LAYER_IMPL_H_
6 #define CC_LAYERS_SURFACE_LAYER_IMPL_H_
7 
8 #include <memory>
9 
10 #include "base/bind.h"
11 #include "base/memory/ptr_util.h"
12 #include "base/synchronization/waitable_event.h"
13 #include "cc/cc_export.h"
14 #include "cc/layers/layer_impl.h"
15 #include "components/viz/common/quads/surface_draw_quad.h"
16 #include "components/viz/common/surfaces/surface_id.h"
17 #include "components/viz/common/surfaces/surface_info.h"
18 #include "components/viz/common/surfaces/surface_range.h"
19 
20 namespace cc {
21 
22 // This must match surface_layer.h's UpdateSubmissionStateCB.
23 using UpdateSubmissionStateCB =
24     base::RepeatingCallback<void(bool is_visible, base::WaitableEvent*)>;
25 
26 class CC_EXPORT SurfaceLayerImpl : public LayerImpl {
27  public:
28   static std::unique_ptr<SurfaceLayerImpl> Create(
29       LayerTreeImpl* tree_impl,
30       int id,
31       UpdateSubmissionStateCB update_submission_state_callback);
32 
33   static std::unique_ptr<SurfaceLayerImpl> Create(LayerTreeImpl* tree_impl,
34                                                   int id);
35 
36   SurfaceLayerImpl(const SurfaceLayerImpl&) = delete;
37   ~SurfaceLayerImpl() override;
38 
39   SurfaceLayerImpl& operator=(const SurfaceLayerImpl&) = delete;
40 
41   void SetRange(const viz::SurfaceRange& surface_range,
42                 base::Optional<uint32_t> deadline_in_frames);
range()43   const viz::SurfaceRange& range() const { return surface_range_; }
44 
deadline_in_frames()45   base::Optional<uint32_t> deadline_in_frames() const {
46     return deadline_in_frames_;
47   }
48 
49   void SetStretchContentToFillBounds(bool stretch_content);
stretch_content_to_fill_bounds()50   bool stretch_content_to_fill_bounds() const {
51     return stretch_content_to_fill_bounds_;
52   }
53 
54   void SetSurfaceHitTestable(bool surface_hit_testable);
surface_hit_testable()55   bool surface_hit_testable() const { return surface_hit_testable_; }
56 
57   void SetHasPointerEventsNone(bool has_pointer_events_none);
has_pointer_events_none()58   bool has_pointer_events_none() const { return has_pointer_events_none_; }
59 
60   void SetIsReflection(bool is_reflection);
is_reflection()61   bool is_reflection() const { return is_reflection_; }
62 
63   // LayerImpl overrides.
64   std::unique_ptr<LayerImpl> CreateLayerImpl(LayerTreeImpl* tree_impl) override;
65   void PushPropertiesTo(LayerImpl* layer) override;
66   bool WillDraw(DrawMode draw_mode,
67                 viz::ClientResourceProvider* resource_provider) override;
68   void AppendQuads(viz::CompositorRenderPass* render_pass,
69                    AppendQuadsData* append_quads_data) override;
70   bool is_surface_layer() const override;
71   gfx::Rect GetEnclosingRectInTargetSpace() const override;
72 
73  protected:
74   SurfaceLayerImpl(LayerTreeImpl* tree_impl, int id, UpdateSubmissionStateCB);
75 
76  private:
77   void GetDebugBorderProperties(SkColor* color, float* width) const override;
78   void AppendRainbowDebugBorder(viz::CompositorRenderPass* render_pass);
79   void AsValueInto(base::trace_event::TracedValue* dict) const override;
80   const char* LayerTypeAsString() const override;
81 
82   UpdateSubmissionStateCB update_submission_state_callback_;
83   viz::SurfaceRange surface_range_;
84   base::Optional<uint32_t> deadline_in_frames_;
85 
86   bool stretch_content_to_fill_bounds_ = false;
87   bool surface_hit_testable_ = false;
88   bool has_pointer_events_none_ = false;
89   bool is_reflection_ = false;
90   bool will_draw_ = false;
91 };
92 
93 }  // namespace cc
94 
95 #endif  // CC_LAYERS_SURFACE_LAYER_IMPL_H_
96