blob: c63c738d349bd489169cf0c4799bd8a213ee531b [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 {
Marin Shalamanovf6b5d182020-06-12 02:08:51 +020021
22std::unique_ptr<RenderArea> DisplayRenderArea::create(wp<const DisplayDevice> displayWeak,
23 const Rect& sourceCrop, ui::Size reqSize,
24 ui::Dataspace reqDataSpace,
Vishnu Nair96a5aaf2024-06-26 17:17:51 -070025 ftl::Flags<Options> options) {
Marin Shalamanovf6b5d182020-06-12 02:08:51 +020026 if (auto display = displayWeak.promote()) {
27 // Using new to access a private constructor.
Vishnu Nair96a5aaf2024-06-26 17:17:51 -070028 return std::unique_ptr<DisplayRenderArea>(new DisplayRenderArea(std::move(display),
29 sourceCrop, reqSize,
30 reqDataSpace, options));
Marin Shalamanovf6b5d182020-06-12 02:08:51 +020031 }
32 return nullptr;
33}
34
35DisplayRenderArea::DisplayRenderArea(sp<const DisplayDevice> display, const Rect& sourceCrop,
36 ui::Size reqSize, ui::Dataspace reqDataSpace,
Vishnu Nair96a5aaf2024-06-26 17:17:51 -070037 ftl::Flags<Options> options)
38 : RenderArea(reqSize, CaptureFill::OPAQUE, reqDataSpace, options),
Marin Shalamanovf6b5d182020-06-12 02:08:51 +020039 mDisplay(std::move(display)),
chaviw70cb6a42020-07-30 13:57:36 -070040 mSourceCrop(sourceCrop) {}
Marin Shalamanovf6b5d182020-06-12 02:08:51 +020041
42const ui::Transform& DisplayRenderArea::getTransform() const {
43 return mTransform;
44}
45
Marin Shalamanovf6b5d182020-06-12 02:08:51 +020046bool DisplayRenderArea::isSecure() const {
Vishnu Nair96a5aaf2024-06-26 17:17:51 -070047 return mOptions.test(Options::CAPTURE_SECURE_LAYERS) && mDisplay->isSecure();
Marin Shalamanovf6b5d182020-06-12 02:08:51 +020048}
49
50sp<const DisplayDevice> DisplayRenderArea::getDisplayDevice() const {
51 return mDisplay;
52}
53
Marin Shalamanovf6b5d182020-06-12 02:08:51 +020054Rect DisplayRenderArea::getSourceCrop() const {
55 // use the projected display viewport by default.
56 if (mSourceCrop.isEmpty()) {
Marin Shalamanov6ad317c2020-07-29 23:34:07 +020057 return mDisplay->getLayerStackSpaceRect();
Marin Shalamanovf6b5d182020-06-12 02:08:51 +020058 }
Melody Hsu70a63e52023-11-17 19:49:12 +000059 return mSourceCrop;
Marin Shalamanovf6b5d182020-06-12 02:08:51 +020060}
61
Patrick Williams278a88f2023-01-27 16:52:40 -060062} // namespace android