texture_layer_impl.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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_TEXTURE_LAYER_IMPL_H_
  5. #define CC_LAYERS_TEXTURE_LAYER_IMPL_H_
  6. #include <memory>
  7. #include <string>
  8. #include <vector>
  9. #include "base/callback.h"
  10. #include "base/containers/flat_map.h"
  11. #include "base/memory/ptr_util.h"
  12. #include "cc/cc_export.h"
  13. #include "cc/layers/layer_impl.h"
  14. #include "cc/resources/cross_thread_shared_bitmap.h"
  15. #include "components/viz/common/resources/release_callback.h"
  16. #include "components/viz/common/resources/transferable_resource.h"
  17. namespace cc {
  18. class CC_EXPORT TextureLayerImpl : public LayerImpl {
  19. public:
  20. static std::unique_ptr<TextureLayerImpl> Create(LayerTreeImpl* tree_impl,
  21. int id) {
  22. return base::WrapUnique(new TextureLayerImpl(tree_impl, id));
  23. }
  24. TextureLayerImpl(const TextureLayerImpl&) = delete;
  25. ~TextureLayerImpl() override;
  26. TextureLayerImpl& operator=(const TextureLayerImpl&) = delete;
  27. std::unique_ptr<LayerImpl> CreateLayerImpl(
  28. LayerTreeImpl* layer_tree_impl) const override;
  29. bool IsSnappedToPixelGridInTarget() override;
  30. void PushPropertiesTo(LayerImpl* layer) override;
  31. bool WillDraw(DrawMode draw_mode,
  32. viz::ClientResourceProvider* resource_provider) override;
  33. void AppendQuads(viz::CompositorRenderPass* render_pass,
  34. AppendQuadsData* append_quads_data) override;
  35. SimpleEnclosedRegion VisibleOpaqueRegion() const override;
  36. void ReleaseResources() override;
  37. void OnPurgeMemory() override;
  38. gfx::ContentColorUsage GetContentColorUsage() const override;
  39. // These setter methods don't cause any implicit damage, so the texture client
  40. // must explicitly invalidate if they intend to cause a visible change in the
  41. // layer's output.
  42. void SetTextureId(unsigned id);
  43. void SetPremultipliedAlpha(bool premultiplied_alpha);
  44. void SetBlendBackgroundColor(bool blend);
  45. void SetForceTextureToOpaque(bool opaque);
  46. void SetFlipped(bool flipped);
  47. void SetNearestNeighbor(bool nearest_neighbor);
  48. void SetUVTopLeft(const gfx::PointF& top_left);
  49. void SetUVBottomRight(const gfx::PointF& bottom_right);
  50. void SetTransferableResource(const viz::TransferableResource& resource,
  51. viz::ReleaseCallback release_callback);
  52. // These methods notify the display compositor, through the
  53. // CompositorFrameSink, of the existence of a SharedBitmapId and its
  54. // mapping to a SharedMemory in |bitmap|. Then this SharedBitmapId can be used
  55. // in TransferableResources inserted on the layer while it is registered. If
  56. // the layer is destroyed, the SharedBitmapId will be unregistered
  57. // automatically, and if the CompositorFrameSink is replaced, it will be
  58. // re-registered on the new one. The SharedMemory must be kept alive while it
  59. // is registered.
  60. // If this is a pending layer, the registration is deferred to the active
  61. // layer.
  62. void RegisterSharedBitmapId(viz::SharedBitmapId id,
  63. scoped_refptr<CrossThreadSharedBitmap> bitmap);
  64. void UnregisterSharedBitmapId(viz::SharedBitmapId id);
  65. private:
  66. TextureLayerImpl(LayerTreeImpl* tree_impl, int id);
  67. const char* LayerTypeAsString() const override;
  68. void FreeTransferableResource();
  69. bool premultiplied_alpha_ = true;
  70. bool blend_background_color_ = false;
  71. bool force_texture_to_opaque_ = false;
  72. bool flipped_ = true;
  73. bool nearest_neighbor_ = false;
  74. gfx::PointF uv_top_left_ = gfx::PointF();
  75. gfx::PointF uv_bottom_right_ = gfx::PointF(1.f, 1.f);
  76. // True while the |transferable_resource_| is owned by this layer, and
  77. // becomes false once it is passed to another layer or to the
  78. // viz::ClientResourceProvider, at which point we get back a |resource_id_|.
  79. bool own_resource_ = false;
  80. // A TransferableResource from the layer's client that will be given
  81. // to the display compositor.
  82. viz::TransferableResource transferable_resource_;
  83. // Local ResourceId for the TransferableResource, to be used with the
  84. // compositor's viz::ClientResourceProvider in order to refer to the
  85. // TransferableResource given to it.
  86. viz::ResourceId resource_id_ = viz::kInvalidResourceId;
  87. viz::ReleaseCallback release_callback_;
  88. // As a pending layer, the set of SharedBitmapIds and the underlying
  89. // base::SharedMemory that must be notified to the display compositor through
  90. // the LayerTreeFrameSink. These will be passed to the active layer. As an
  91. // active layer, the set of SharedBitmapIds that need to be registered but
  92. // have not been yet, since it is done lazily.
  93. base::flat_map<viz::SharedBitmapId, scoped_refptr<CrossThreadSharedBitmap>>
  94. to_register_bitmaps_;
  95. // For active layers only. The set of SharedBitmapIds and ownership of the
  96. // underlying base::SharedMemory that have been notified to the display
  97. // compositor through the LayerTreeFrameSink. These will need to be
  98. // re-registered if the LayerTreeFrameSink changes (ie ReleaseResources()
  99. // occurs).
  100. base::flat_map<viz::SharedBitmapId, scoped_refptr<CrossThreadSharedBitmap>>
  101. registered_bitmaps_;
  102. // As a pending layer, the set of SharedBitmapIds that the active layer should
  103. // unregister.
  104. std::vector<viz::SharedBitmapId> to_unregister_bitmap_ids_;
  105. };
  106. } // namespace cc
  107. #endif // CC_LAYERS_TEXTURE_LAYER_IMPL_H_