blob: e70bfe4b1e288ed3dac29a96956ad79e863c665e [file] [log] [blame]
Ady Abraham03b02dd2019-03-21 15:40:11 -07001/*
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
21namespace android {
22
23using RefreshRateType = scheduler::RefreshRateConfigs::RefreshRateType;
24
25RefreshRateOverlay::RefreshRateOverlay(SurfaceFlinger& flinger)
26 : mFlinger(flinger), mClient(new Client(&mFlinger)) {
27 createLayer();
28}
29
30bool 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, &mLayer);
35 if (ret) {
36 ALOGE("failed to color layer");
37 return false;
38 }
39
40 mLayer = mClient->getLayerUser(mIBinder);
41 mLayer->setCrop_legacy(Rect(0, 0, 200, 100), true);
42 mLayer->setLayer(INT32_MAX - 2);
43
44 return true;
45}
46
47void RefreshRateOverlay::changeRefreshRate(RefreshRateType type) {
48 const half3& color = (type == RefreshRateType::PERFORMANCE) ? GREEN : RED;
49 mLayer->setColor(color);
50 mFlinger.setTransactionFlags(eTransactionMask);
51}
52
53}; // namespace android