blob: 387364c03aedadac7de1dfa3917a88fd57fc3c02 [file] [log] [blame]
chaviwa76b2712017-09-20 12:02:26 -07001#pragma once
2
Peiyong Lin0e003c92018-09-17 11:09:51 -07003#include <ui/GraphicTypes.h>
Peiyong Linefefaac2018-08-17 12:27:51 -07004#include <ui/Transform.h>
chaviwa76b2712017-09-20 12:02:26 -07005
Robert Carr578038f2018-03-09 12:25:24 -08006#include <functional>
Robert Carr12a3b9b2022-03-10 09:55:29 -08007#include "Layer.h"
Robert Carr578038f2018-03-09 12:25:24 -08008
chaviwa76b2712017-09-20 12:02:26 -07009namespace android {
10
Lloyd Pique37c2c9b2018-12-04 17:25:10 -080011class DisplayDevice;
12
Chia-I Wub68fac72018-08-23 12:05:27 -070013// RenderArea describes a rectangular area that layers can be rendered to.
14//
15// There is a logical render area and a physical render area. When a layer is
16// rendered to the render area, it is first transformed and clipped to the logical
17// render area. The transformed and clipped layer is then projected onto the
18// physical render area.
chaviwa76b2712017-09-20 12:02:26 -070019class RenderArea {
20public:
Dominik Laskowski718f9602019-11-09 20:01:35 -080021 using RotationFlags = ui::Transform::RotationFlags;
22
chaviw50da5042018-04-09 13:49:37 -070023 enum class CaptureFill {CLEAR, OPAQUE};
24
25 static float getCaptureFillValue(CaptureFill captureFill);
26
Marin Shalamanov1c434292020-06-12 01:47:29 +020027 RenderArea(ui::Size reqSize, CaptureFill captureFill, ui::Dataspace reqDataSpace,
Marin Shalamanov6ad317c2020-07-29 23:34:07 +020028 const Rect& layerStackRect, bool allowSecureLayers = false,
chaviw70cb6a42020-07-30 13:57:36 -070029 RotationFlags rotation = ui::Transform::ROT_0)
30 : mAllowSecureLayers(allowSecureLayers),
31 mReqSize(reqSize),
Peiyong Lin0e003c92018-09-17 11:09:51 -070032 mReqDataSpace(reqDataSpace),
Chia-I Wuc80dcbb2018-08-24 15:34:02 -070033 mCaptureFill(captureFill),
Vishnu Nair3a7346c2019-12-04 08:09:09 -080034 mRotationFlags(rotation),
Marin Shalamanov6ad317c2020-07-29 23:34:07 +020035 mLayerStackSpaceRect(layerStackRect) {}
chaviwa76b2712017-09-20 12:02:26 -070036
37 virtual ~RenderArea() = default;
38
Chia-I Wub68fac72018-08-23 12:05:27 -070039 // Invoke drawLayers to render layers into the render area.
Robert Carr578038f2018-03-09 12:25:24 -080040 virtual void render(std::function<void()> drawLayers) { drawLayers(); }
41
Chia-I Wub68fac72018-08-23 12:05:27 -070042 // Returns true if the render area is secure. A secure layer should be
43 // blacked out / skipped when rendered to an insecure render area.
44 virtual bool isSecure() const = 0;
chaviwa76b2712017-09-20 12:02:26 -070045
Chia-I Wub68fac72018-08-23 12:05:27 -070046 // Returns true if the otherwise disabled layer filtering should be
47 // enabled when rendering to this render area.
48 virtual bool needsFiltering() const = 0;
49
50 // Returns the transform to be applied on layers to transform them into
51 // the logical render area.
52 virtual const ui::Transform& getTransform() const = 0;
53
54 // Returns the size of the logical render area. Layers are clipped to the
55 // logical render area.
56 virtual int getWidth() const = 0;
57 virtual int getHeight() const = 0;
58 virtual Rect getBounds() const = 0;
59
60 // Returns the source crop of the render area. The source crop defines
61 // how layers are projected from the logical render area onto the physical
62 // render area. It can be larger than the logical render area. It can
63 // also be optionally rotated.
64 //
Alec Mouri5a6d8572020-03-23 23:56:15 -070065 // The source crop is specified in layer space (when rendering a layer and
66 // its children), or in layer-stack space (when rendering all layers visible
67 // on the display).
Chia-I Wub68fac72018-08-23 12:05:27 -070068 virtual Rect getSourceCrop() const = 0;
69
70 // Returns the rotation of the source crop and the layers.
Dominik Laskowski718f9602019-11-09 20:01:35 -080071 RotationFlags getRotationFlags() const { return mRotationFlags; }
Chia-I Wub68fac72018-08-23 12:05:27 -070072
73 // Returns the size of the physical render area.
Marin Shalamanov1c434292020-06-12 01:47:29 +020074 int getReqWidth() const { return mReqSize.width; }
75 int getReqHeight() const { return mReqSize.height; }
Chia-I Wub68fac72018-08-23 12:05:27 -070076
Peiyong Lin0e003c92018-09-17 11:09:51 -070077 // Returns the composition data space of the render area.
78 ui::Dataspace getReqDataSpace() const { return mReqDataSpace; }
79
Chia-I Wub68fac72018-08-23 12:05:27 -070080 // Returns the fill color of the physical render area. Regions not
81 // covered by any rendered layer should be filled with this color.
Dominik Laskowski718f9602019-11-09 20:01:35 -080082 CaptureFill getCaptureFill() const { return mCaptureFill; }
chaviw50da5042018-04-09 13:49:37 -070083
Dominik Laskowski718f9602019-11-09 20:01:35 -080084 virtual sp<const DisplayDevice> getDisplayDevice() const = 0;
Lloyd Pique37c2c9b2018-12-04 17:25:10 -080085
Vishnu Nair3a7346c2019-12-04 08:09:09 -080086 // Returns the source display viewport.
Marin Shalamanov6ad317c2020-07-29 23:34:07 +020087 const Rect& getLayerStackSpaceRect() const { return mLayerStackSpaceRect; }
Vishnu Nair3a7346c2019-12-04 08:09:09 -080088
Robert Carr12a3b9b2022-03-10 09:55:29 -080089 // If this is a LayerRenderArea, return the root layer of the
90 // capture operation.
91 virtual sp<Layer> getParentLayer() const { return nullptr; }
92
chaviw70cb6a42020-07-30 13:57:36 -070093protected:
94 const bool mAllowSecureLayers;
95
chaviwa76b2712017-09-20 12:02:26 -070096private:
Marin Shalamanov1c434292020-06-12 01:47:29 +020097 const ui::Size mReqSize;
Peiyong Lin0e003c92018-09-17 11:09:51 -070098 const ui::Dataspace mReqDataSpace;
Chia-I Wuc80dcbb2018-08-24 15:34:02 -070099 const CaptureFill mCaptureFill;
Dominik Laskowski718f9602019-11-09 20:01:35 -0800100 const RotationFlags mRotationFlags;
Marin Shalamanov6ad317c2020-07-29 23:34:07 +0200101 const Rect mLayerStackSpaceRect;
chaviwa76b2712017-09-20 12:02:26 -0700102};
103
Chia-I Wu83ce7c12017-10-19 15:18:55 -0700104} // namespace android