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