1 /*
2 * Copyright 2019 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 "RefreshRateOverlay.h"
18 #include "Client.h"
19 #include "Layer.h"
20
21 namespace android {
22
23 using RefreshRateType = scheduler::RefreshRateConfigs::RefreshRateType;
24
RefreshRateOverlay(SurfaceFlinger & flinger)25 RefreshRateOverlay::RefreshRateOverlay(SurfaceFlinger& flinger)
26 : mFlinger(flinger), mClient(new Client(&mFlinger)) {
27 createLayer();
28 }
29
createLayer()30 bool RefreshRateOverlay::createLayer() {
31 const status_t ret =
32 mFlinger.createLayer(String8("RefreshRateOverlay"), mClient, 0, 0,
33 PIXEL_FORMAT_RGBA_8888, ISurfaceComposerClient::eFXSurfaceColor,
34 LayerMetadata(), &mIBinder, &mGbp, nullptr);
35 if (ret) {
36 ALOGE("failed to create color layer");
37 return false;
38 }
39
40 Mutex::Autolock _l(mFlinger.mStateLock);
41 mLayer = mClient->getLayerUser(mIBinder);
42 mLayer->setCrop_legacy(Rect(50, 70, 200, 100), true);
43
44 // setting Layer's Z requires resorting layersSortedByZ
45 ssize_t idx = mFlinger.mCurrentState.layersSortedByZ.indexOf(mLayer);
46 if (mLayer->setLayer(INT32_MAX - 2) && idx >= 0) {
47 mFlinger.mCurrentState.layersSortedByZ.removeAt(idx);
48 mFlinger.mCurrentState.layersSortedByZ.add(mLayer);
49 }
50
51 return true;
52 }
53
changeRefreshRate(RefreshRateType type)54 void RefreshRateOverlay::changeRefreshRate(RefreshRateType type) {
55 const half3& color = (type == RefreshRateType::PERFORMANCE) ? GREEN : RED;
56 mLayer->setColor(color);
57 mFlinger.mTransactionFlags.fetch_or(eTransactionMask);
58 }
59
60 }; // namespace android
61