Ady Abraham | 03b02dd | 2019-03-21 15:40:11 -0700 | [diff] [blame] | 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 | |
| 25 | RefreshRateOverlay::RefreshRateOverlay(SurfaceFlinger& flinger) |
| 26 | : mFlinger(flinger), mClient(new Client(&mFlinger)) { |
| 27 | createLayer(); |
| 28 | } |
| 29 | |
| 30 | bool RefreshRateOverlay::createLayer() { |
| 31 | const status_t ret = |
| 32 | mFlinger.createLayer(String8("RefreshRateOverlay"), mClient, 0, 0, |
| 33 | PIXEL_FORMAT_RGBA_8888, ISurfaceComposerClient::eFXSurfaceColor, |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 34 | LayerMetadata(), &mIBinder, &mGbp, nullptr); |
Ady Abraham | 03b02dd | 2019-03-21 15:40:11 -0700 | [diff] [blame] | 35 | if (ret) { |
Robert Carr | c0df312 | 2019-04-11 13:18:21 -0700 | [diff] [blame] | 36 | ALOGE("failed to create color layer"); |
Ady Abraham | 03b02dd | 2019-03-21 15:40:11 -0700 | [diff] [blame] | 37 | return false; |
| 38 | } |
| 39 | |
Ady Abraham | fed164b | 2019-05-10 17:12:54 -0700 | [diff] [blame^] | 40 | Mutex::Autolock _l(mFlinger.mStateLock); |
Ady Abraham | 03b02dd | 2019-03-21 15:40:11 -0700 | [diff] [blame] | 41 | mLayer = mClient->getLayerUser(mIBinder); |
Ady Abraham | 6aa35b2 | 2019-05-02 17:22:13 -0700 | [diff] [blame] | 42 | mLayer->setCrop_legacy(Rect(50, 70, 200, 100), true); |
Ady Abraham | fed164b | 2019-05-10 17:12:54 -0700 | [diff] [blame^] | 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 | } |
Ady Abraham | 03b02dd | 2019-03-21 15:40:11 -0700 | [diff] [blame] | 50 | |
| 51 | return true; |
| 52 | } |
| 53 | |
| 54 | void RefreshRateOverlay::changeRefreshRate(RefreshRateType type) { |
| 55 | const half3& color = (type == RefreshRateType::PERFORMANCE) ? GREEN : RED; |
| 56 | mLayer->setColor(color); |
Ady Abraham | fe57b76 | 2019-04-17 20:06:14 -0700 | [diff] [blame] | 57 | mFlinger.mTransactionFlags.fetch_or(eTransactionMask); |
Ady Abraham | 03b02dd | 2019-03-21 15:40:11 -0700 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | }; // namespace android |