1 /*
2 * Copyright (c) 2014-2020, The Linux Foundation. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above
10 * copyright notice, this list of conditions and the following
11 * disclaimer in the documentation and/or other materials provided
12 * with the distribution.
13 * * Neither the name of The Linux Foundation nor the names of its
14 * contributors may be used to endorse or promote products derived
15 * from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
18 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
21 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
24 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
26 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30 #include <utils/constants.h>
31 #include <utils/debug.h>
32 #include <sync/sync.h>
33 #include <stdarg.h>
34
35 #include "hwc_display_virtual.h"
36 #include "hwc_debugger.h"
37
38 #define __CLASS__ "HWCDisplayVirtual"
39
40 namespace sdm {
41
Destroy(HWCDisplay * hwc_display)42 void HWCDisplayVirtual::Destroy(HWCDisplay *hwc_display) {
43 hwc_display->Deinit();
44 delete hwc_display;
45 }
46
HWCDisplayVirtual(CoreInterface * core_intf,HWCBufferAllocator * buffer_allocator,HWCCallbacks * callbacks,hwc2_display_t id,int32_t sdm_id,uint32_t width,uint32_t height)47 HWCDisplayVirtual::HWCDisplayVirtual(CoreInterface *core_intf, HWCBufferAllocator *buffer_allocator,
48 HWCCallbacks *callbacks, hwc2_display_t id, int32_t sdm_id,
49 uint32_t width, uint32_t height) :
50 HWCDisplay(core_intf, buffer_allocator, callbacks, nullptr, nullptr, kVirtual, id, sdm_id,
51 DISPLAY_CLASS_VIRTUAL), width_(width), height_(height) {
52 }
53
Init()54 int HWCDisplayVirtual::Init() {
55 flush_on_error_ = true;
56 return 0;
57 }
58
Deinit()59 int HWCDisplayVirtual::Deinit() {
60 return HWCDisplay::Deinit();
61 }
62
NeedsGPUBypass()63 bool HWCDisplayVirtual::NeedsGPUBypass() {
64 return display_paused_ || active_secure_sessions_.any() || layer_set_.empty();
65 }
66
Present(shared_ptr<Fence> * out_retire_fence)67 HWC2::Error HWCDisplayVirtual::Present(shared_ptr<Fence> *out_retire_fence) {
68 return HWC2::Error::None;
69 }
70
DumpVDSBuffer()71 HWC2::Error HWCDisplayVirtual::DumpVDSBuffer() {
72 if (dump_frame_count_ && !flush_ && dump_output_layer_) {
73 if (output_handle_) {
74 BufferInfo buffer_info;
75 const private_handle_t *output_handle =
76 reinterpret_cast<const private_handle_t *>(output_buffer_.buffer_id);
77 DisplayError error = kErrorNone;
78 if (!output_handle->base) {
79 error = buffer_allocator_->MapBuffer(output_handle, nullptr);
80 if (error != kErrorNone) {
81 DLOGE("Failed to map output buffer, error = %d", error);
82 return HWC2::Error::BadParameter;
83 }
84 }
85 buffer_info.buffer_config.width = static_cast<uint32_t>(output_handle->width);
86 buffer_info.buffer_config.height = static_cast<uint32_t>(output_handle->height);
87 buffer_info.buffer_config.format =
88 HWCLayer::GetSDMFormat(output_handle->format, output_handle->flags);
89 buffer_info.alloc_buffer_info.size = static_cast<uint32_t>(output_handle->size);
90 DumpOutputBuffer(buffer_info, reinterpret_cast<void *>(output_handle->base),
91 layer_stack_.retire_fence);
92
93 int release_fence = -1;
94 error = buffer_allocator_->UnmapBuffer(output_handle, &release_fence);
95 if (error != kErrorNone) {
96 DLOGE("Failed to unmap buffer, error = %d", error);
97 return HWC2::Error::BadParameter;
98 }
99 }
100 }
101
102 return HWC2::Error::None;
103 }
104
SetOutputBuffer(buffer_handle_t buf,shared_ptr<Fence> release_fence)105 HWC2::Error HWCDisplayVirtual::SetOutputBuffer(buffer_handle_t buf,
106 shared_ptr<Fence> release_fence) {
107 if (buf == nullptr) {
108 return HWC2::Error::BadParameter;
109 }
110 const private_handle_t *output_handle = static_cast<const private_handle_t *>(buf);
111
112 if (output_handle) {
113 int output_handle_format = output_handle->format;
114 ColorMetaData color_metadata = {};
115
116 if (output_handle_format == HAL_PIXEL_FORMAT_RGBA_8888) {
117 output_handle_format = HAL_PIXEL_FORMAT_RGBX_8888;
118 }
119
120 LayerBufferFormat new_sdm_format =
121 HWCLayer::GetSDMFormat(output_handle_format, output_handle->flags);
122 if (new_sdm_format == kFormatInvalid) {
123 return HWC2::Error::BadParameter;
124 }
125
126 if (sdm::SetCSC(output_handle, &color_metadata) != kErrorNone) {
127 return HWC2::Error::BadParameter;
128 }
129
130 output_buffer_.flags.secure = 0;
131 output_buffer_.flags.video = 0;
132 output_buffer_.buffer_id = reinterpret_cast<uint64_t>(output_handle);
133 output_buffer_.format = new_sdm_format;
134 output_buffer_.color_metadata = color_metadata;
135 output_handle_ = output_handle;
136
137 // TZ Protected Buffer - L1
138 if (output_handle->flags & private_handle_t::PRIV_FLAGS_SECURE_BUFFER) {
139 output_buffer_.flags.secure = 1;
140 }
141
142 // ToDo: Need to extend for non-RGB formats
143 output_buffer_.planes[0].fd = output_handle->fd;
144 output_buffer_.planes[0].offset = output_handle->offset;
145 output_buffer_.planes[0].stride = UINT32(output_handle->width);
146 }
147
148 output_buffer_.acquire_fence = release_fence;
149
150 return HWC2::Error::None;
151 }
152
SetFrameDumpConfig(uint32_t count,uint32_t bit_mask_layer_type,int32_t format,bool post_processed)153 HWC2::Error HWCDisplayVirtual::SetFrameDumpConfig(uint32_t count, uint32_t bit_mask_layer_type,
154 int32_t format, bool post_processed) {
155 HWCDisplay::SetFrameDumpConfig(count, bit_mask_layer_type, format, post_processed);
156 dump_output_layer_ = ((bit_mask_layer_type & (1 << OUTPUT_LAYER_DUMP)) != 0);
157
158 DLOGI("output_layer_dump_enable %d", dump_output_layer_);
159 return HWC2::Error::None;
160 }
161
GetDisplayType(int32_t * out_type)162 HWC2::Error HWCDisplayVirtual::GetDisplayType(int32_t *out_type) {
163 if (out_type == nullptr) {
164 return HWC2::Error::BadParameter;
165 }
166
167 *out_type = HWC2_DISPLAY_TYPE_VIRTUAL;
168
169 return HWC2::Error::None;
170 }
171
SetColorMode(ColorMode mode)172 HWC2::Error HWCDisplayVirtual::SetColorMode(ColorMode mode) {
173 return HWC2::Error::None;
174 }
175
176 } // namespace sdm
177