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
create(wp<const DisplayDevice> displayWeak,const Rect & sourceCrop,ui::Size reqSize,ui::Dataspace reqDataSpace,ftl::Flags<Options> options)22 std::unique_ptr<RenderArea> DisplayRenderArea::create(wp<const DisplayDevice> displayWeak,
23 const Rect& sourceCrop, ui::Size reqSize,
24 ui::Dataspace reqDataSpace,
25 ftl::Flags<Options> options) {
26 if (auto display = displayWeak.promote()) {
27 // Using new to access a private constructor.
28 return std::unique_ptr<DisplayRenderArea>(new DisplayRenderArea(std::move(display),
29 sourceCrop, reqSize,
30 reqDataSpace, options));
31 }
32 return nullptr;
33 }
34
DisplayRenderArea(sp<const DisplayDevice> display,const Rect & sourceCrop,ui::Size reqSize,ui::Dataspace reqDataSpace,ftl::Flags<Options> options)35 DisplayRenderArea::DisplayRenderArea(sp<const DisplayDevice> display, const Rect& sourceCrop,
36 ui::Size reqSize, ui::Dataspace reqDataSpace,
37 ftl::Flags<Options> options)
38 : RenderArea(reqSize, CaptureFill::OPAQUE, reqDataSpace, options),
39 mDisplay(std::move(display)),
40 mSourceCrop(sourceCrop) {}
41
getTransform() const42 const ui::Transform& DisplayRenderArea::getTransform() const {
43 return mTransform;
44 }
45
isSecure() const46 bool DisplayRenderArea::isSecure() const {
47 return mOptions.test(Options::CAPTURE_SECURE_LAYERS) && mDisplay->isSecure();
48 }
49
getDisplayDevice() const50 sp<const DisplayDevice> DisplayRenderArea::getDisplayDevice() const {
51 return mDisplay;
52 }
53
getSourceCrop() const54 Rect DisplayRenderArea::getSourceCrop() const {
55 // use the projected display viewport by default.
56 if (mSourceCrop.isEmpty()) {
57 return mDisplay->getLayerStackSpaceRect();
58 }
59 return mSourceCrop;
60 }
61
62 } // namespace android
63