surface_layer.h 4.5 KB

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