ui_resource_layer.h 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. // Copyright 2013 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_UI_RESOURCE_LAYER_H_
  5. #define CC_LAYERS_UI_RESOURCE_LAYER_H_
  6. #include <memory>
  7. #include "cc/cc_export.h"
  8. #include "cc/layers/layer.h"
  9. #include "cc/resources/ui_resource_client.h"
  10. #include "third_party/skia/include/core/SkBitmap.h"
  11. #include "ui/gfx/geometry/rect.h"
  12. namespace cc {
  13. class LayerTreeHost;
  14. class CC_EXPORT UIResourceLayer : public Layer {
  15. public:
  16. static scoped_refptr<UIResourceLayer> Create();
  17. UIResourceLayer(const UIResourceLayer&) = delete;
  18. UIResourceLayer& operator=(const UIResourceLayer&) = delete;
  19. void PushPropertiesTo(LayerImpl* layer,
  20. const CommitState& commit_state,
  21. const ThreadUnsafeCommitState& unsafe_state) override;
  22. void SetLayerTreeHost(LayerTreeHost* host) override;
  23. // Sets the resource. If they don't exist already, the shared UI resource and
  24. // ID are generated and cached in a map in the associated UIResourceManager.
  25. // Currently, this resource will never be released by the UIResourceManager.
  26. void SetBitmap(const SkBitmap& skbitmap);
  27. // An alternative way of setting the resource where an ID is used directly. If
  28. // you use this method, you are responsible for updating the ID if the layer
  29. // moves between compositors.
  30. void SetUIResourceId(UIResourceId resource_id);
  31. // Sets a UV transform to be used at draw time. Defaults to (0, 0) and (1, 1).
  32. void SetUV(const gfx::PointF& top_left, const gfx::PointF& bottom_right);
  33. // Sets an opacity value per vertex. It will be multiplied by the layer
  34. // opacity value.
  35. void SetVertexOpacity(float bottom_left,
  36. float top_left,
  37. float top_right,
  38. float bottom_right);
  39. protected:
  40. UIResourceLayer();
  41. ~UIResourceLayer() override;
  42. bool HasDrawableContent() const override;
  43. UIResourceId resource_id() const { return resource_id_.Read(*this); }
  44. private:
  45. std::unique_ptr<LayerImpl> CreateLayerImpl(
  46. LayerTreeImpl* tree_impl) const override;
  47. void RecreateUIResourceIdFromBitmap();
  48. void SetUIResourceIdInternal(UIResourceId resource_id);
  49. // The resource ID will be zero when it's unset or when there's no associated
  50. // LayerTreeHost.
  51. ProtectedSequenceReadable<UIResourceId> resource_id_;
  52. ProtectedSequenceForbidden<SkBitmap> bitmap_;
  53. ProtectedSequenceReadable<gfx::PointF> uv_top_left_;
  54. ProtectedSequenceReadable<gfx::PointF> uv_bottom_right_;
  55. ProtectedSequenceReadable<float[4]> vertex_opacity_;
  56. };
  57. } // namespace cc
  58. #endif // CC_LAYERS_UI_RESOURCE_LAYER_H_