nine_patch_layer.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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_NINE_PATCH_LAYER_H_
  5. #define CC_LAYERS_NINE_PATCH_LAYER_H_
  6. #include <memory>
  7. #include "cc/cc_export.h"
  8. #include "cc/layers/layer.h"
  9. #include "cc/layers/ui_resource_layer.h"
  10. #include "cc/resources/ui_resource_client.h"
  11. #include "ui/gfx/geometry/rect.h"
  12. namespace cc {
  13. class CC_EXPORT NinePatchLayer : public UIResourceLayer {
  14. public:
  15. static scoped_refptr<NinePatchLayer> Create();
  16. NinePatchLayer(const NinePatchLayer&) = delete;
  17. NinePatchLayer& operator=(const NinePatchLayer&) = delete;
  18. void PushPropertiesTo(LayerImpl* layer,
  19. const CommitState& commit_state,
  20. const ThreadUnsafeCommitState& unsafe_state) override;
  21. // |border| is the space around the center rectangular region in layer space
  22. // (known as aperture in image space). |border.x()| and |border.y()| are the
  23. // size of the left and top boundary, respectively.
  24. // |border.width()-border.x()| and |border.height()-border.y()| are the size
  25. // of the right and bottom boundary, respectively.
  26. void SetBorder(const gfx::Rect& border);
  27. // aperture is in the pixel space of the bitmap resource and refers to
  28. // the center patch of the ninepatch (which is unused in this
  29. // implementation). We split off eight rects surrounding it and stick them
  30. // on the edges of the layer. The corners are unscaled, the top and bottom
  31. // rects are x-stretched to fit, and the left and right rects are
  32. // y-stretched to fit.
  33. void SetAperture(const gfx::Rect& aperture);
  34. void SetFillCenter(bool fill_center);
  35. void SetNearestNeighbor(bool nearest_neighbor);
  36. // |rect| is the space completely occluded by another layer in layer
  37. // space. This can be used for example to occlude the entire window's
  38. // content when drawing the shadow with a 9 patches layer.
  39. void SetLayerOcclusion(const gfx::Rect& occlusion);
  40. private:
  41. NinePatchLayer();
  42. ~NinePatchLayer() override;
  43. std::unique_ptr<LayerImpl> CreateLayerImpl(
  44. LayerTreeImpl* tree_impl) const override;
  45. ProtectedSequenceReadable<gfx::Rect> border_;
  46. ProtectedSequenceReadable<bool> fill_center_;
  47. ProtectedSequenceReadable<bool> nearest_neighbor_;
  48. // The transparent center region that shows the parent layer's contents in
  49. // image space.
  50. ProtectedSequenceReadable<gfx::Rect> image_aperture_;
  51. // The occluded region in layer space set by SetLayerOcclusion. It is
  52. // usually larger than |image_aperture_|.
  53. ProtectedSequenceReadable<gfx::Rect> layer_occlusion_;
  54. };
  55. } // namespace cc
  56. #endif // CC_LAYERS_NINE_PATCH_LAYER_H_