RenderArea.h 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #pragma once
  2. #include <ui/GraphicTypes.h>
  3. #include <ui/Transform.h>
  4. #include <functional>
  5. namespace android {
  6. class DisplayDevice;
  7. // RenderArea describes a rectangular area that layers can be rendered to.
  8. //
  9. // There is a logical render area and a physical render area. When a layer is
  10. // rendered to the render area, it is first transformed and clipped to the logical
  11. // render area. The transformed and clipped layer is then projected onto the
  12. // physical render area.
  13. class RenderArea {
  14. public:
  15. enum class CaptureFill {CLEAR, OPAQUE};
  16. static float getCaptureFillValue(CaptureFill captureFill);
  17. RenderArea(uint32_t reqWidth, uint32_t reqHeight, CaptureFill captureFill,
  18. ui::Dataspace reqDataSpace,
  19. ui::Transform::orientation_flags rotation = ui::Transform::ROT_0)
  20. : mReqWidth(reqWidth),
  21. mReqHeight(reqHeight),
  22. mReqDataSpace(reqDataSpace),
  23. mCaptureFill(captureFill),
  24. mRotationFlags(rotation) {}
  25. virtual ~RenderArea() = default;
  26. // Invoke drawLayers to render layers into the render area.
  27. virtual void render(std::function<void()> drawLayers) { drawLayers(); }
  28. // Returns true if the render area is secure. A secure layer should be
  29. // blacked out / skipped when rendered to an insecure render area.
  30. virtual bool isSecure() const = 0;
  31. // Returns true if the otherwise disabled layer filtering should be
  32. // enabled when rendering to this render area.
  33. virtual bool needsFiltering() const = 0;
  34. // Returns the transform to be applied on layers to transform them into
  35. // the logical render area.
  36. virtual const ui::Transform& getTransform() const = 0;
  37. // Returns the size of the logical render area. Layers are clipped to the
  38. // logical render area.
  39. virtual int getWidth() const = 0;
  40. virtual int getHeight() const = 0;
  41. virtual Rect getBounds() const = 0;
  42. // Returns the source crop of the render area. The source crop defines
  43. // how layers are projected from the logical render area onto the physical
  44. // render area. It can be larger than the logical render area. It can
  45. // also be optionally rotated.
  46. //
  47. // Layers are first clipped to the source crop (in addition to being
  48. // clipped to the logical render area already). The source crop and the
  49. // layers are then rotated around the center of the source crop, and
  50. // scaled to the physical render area linearly.
  51. virtual Rect getSourceCrop() const = 0;
  52. // Returns the rotation of the source crop and the layers.
  53. ui::Transform::orientation_flags getRotationFlags() const { return mRotationFlags; };
  54. // Returns the size of the physical render area.
  55. int getReqWidth() const { return mReqWidth; };
  56. int getReqHeight() const { return mReqHeight; };
  57. // Returns the composition data space of the render area.
  58. ui::Dataspace getReqDataSpace() const { return mReqDataSpace; }
  59. // Returns the fill color of the physical render area. Regions not
  60. // covered by any rendered layer should be filled with this color.
  61. CaptureFill getCaptureFill() const { return mCaptureFill; };
  62. virtual const sp<const DisplayDevice> getDisplayDevice() const = 0;
  63. private:
  64. const uint32_t mReqWidth;
  65. const uint32_t mReqHeight;
  66. const ui::Dataspace mReqDataSpace;
  67. const CaptureFill mCaptureFill;
  68. const ui::Transform::orientation_flags mRotationFlags;
  69. };
  70. } // namespace android