blob: 3cd8e390b2f16d526f7e690df152f9c2cd9adab8 [file] [log] [blame]
Haoxiang Li95917b12019-11-15 11:29:05 -08001//
2// Copyright (C) 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//
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -080016
17#include <utility>
18
Haoxiang Li95917b12019-11-15 11:29:05 -080019#include <gui/bufferqueue/2.0/B2HGraphicBufferProducer.h>
20
Changyeon Jo4ff8fb02020-02-05 21:56:59 -080021#include "AutomotiveDisplayProxyService.h"
Haoxiang Li95917b12019-11-15 11:29:05 -080022
23namespace android {
24namespace frameworks {
25namespace automotive {
26namespace display {
27namespace V1_0 {
28namespace implementation {
29
30Return<sp<IGraphicBufferProducer>>
Changyeon Jo4ff8fb02020-02-05 21:56:59 -080031AutomotiveDisplayProxyService::getIGraphicBufferProducer() {
Haoxiang Li95917b12019-11-15 11:29:05 -080032 if (mSurface == nullptr) {
33 status_t err;
34 mSurfaceComposerClient = new SurfaceComposerClient();
35
36 err = mSurfaceComposerClient->initCheck();
37 if (err != NO_ERROR) {
38 ALOGE("SurfaceComposerClient::initCheck error: %#x", err);
39 mSurfaceComposerClient = nullptr;
40 return nullptr;
41 }
42
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -080043 const auto displayToken = SurfaceComposerClient::getInternalDisplayToken();
44 if (displayToken == nullptr) {
Haoxiang Li95917b12019-11-15 11:29:05 -080045 ALOGE("Failed to get internal display ");
46 return nullptr;
47 }
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -080048
Changyeon Joe1dd30a2020-01-06 16:51:23 -080049 err = SurfaceComposerClient::getActiveDisplayConfig(displayToken, &mDpyConfig);
Haoxiang Li95917b12019-11-15 11:29:05 -080050 if (err != NO_ERROR) {
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -080051 ALOGE("Failed to get active display config");
Haoxiang Li95917b12019-11-15 11:29:05 -080052 return nullptr;
53 }
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -080054
Changyeon Joe1dd30a2020-01-06 16:51:23 -080055 err = SurfaceComposerClient::getDisplayState(displayToken, &mDpyState);
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -080056 if (err != NO_ERROR) {
57 ALOGE("Failed to get display state");
58 return nullptr;
59 }
60
Changyeon Joe1dd30a2020-01-06 16:51:23 -080061 const ui::Size& resolution = mDpyConfig.resolution;
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -080062 auto width = resolution.getWidth();
63 auto height = resolution.getHeight();
64
Changyeon Joe1dd30a2020-01-06 16:51:23 -080065 if (mDpyState.orientation == ui::ROTATION_90 ||
66 mDpyState.orientation == ui::ROTATION_270) {
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -080067 std::swap(width, height);
Haoxiang Li95917b12019-11-15 11:29:05 -080068 }
69
70 mSurfaceControl = mSurfaceComposerClient->createSurface(
Dominik Laskowski3cb3d4e2019-11-21 11:14:45 -080071 String8("Automotive Display"), width, height,
Haoxiang Li95917b12019-11-15 11:29:05 -080072 PIXEL_FORMAT_RGBX_8888, ISurfaceComposerClient::eOpaque);
73 if (mSurfaceControl == nullptr || !mSurfaceControl->isValid()) {
74 ALOGE("Failed to create SurfaceControl");
75 mSurfaceComposerClient = nullptr;
76 mSurfaceControl = nullptr;
77 return nullptr;
78 }
79
80 // SurfaceControl::getSurface is guaranteed to be not null.
81 mSurface = mSurfaceControl->getSurface();
82 }
83
84 return new ::android::hardware::graphics::bufferqueue::V2_0::utils::
85 B2HGraphicBufferProducer(
86 mSurface->getIGraphicBufferProducer());
87}
88
Changyeon Jo4ff8fb02020-02-05 21:56:59 -080089Return<bool> AutomotiveDisplayProxyService::showWindow() {
Haoxiang Li95917b12019-11-15 11:29:05 -080090 status_t status = NO_ERROR;
91
92 if (mSurfaceControl != nullptr) {
93 status = SurfaceComposerClient::Transaction{}
94 .setLayer(
95 mSurfaceControl, 0x7FFFFFFF) // always on top
96 .show(mSurfaceControl)
97 .apply();
98 } else {
99 ALOGE("showWindow: Failed to get a valid SurfaceControl!");
100 return false;
101 }
102
103 return status == NO_ERROR;
104}
105
Changyeon Jo4ff8fb02020-02-05 21:56:59 -0800106Return<bool> AutomotiveDisplayProxyService::hideWindow() {
Haoxiang Li95917b12019-11-15 11:29:05 -0800107 status_t status = NO_ERROR;
108
109 if (mSurfaceControl != nullptr) {
110 status = SurfaceComposerClient::Transaction{}
111 .hide(mSurfaceControl)
112 .apply();
113 } else {
114 ALOGE("hideWindow: Failed to get a valid SurfaceControl!");
115 return false;
116 }
117
118 return status == NO_ERROR;
119}
120
121} // namespace implementation
122} // namespace V1_0
123} // namespace display
124} // namespace automotive
125} // namespace frameworks
126} // namespace android
127