chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 1 | #include "RenderArea.h" |
| 2 | |
Iris Chang | 7501ed6 | 2018-04-30 14:45:42 +0800 | [diff] [blame] | 3 | #include <gui/LayerState.h> |
| 4 | |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 5 | namespace android { |
| 6 | |
Peiyong Lin | efefaac | 2018-08-17 12:27:51 -0700 | [diff] [blame] | 7 | ui::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 Wu | 9d1abea | 2018-08-23 13:44:43 -0700 | [diff] [blame^] | 22 | RenderArea::RenderArea(uint32_t reqWidth, uint32_t reqHeight, CaptureFill captureFill, |
Peiyong Lin | efefaac | 2018-08-17 12:27:51 -0700 | [diff] [blame] | 23 | ISurfaceComposer::Rotation rotation) |
Chia-I Wu | 9d1abea | 2018-08-23 13:44:43 -0700 | [diff] [blame^] | 24 | : mReqWidth(reqWidth), mReqHeight(reqHeight), mCaptureFill(captureFill) { |
Peiyong Lin | efefaac | 2018-08-17 12:27:51 -0700 | [diff] [blame] | 25 | mRotationFlags = fromRotation(rotation); |
| 26 | } |
| 27 | |
chaviw | 50da504 | 2018-04-09 13:49:37 -0700 | [diff] [blame] | 28 | float 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 | } |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 37 | /* |
| 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 Chang | 7501ed6 | 2018-04-30 14:45:42 +0800 | [diff] [blame] | 41 | status_t RenderArea::updateDimensions(int displayRotation) { |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 42 | // get screen geometry |
| 43 | |
| 44 | uint32_t width = getWidth(); |
| 45 | uint32_t height = getHeight(); |
| 46 | |
Peiyong Lin | efefaac | 2018-08-17 12:27:51 -0700 | [diff] [blame] | 47 | if (mRotationFlags & ui::Transform::ROT_90) { |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 48 | std::swap(width, height); |
| 49 | } |
| 50 | |
Iris Chang | 7501ed6 | 2018-04-30 14:45:42 +0800 | [diff] [blame] | 51 | if (displayRotation & DisplayState::eOrientationSwapMask) { |
| 52 | std::swap(width, height); |
| 53 | } |
| 54 | |
chaviw | a76b271 | 2017-09-20 12:02:26 -0700 | [diff] [blame] | 55 | 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 Chang | 7501ed6 | 2018-04-30 14:45:42 +0800 | [diff] [blame] | 70 | } // namespace android |