chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Peiyong Lin | efefaac | 2018-08-17 12:27:51 -0700 | [diff] [blame] | 3 | #include <ui/Transform.h> |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 4 | |
Robert Carr | 578038f | 2018-03-09 12:25:24 -0800 | [diff] [blame] | 5 | #include <functional> |
| 6 | |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 7 | namespace android { |
| 8 | |
Chia-I Wu | b68fac7 | 2018-08-23 12:05:27 -0700 | [diff] [blame] | 9 | // RenderArea describes a rectangular area that layers can be rendered to. |
| 10 | // |
| 11 | // There is a logical render area and a physical render area. When a layer is |
| 12 | // rendered to the render area, it is first transformed and clipped to the logical |
| 13 | // render area. The transformed and clipped layer is then projected onto the |
| 14 | // physical render area. |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 15 | class RenderArea { |
| 16 | public: |
chaviw | 50da504 | 2018-04-09 13:49:37 -0700 | [diff] [blame] | 17 | enum class CaptureFill {CLEAR, OPAQUE}; |
| 18 | |
| 19 | static float getCaptureFillValue(CaptureFill captureFill); |
| 20 | |
Chia-I Wu | 9d1abea | 2018-08-23 13:44:43 -0700 | [diff] [blame] | 21 | RenderArea(uint32_t reqWidth, uint32_t reqHeight, CaptureFill captureFill, |
Chia-I Wu | c80dcbb | 2018-08-24 15:34:02 -0700 | [diff] [blame] | 22 | ui::Transform::orientation_flags rotation = ui::Transform::ROT_0) |
| 23 | : mReqWidth(reqWidth), |
| 24 | mReqHeight(reqHeight), |
| 25 | mCaptureFill(captureFill), |
| 26 | mRotationFlags(rotation) {} |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 27 | |
| 28 | virtual ~RenderArea() = default; |
| 29 | |
Chia-I Wu | b68fac7 | 2018-08-23 12:05:27 -0700 | [diff] [blame] | 30 | // Invoke drawLayers to render layers into the render area. |
Robert Carr | 578038f | 2018-03-09 12:25:24 -0800 | [diff] [blame] | 31 | virtual void render(std::function<void()> drawLayers) { drawLayers(); } |
| 32 | |
Chia-I Wu | b68fac7 | 2018-08-23 12:05:27 -0700 | [diff] [blame] | 33 | // Returns true if the render area is secure. A secure layer should be |
| 34 | // blacked out / skipped when rendered to an insecure render area. |
| 35 | virtual bool isSecure() const = 0; |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 36 | |
Chia-I Wu | b68fac7 | 2018-08-23 12:05:27 -0700 | [diff] [blame] | 37 | // Returns true if the otherwise disabled layer filtering should be |
| 38 | // enabled when rendering to this render area. |
| 39 | virtual bool needsFiltering() const = 0; |
| 40 | |
| 41 | // Returns the transform to be applied on layers to transform them into |
| 42 | // the logical render area. |
| 43 | virtual const ui::Transform& getTransform() const = 0; |
| 44 | |
| 45 | // Returns the size of the logical render area. Layers are clipped to the |
| 46 | // logical render area. |
| 47 | virtual int getWidth() const = 0; |
| 48 | virtual int getHeight() const = 0; |
| 49 | virtual Rect getBounds() const = 0; |
| 50 | |
| 51 | // Returns the source crop of the render area. The source crop defines |
| 52 | // how layers are projected from the logical render area onto the physical |
| 53 | // render area. It can be larger than the logical render area. It can |
| 54 | // also be optionally rotated. |
| 55 | // |
| 56 | // Layers are first clipped to the source crop (in addition to being |
| 57 | // clipped to the logical render area already). The source crop and the |
| 58 | // layers are then rotated around the center of the source crop, and |
| 59 | // scaled to the physical render area linearly. |
| 60 | virtual Rect getSourceCrop() const = 0; |
| 61 | |
| 62 | // Returns the rotation of the source crop and the layers. |
| 63 | ui::Transform::orientation_flags getRotationFlags() const { return mRotationFlags; }; |
| 64 | |
| 65 | // Returns the size of the physical render area. |
| 66 | int getReqWidth() const { return mReqWidth; }; |
| 67 | int getReqHeight() const { return mReqHeight; }; |
| 68 | |
| 69 | // Returns the fill color of the physical render area. Regions not |
| 70 | // covered by any rendered layer should be filled with this color. |
chaviw | 50da504 | 2018-04-09 13:49:37 -0700 | [diff] [blame] | 71 | CaptureFill getCaptureFill() const { return mCaptureFill; }; |
| 72 | |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 73 | private: |
Chia-I Wu | 20261cb | 2018-08-23 12:55:44 -0700 | [diff] [blame] | 74 | const uint32_t mReqWidth; |
| 75 | const uint32_t mReqHeight; |
Chia-I Wu | c80dcbb | 2018-08-24 15:34:02 -0700 | [diff] [blame] | 76 | const CaptureFill mCaptureFill; |
| 77 | const ui::Transform::orientation_flags mRotationFlags; |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 78 | }; |
| 79 | |
Chia-I Wu | 83ce7c1 | 2017-10-19 15:18:55 -0700 | [diff] [blame] | 80 | } // namespace android |