blob: 918bbd3a475e6d20dea3a00f77a64c232689ff23 [file] [log] [blame]
chaviwa76b2712017-09-20 12:02:26 -07001#include "RenderArea.h"
2
Iris Chang7501ed62018-04-30 14:45:42 +08003#include <gui/LayerState.h>
4
chaviwa76b2712017-09-20 12:02:26 -07005namespace android {
6
Peiyong Linefefaac2018-08-17 12:27:51 -07007ui::Transform::orientation_flags fromRotation(ISurfaceComposer::Rotation rotation) {
8 switch (rotation) {
9 case ISurfaceComposer::eRotateNone:
10 return ui::Transform::ROT_0;
11 case ISurfaceComposer::eRotate90:
12 return ui::Transform::ROT_90;
13 case ISurfaceComposer::eRotate180:
14 return ui::Transform::ROT_180;
15 case ISurfaceComposer::eRotate270:
16 return ui::Transform::ROT_270;
17 }
18 ALOGE("Invalid rotation passed to captureScreen(): %d\n", rotation);
19 return ui::Transform::ROT_0;
20}
21
Chia-I Wu9d1abea2018-08-23 13:44:43 -070022RenderArea::RenderArea(uint32_t reqWidth, uint32_t reqHeight, CaptureFill captureFill,
Peiyong Linefefaac2018-08-17 12:27:51 -070023 ISurfaceComposer::Rotation rotation)
Chia-I Wu9d1abea2018-08-23 13:44:43 -070024 : mReqWidth(reqWidth), mReqHeight(reqHeight), mCaptureFill(captureFill) {
Peiyong Linefefaac2018-08-17 12:27:51 -070025 mRotationFlags = fromRotation(rotation);
26}
27
chaviw50da5042018-04-09 13:49:37 -070028float RenderArea::getCaptureFillValue(CaptureFill captureFill) {
29 switch(captureFill) {
30 case CaptureFill::CLEAR:
31 return 0.0f;
32 case CaptureFill::OPAQUE:
33 default:
34 return 1.0f;
35 }
36}
chaviwa76b2712017-09-20 12:02:26 -070037/*
38 * Checks that the requested width and height are valid and updates them to the render area
39 * dimensions if they are set to 0
40 */
Iris Chang7501ed62018-04-30 14:45:42 +080041status_t RenderArea::updateDimensions(int displayRotation) {
chaviwa76b2712017-09-20 12:02:26 -070042 // get screen geometry
43
44 uint32_t width = getWidth();
45 uint32_t height = getHeight();
46
Peiyong Linefefaac2018-08-17 12:27:51 -070047 if (mRotationFlags & ui::Transform::ROT_90) {
chaviwa76b2712017-09-20 12:02:26 -070048 std::swap(width, height);
49 }
50
Iris Chang7501ed62018-04-30 14:45:42 +080051 if (displayRotation & DisplayState::eOrientationSwapMask) {
52 std::swap(width, height);
53 }
54
chaviwa76b2712017-09-20 12:02:26 -070055 if ((mReqWidth > width) || (mReqHeight > height)) {
56 ALOGE("size mismatch (%d, %d) > (%d, %d)", mReqWidth, mReqHeight, width, height);
57 return BAD_VALUE;
58 }
59
60 if (mReqWidth == 0) {
61 mReqWidth = width;
62 }
63 if (mReqHeight == 0) {
64 mReqHeight = height;
65 }
66
67 return NO_ERROR;
68}
69
Iris Chang7501ed62018-04-30 14:45:42 +080070} // namespace android