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_H_ 6 #define CC_LAYERS_SURFACE_LAYER_H_ 7 8 #include <memory> 9 10 #include "cc/cc_export.h" 11 #include "cc/layers/deadline_policy.h" 12 #include "cc/layers/layer.h" 13 #include "components/viz/common/surfaces/surface_info.h" 14 #include "components/viz/common/surfaces/surface_range.h" 15 #include "third_party/skia/include/core/SkColor.h" 16 #include "ui/gfx/geometry/size.h" 17 18 namespace base { 19 class WaitableEvent; 20 } 21 22 namespace cc { 23 24 // If given true, we should submit frames, as we are unoccluded on screen. 25 // If given false, we should not submit compositor frames. 26 // The second parameter is only used in tests to ensure that the 27 // UpdateSubmissionStateCB is called synchronously relative to the calling 28 // thread. That is, the calling thread will block on the given waitable event 29 // when calling the callback. It is the responsibility of the callback to signal 30 // the event once the state has been updated. If blocking is not required, then 31 // the second parameter will be nullptr. 32 using UpdateSubmissionStateCB = 33 base::RepeatingCallback<void(bool is_visible, base::WaitableEvent*)>; 34 35 // A layer that renders a surface referencing the output of another compositor 36 // instance or client. 37 class CC_EXPORT SurfaceLayer : public Layer { 38 public: 39 static scoped_refptr<SurfaceLayer> Create(); 40 static scoped_refptr<SurfaceLayer> Create(UpdateSubmissionStateCB); 41 42 SurfaceLayer(const SurfaceLayer&) = delete; 43 SurfaceLayer& operator=(const SurfaceLayer&) = delete; 44 45 void SetSurfaceId(const viz::SurfaceId& surface_id, 46 const DeadlinePolicy& deadline_policy); 47 void SetOldestAcceptableFallback(const viz::SurfaceId& surface_id); 48 49 // When stretch_content_to_fill_bounds is true, the scale of the embedded 50 // surface is ignored and the content will be stretched to fill the bounds. 51 void SetStretchContentToFillBounds(bool stretch_content_to_fill_bounds); stretch_content_to_fill_bounds()52 bool stretch_content_to_fill_bounds() const { 53 return stretch_content_to_fill_bounds_; 54 } 55 56 void SetSurfaceHitTestable(bool surface_hit_testable); 57 58 void SetHasPointerEventsNone(bool has_pointer_events_none); 59 60 void SetIsReflection(bool is_reflection); 61 62 void SetMayContainVideo(bool may_contain_video); 63 64 // Layer overrides. 65 std::unique_ptr<LayerImpl> CreateLayerImpl(LayerTreeImpl* tree_impl) override; 66 void SetLayerTreeHost(LayerTreeHost* host) override; 67 void PushPropertiesTo(LayerImpl* layer) override; 68 surface_id()69 const viz::SurfaceId& surface_id() const { return surface_range_.end(); } 70 oldest_acceptable_fallback()71 const base::Optional<viz::SurfaceId>& oldest_acceptable_fallback() const { 72 return surface_range_.start(); 73 } 74 deadline_in_frames()75 base::Optional<uint32_t> deadline_in_frames() const { 76 return deadline_in_frames_; 77 } 78 79 protected: 80 SurfaceLayer(); 81 explicit SurfaceLayer(UpdateSubmissionStateCB); 82 bool HasDrawableContent() const override; 83 84 private: 85 ~SurfaceLayer() override; 86 87 UpdateSubmissionStateCB update_submission_state_callback_; 88 89 bool may_contain_video_ = false; 90 viz::SurfaceRange surface_range_; 91 base::Optional<uint32_t> deadline_in_frames_ = 0u; 92 93 bool stretch_content_to_fill_bounds_ = false; 94 95 // Whether or not the surface should submit hit test data when submitting 96 // compositor frame. The bit represents that the surface layer may be 97 // associated with an out-of-process iframe and viz hit testing needs to know 98 // the hit test information of that iframe. This bit is different from a layer 99 // being hit testable in the renderer, a hit testable surface layer may not 100 // be surface hit testable (e.g., a surface layer created by video). 101 bool surface_hit_testable_ = false; 102 103 // Whether or not the surface can accept pointer events. It is set to true if 104 // the frame owner has pointer-events: none property. 105 // TODO(sunxd): consider renaming it to oopif_has_pointer_events_none_ for 106 // disambiguation. 107 bool has_pointer_events_none_ = false; 108 109 // This surface layer is reflecting the root surface of another display. 110 bool is_reflection_ = false; 111 }; 112 113 } // namespace cc 114 115 #endif // CC_LAYERS_SURFACE_LAYER_H_ 116