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