xref: /aosp_15_r20/frameworks/native/services/surfaceflinger/DisplayRenderArea.cpp (revision 38e8c45f13ce32b0dcecb25141ffecaf386fa17f)
1*38e8c45fSAndroid Build Coastguard Worker /*
2*38e8c45fSAndroid Build Coastguard Worker  * Copyright 2020 The Android Open Source Project
3*38e8c45fSAndroid Build Coastguard Worker  *
4*38e8c45fSAndroid Build Coastguard Worker  * Licensed under the Apache License, Version 2.0 (the "License");
5*38e8c45fSAndroid Build Coastguard Worker  * you may not use this file except in compliance with the License.
6*38e8c45fSAndroid Build Coastguard Worker  * You may obtain a copy of the License at
7*38e8c45fSAndroid Build Coastguard Worker  *
8*38e8c45fSAndroid Build Coastguard Worker  *      http://www.apache.org/licenses/LICENSE-2.0
9*38e8c45fSAndroid Build Coastguard Worker  *
10*38e8c45fSAndroid Build Coastguard Worker  * Unless required by applicable law or agreed to in writing, software
11*38e8c45fSAndroid Build Coastguard Worker  * distributed under the License is distributed on an "AS IS" BASIS,
12*38e8c45fSAndroid Build Coastguard Worker  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*38e8c45fSAndroid Build Coastguard Worker  * See the License for the specific language governing permissions and
14*38e8c45fSAndroid Build Coastguard Worker  * limitations under the License.
15*38e8c45fSAndroid Build Coastguard Worker  */
16*38e8c45fSAndroid Build Coastguard Worker 
17*38e8c45fSAndroid Build Coastguard Worker #include "DisplayRenderArea.h"
18*38e8c45fSAndroid Build Coastguard Worker #include "DisplayDevice.h"
19*38e8c45fSAndroid Build Coastguard Worker 
20*38e8c45fSAndroid Build Coastguard Worker namespace android {
21*38e8c45fSAndroid Build Coastguard Worker 
create(wp<const DisplayDevice> displayWeak,const Rect & sourceCrop,ui::Size reqSize,ui::Dataspace reqDataSpace,ftl::Flags<Options> options)22*38e8c45fSAndroid Build Coastguard Worker std::unique_ptr<RenderArea> DisplayRenderArea::create(wp<const DisplayDevice> displayWeak,
23*38e8c45fSAndroid Build Coastguard Worker                                                       const Rect& sourceCrop, ui::Size reqSize,
24*38e8c45fSAndroid Build Coastguard Worker                                                       ui::Dataspace reqDataSpace,
25*38e8c45fSAndroid Build Coastguard Worker                                                       ftl::Flags<Options> options) {
26*38e8c45fSAndroid Build Coastguard Worker     if (auto display = displayWeak.promote()) {
27*38e8c45fSAndroid Build Coastguard Worker         // Using new to access a private constructor.
28*38e8c45fSAndroid Build Coastguard Worker         return std::unique_ptr<DisplayRenderArea>(new DisplayRenderArea(std::move(display),
29*38e8c45fSAndroid Build Coastguard Worker                                                                         sourceCrop, reqSize,
30*38e8c45fSAndroid Build Coastguard Worker                                                                         reqDataSpace, options));
31*38e8c45fSAndroid Build Coastguard Worker     }
32*38e8c45fSAndroid Build Coastguard Worker     return nullptr;
33*38e8c45fSAndroid Build Coastguard Worker }
34*38e8c45fSAndroid Build Coastguard Worker 
DisplayRenderArea(sp<const DisplayDevice> display,const Rect & sourceCrop,ui::Size reqSize,ui::Dataspace reqDataSpace,ftl::Flags<Options> options)35*38e8c45fSAndroid Build Coastguard Worker DisplayRenderArea::DisplayRenderArea(sp<const DisplayDevice> display, const Rect& sourceCrop,
36*38e8c45fSAndroid Build Coastguard Worker                                      ui::Size reqSize, ui::Dataspace reqDataSpace,
37*38e8c45fSAndroid Build Coastguard Worker                                      ftl::Flags<Options> options)
38*38e8c45fSAndroid Build Coastguard Worker       : RenderArea(reqSize, CaptureFill::OPAQUE, reqDataSpace, options),
39*38e8c45fSAndroid Build Coastguard Worker         mDisplay(std::move(display)),
40*38e8c45fSAndroid Build Coastguard Worker         mSourceCrop(sourceCrop) {}
41*38e8c45fSAndroid Build Coastguard Worker 
getTransform() const42*38e8c45fSAndroid Build Coastguard Worker const ui::Transform& DisplayRenderArea::getTransform() const {
43*38e8c45fSAndroid Build Coastguard Worker     return mTransform;
44*38e8c45fSAndroid Build Coastguard Worker }
45*38e8c45fSAndroid Build Coastguard Worker 
isSecure() const46*38e8c45fSAndroid Build Coastguard Worker bool DisplayRenderArea::isSecure() const {
47*38e8c45fSAndroid Build Coastguard Worker     return mOptions.test(Options::CAPTURE_SECURE_LAYERS) && mDisplay->isSecure();
48*38e8c45fSAndroid Build Coastguard Worker }
49*38e8c45fSAndroid Build Coastguard Worker 
getDisplayDevice() const50*38e8c45fSAndroid Build Coastguard Worker sp<const DisplayDevice> DisplayRenderArea::getDisplayDevice() const {
51*38e8c45fSAndroid Build Coastguard Worker     return mDisplay;
52*38e8c45fSAndroid Build Coastguard Worker }
53*38e8c45fSAndroid Build Coastguard Worker 
getSourceCrop() const54*38e8c45fSAndroid Build Coastguard Worker Rect DisplayRenderArea::getSourceCrop() const {
55*38e8c45fSAndroid Build Coastguard Worker     // use the projected display viewport by default.
56*38e8c45fSAndroid Build Coastguard Worker     if (mSourceCrop.isEmpty()) {
57*38e8c45fSAndroid Build Coastguard Worker         return mDisplay->getLayerStackSpaceRect();
58*38e8c45fSAndroid Build Coastguard Worker     }
59*38e8c45fSAndroid Build Coastguard Worker     return mSourceCrop;
60*38e8c45fSAndroid Build Coastguard Worker }
61*38e8c45fSAndroid Build Coastguard Worker 
62*38e8c45fSAndroid Build Coastguard Worker } // namespace android
63