blob: 38f4cbc6399e1d0653dc1e7619ab072d249b789e [file] [log] [blame]
chaviwa76b2712017-09-20 12:02:26 -07001#pragma once
2
Peiyong Linfd997e02018-03-28 15:29:00 -07003#include <ui/GraphicTypes.h>
Peiyong Lina52f0292018-03-14 17:26:31 -07004
chaviwa76b2712017-09-20 12:02:26 -07005#include "Transform.h"
6
Robert Carr578038f2018-03-09 12:25:24 -08007#include <functional>
8
chaviwa76b2712017-09-20 12:02:26 -07009namespace android {
10
Chia-I Wufed28572018-08-23 12:05:27 -070011// 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.
chaviwa76b2712017-09-20 12:02:26 -070017class RenderArea {
18public:
chaviw50da5042018-04-09 13:49:37 -070019 enum class CaptureFill {CLEAR, OPAQUE};
20
21 static float getCaptureFillValue(CaptureFill captureFill);
22
Chia-I Wu07f190f2018-08-23 13:44:43 -070023 RenderArea(uint32_t reqWidth, uint32_t reqHeight, CaptureFill captureFill,
chaviw7206d492017-11-10 16:16:12 -080024 ISurfaceComposer::Rotation rotation = ISurfaceComposer::eRotateNone)
Chia-I Wu07f190f2018-08-23 13:44:43 -070025 : mReqWidth(reqWidth), mReqHeight(reqHeight), mCaptureFill(captureFill) {
chaviwa76b2712017-09-20 12:02:26 -070026 mRotationFlags = Transform::fromRotation(rotation);
27 }
28
29 virtual ~RenderArea() = default;
30
Chia-I Wufed28572018-08-23 12:05:27 -070031 // Invoke drawLayers to render layers into the render area.
Robert Carr578038f2018-03-09 12:25:24 -080032 virtual void render(std::function<void()> drawLayers) { drawLayers(); }
33
Chia-I Wufed28572018-08-23 12:05:27 -070034 // 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;
chaviwa76b2712017-09-20 12:02:26 -070037
Chia-I Wufed28572018-08-23 12:05:27 -070038 // 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.
chaviw50da5042018-04-09 13:49:37 -070072 CaptureFill getCaptureFill() const { return mCaptureFill; };
73
Chia-I Wufed28572018-08-23 12:05:27 -070074 status_t updateDimensions(int displayRotation);
75
chaviwa76b2712017-09-20 12:02:26 -070076private:
chaviwa76b2712017-09-20 12:02:26 -070077 uint32_t mReqWidth;
Chia-I Wu07f190f2018-08-23 13:44:43 -070078 uint32_t mReqHeight;
chaviwa76b2712017-09-20 12:02:26 -070079 Transform::orientation_flags mRotationFlags;
chaviw50da5042018-04-09 13:49:37 -070080 CaptureFill mCaptureFill;
chaviwa76b2712017-09-20 12:02:26 -070081};
82
Chia-I Wu83ce7c12017-10-19 15:18:55 -070083} // namespace android