picture_layer.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. // Copyright 2012 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_PICTURE_LAYER_H_
  5. #define CC_LAYERS_PICTURE_LAYER_H_
  6. #include <memory>
  7. #include <vector>
  8. #include "base/memory/raw_ptr.h"
  9. #include "cc/base/devtools_instrumentation.h"
  10. #include "cc/base/invalidation_region.h"
  11. #include "cc/benchmarks/micro_benchmark_controller.h"
  12. #include "cc/layers/layer.h"
  13. namespace cc {
  14. class ContentLayerClient;
  15. class DisplayItemList;
  16. class RecordingSource;
  17. class CC_EXPORT PictureLayer : public Layer {
  18. public:
  19. static scoped_refptr<PictureLayer> Create(ContentLayerClient* client);
  20. PictureLayer(const PictureLayer&) = delete;
  21. PictureLayer& operator=(const PictureLayer&) = delete;
  22. void ClearClient();
  23. void SetNearestNeighbor(bool nearest_neighbor);
  24. bool nearest_neighbor() const {
  25. return picture_layer_inputs_.nearest_neighbor;
  26. }
  27. void SetIsBackdropFilterMask(bool is_backdrop_filter_mask);
  28. bool is_backdrop_filter_mask() const {
  29. return picture_layer_inputs_.is_backdrop_filter_mask;
  30. }
  31. // Layer interface.
  32. std::unique_ptr<LayerImpl> CreateLayerImpl(
  33. LayerTreeImpl* tree_impl) const override;
  34. void SetLayerTreeHost(LayerTreeHost* host) override;
  35. void PushPropertiesTo(LayerImpl* layer,
  36. const CommitState& commit_state,
  37. const ThreadUnsafeCommitState& unsafe_state) override;
  38. void SetNeedsDisplayRect(const gfx::Rect& layer_rect) override;
  39. sk_sp<const SkPicture> GetPicture() const override;
  40. bool Update() override;
  41. void RunMicroBenchmark(MicroBenchmark* benchmark) override;
  42. void CaptureContent(const gfx::Rect& rect,
  43. std::vector<NodeInfo>* content) const override;
  44. ContentLayerClient* client() { return picture_layer_inputs_.client; }
  45. RecordingSource* GetRecordingSourceForTesting() {
  46. return recording_source_.Write(*this).get();
  47. }
  48. const RecordingSource* GetRecordingSourceForTesting() const {
  49. return recording_source_.Read(*this);
  50. }
  51. const DisplayItemList* GetDisplayItemList() const;
  52. gfx::Vector2dF DirectlyCompositedImageDefaultRasterScaleForTesting() const {
  53. return picture_layer_inputs_.directly_composited_image_default_raster_scale;
  54. }
  55. protected:
  56. // Encapsulates all data, callbacks or interfaces received from the embedder.
  57. struct PictureLayerInputs {
  58. PictureLayerInputs();
  59. ~PictureLayerInputs();
  60. raw_ptr<ContentLayerClient> client = nullptr;
  61. bool nearest_neighbor = false;
  62. bool is_backdrop_filter_mask = false;
  63. scoped_refptr<DisplayItemList> display_list;
  64. gfx::Vector2dF directly_composited_image_default_raster_scale;
  65. };
  66. explicit PictureLayer(ContentLayerClient* client);
  67. // Allow tests to inject a recording source.
  68. PictureLayer(ContentLayerClient* client,
  69. std::unique_ptr<RecordingSource> source);
  70. ~PictureLayer() override;
  71. bool HasDrawableContent() const override;
  72. PictureLayerInputs picture_layer_inputs_;
  73. private:
  74. friend class TestSerializationPictureLayer;
  75. // Called on impl thread
  76. void DropRecordingSourceContentIfInvalid(int source_frame_number);
  77. ProtectedSequenceWritable<std::unique_ptr<RecordingSource>> recording_source_;
  78. ProtectedSequenceForbidden<devtools_instrumentation::ScopedLayerObjectTracker>
  79. instrumentation_object_tracker_;
  80. ProtectedSequenceWritable<Region> last_updated_invalidation_;
  81. ProtectedSequenceReadable<int> update_source_frame_number_;
  82. };
  83. } // namespace cc
  84. #endif // CC_LAYERS_PICTURE_LAYER_H_