blob: 8f39e26e0f5cff65c082e6435896bfd8a2f3e8c5 [file] [log] [blame]
Marin Shalamanovf6b5d182020-06-12 02:08:51 +02001/*
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
20namespace android {
21namespace {
22
chaviwc6ad8af2020-08-03 11:33:30 -070023RenderArea::RotationFlags applyDeviceOrientation(bool useIdentityTransform,
Marin Shalamanovf6b5d182020-06-12 02:08:51 +020024 const DisplayDevice& display) {
chaviwc6ad8af2020-08-03 11:33:30 -070025 if (!useIdentityTransform) {
26 return RenderArea::RotationFlags::ROT_0;
Marin Shalamanovf6b5d182020-06-12 02:08:51 +020027 }
28
chaviw387aff52020-10-08 13:15:27 -070029 return ui::Transform::toRotationFlags(display.getOrientation());
Marin Shalamanovf6b5d182020-06-12 02:08:51 +020030}
31
32} // namespace
33
34std::unique_ptr<RenderArea> DisplayRenderArea::create(wp<const DisplayDevice> displayWeak,
35 const Rect& sourceCrop, ui::Size reqSize,
36 ui::Dataspace reqDataSpace,
chaviwc6ad8af2020-08-03 11:33:30 -070037 bool useIdentityTransform,
Marin Shalamanovf6b5d182020-06-12 02:08:51 +020038 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,
chaviwc6ad8af2020-08-03 11:33:30 -070043 useIdentityTransform, allowSecureLayers));
Marin Shalamanovf6b5d182020-06-12 02:08:51 +020044 }
45 return nullptr;
46}
47
48DisplayRenderArea::DisplayRenderArea(sp<const DisplayDevice> display, const Rect& sourceCrop,
49 ui::Size reqSize, ui::Dataspace reqDataSpace,
chaviwc6ad8af2020-08-03 11:33:30 -070050 bool useIdentityTransform, bool allowSecureLayers)
Patrick Williams278a88f2023-01-27 16:52:40 -060051 : RenderArea(reqSize, CaptureFill::OPAQUE, reqDataSpace, allowSecureLayers,
52 applyDeviceOrientation(useIdentityTransform, *display)),
Marin Shalamanovf6b5d182020-06-12 02:08:51 +020053 mDisplay(std::move(display)),
chaviw70cb6a42020-07-30 13:57:36 -070054 mSourceCrop(sourceCrop) {}
Marin Shalamanovf6b5d182020-06-12 02:08:51 +020055
56const ui::Transform& DisplayRenderArea::getTransform() const {
57 return mTransform;
58}
59
Marin Shalamanovf6b5d182020-06-12 02:08:51 +020060bool DisplayRenderArea::isSecure() const {
61 return mAllowSecureLayers && mDisplay->isSecure();
62}
63
64sp<const DisplayDevice> DisplayRenderArea::getDisplayDevice() const {
65 return mDisplay;
66}
67
Marin Shalamanovf6b5d182020-06-12 02:08:51 +020068Rect DisplayRenderArea::getSourceCrop() const {
69 // use the projected display viewport by default.
70 if (mSourceCrop.isEmpty()) {
Marin Shalamanov6ad317c2020-07-29 23:34:07 +020071 return mDisplay->getLayerStackSpaceRect();
Marin Shalamanovf6b5d182020-06-12 02:08:51 +020072 }
73
chaviwc6ad8af2020-08-03 11:33:30 -070074 // Correct for the orientation when the screen capture request contained
75 // useIdentityTransform. This will cause the rotation flag to be non 0 since
76 // it needs to rotate based on the screen orientation to allow the screenshot
77 // to be taken in the ROT_0 orientation
78 const auto flags = getRotationFlags();
Marin Shalamanov6ad317c2020-07-29 23:34:07 +020079 int width = mDisplay->getLayerStackSpaceRect().getWidth();
80 int height = mDisplay->getLayerStackSpaceRect().getHeight();
Marin Shalamanovf6b5d182020-06-12 02:08:51 +020081 ui::Transform rotation;
82 rotation.set(flags, width, height);
83 return rotation.transform(mSourceCrop);
84}
85
Patrick Williams278a88f2023-01-27 16:52:40 -060086} // namespace android