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