Marin Shalamanov | f6b5d18 | 2020-06-12 02:08:51 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2020 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include "DisplayRenderArea.h" |
| 18 | #include "DisplayDevice.h" |
| 19 | |
| 20 | namespace android { |
| 21 | namespace { |
| 22 | |
chaviw | c6ad8af | 2020-08-03 11:33:30 -0700 | [diff] [blame] | 23 | RenderArea::RotationFlags applyDeviceOrientation(bool useIdentityTransform, |
Marin Shalamanov | f6b5d18 | 2020-06-12 02:08:51 +0200 | [diff] [blame] | 24 | const DisplayDevice& display) { |
chaviw | c6ad8af | 2020-08-03 11:33:30 -0700 | [diff] [blame] | 25 | if (!useIdentityTransform) { |
| 26 | return RenderArea::RotationFlags::ROT_0; |
Marin Shalamanov | f6b5d18 | 2020-06-12 02:08:51 +0200 | [diff] [blame] | 27 | } |
| 28 | |
chaviw | 387aff5 | 2020-10-08 13:15:27 -0700 | [diff] [blame] | 29 | return ui::Transform::toRotationFlags(display.getOrientation()); |
Marin Shalamanov | f6b5d18 | 2020-06-12 02:08:51 +0200 | [diff] [blame] | 30 | } |
| 31 | |
| 32 | } // namespace |
| 33 | |
| 34 | std::unique_ptr<RenderArea> DisplayRenderArea::create(wp<const DisplayDevice> displayWeak, |
| 35 | const Rect& sourceCrop, ui::Size reqSize, |
| 36 | ui::Dataspace reqDataSpace, |
chaviw | c6ad8af | 2020-08-03 11:33:30 -0700 | [diff] [blame] | 37 | bool useIdentityTransform, |
Marin Shalamanov | f6b5d18 | 2020-06-12 02:08:51 +0200 | [diff] [blame] | 38 | bool allowSecureLayers) { |
| 39 | if (auto display = displayWeak.promote()) { |
| 40 | // Using new to access a private constructor. |
| 41 | return std::unique_ptr<DisplayRenderArea>( |
| 42 | new DisplayRenderArea(std::move(display), sourceCrop, reqSize, reqDataSpace, |
chaviw | c6ad8af | 2020-08-03 11:33:30 -0700 | [diff] [blame] | 43 | useIdentityTransform, allowSecureLayers)); |
Marin Shalamanov | f6b5d18 | 2020-06-12 02:08:51 +0200 | [diff] [blame] | 44 | } |
| 45 | return nullptr; |
| 46 | } |
| 47 | |
| 48 | DisplayRenderArea::DisplayRenderArea(sp<const DisplayDevice> display, const Rect& sourceCrop, |
| 49 | ui::Size reqSize, ui::Dataspace reqDataSpace, |
chaviw | c6ad8af | 2020-08-03 11:33:30 -0700 | [diff] [blame] | 50 | bool useIdentityTransform, bool allowSecureLayers) |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 51 | : RenderArea(reqSize, CaptureFill::OPAQUE, reqDataSpace, display->getLayerStackSpaceRect(), |
chaviw | c6ad8af | 2020-08-03 11:33:30 -0700 | [diff] [blame] | 52 | allowSecureLayers, applyDeviceOrientation(useIdentityTransform, *display)), |
Marin Shalamanov | f6b5d18 | 2020-06-12 02:08:51 +0200 | [diff] [blame] | 53 | mDisplay(std::move(display)), |
chaviw | 70cb6a4 | 2020-07-30 13:57:36 -0700 | [diff] [blame] | 54 | mSourceCrop(sourceCrop) {} |
Marin Shalamanov | f6b5d18 | 2020-06-12 02:08:51 +0200 | [diff] [blame] | 55 | |
| 56 | const ui::Transform& DisplayRenderArea::getTransform() const { |
| 57 | return mTransform; |
| 58 | } |
| 59 | |
| 60 | Rect DisplayRenderArea::getBounds() const { |
| 61 | return mDisplay->getBounds(); |
| 62 | } |
| 63 | |
| 64 | int DisplayRenderArea::getHeight() const { |
| 65 | return mDisplay->getHeight(); |
| 66 | } |
| 67 | |
| 68 | int DisplayRenderArea::getWidth() const { |
| 69 | return mDisplay->getWidth(); |
| 70 | } |
| 71 | |
| 72 | bool DisplayRenderArea::isSecure() const { |
| 73 | return mAllowSecureLayers && mDisplay->isSecure(); |
| 74 | } |
| 75 | |
| 76 | sp<const DisplayDevice> DisplayRenderArea::getDisplayDevice() const { |
| 77 | return mDisplay; |
| 78 | } |
| 79 | |
| 80 | bool DisplayRenderArea::needsFiltering() const { |
| 81 | // check if the projection from the logical render area |
| 82 | // to the physical render area requires filtering |
| 83 | const Rect& sourceCrop = getSourceCrop(); |
| 84 | int width = sourceCrop.width(); |
| 85 | int height = sourceCrop.height(); |
| 86 | if (getRotationFlags() & ui::Transform::ROT_90) { |
| 87 | std::swap(width, height); |
| 88 | } |
| 89 | return width != getReqWidth() || height != getReqHeight(); |
| 90 | } |
| 91 | |
| 92 | Rect DisplayRenderArea::getSourceCrop() const { |
| 93 | // use the projected display viewport by default. |
| 94 | if (mSourceCrop.isEmpty()) { |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 95 | return mDisplay->getLayerStackSpaceRect(); |
Marin Shalamanov | f6b5d18 | 2020-06-12 02:08:51 +0200 | [diff] [blame] | 96 | } |
| 97 | |
chaviw | c6ad8af | 2020-08-03 11:33:30 -0700 | [diff] [blame] | 98 | // Correct for the orientation when the screen capture request contained |
| 99 | // useIdentityTransform. This will cause the rotation flag to be non 0 since |
| 100 | // it needs to rotate based on the screen orientation to allow the screenshot |
| 101 | // to be taken in the ROT_0 orientation |
| 102 | const auto flags = getRotationFlags(); |
Marin Shalamanov | 6ad317c | 2020-07-29 23:34:07 +0200 | [diff] [blame] | 103 | int width = mDisplay->getLayerStackSpaceRect().getWidth(); |
| 104 | int height = mDisplay->getLayerStackSpaceRect().getHeight(); |
Marin Shalamanov | f6b5d18 | 2020-06-12 02:08:51 +0200 | [diff] [blame] | 105 | ui::Transform rotation; |
| 106 | rotation.set(flags, width, height); |
| 107 | return rotation.transform(mSourceCrop); |
| 108 | } |
| 109 | |
| 110 | } // namespace android |