• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 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 #define LOG_TAG "drmhwc"
18 
19 #include "HwcLayer.h"
20 
21 #include "HwcDisplay.h"
22 #include "bufferinfo/BufferInfoGetter.h"
23 #include "utils/log.h"
24 
25 namespace android {
26 
SetLayerProperties(const LayerProperties & layer_properties)27 void HwcLayer::SetLayerProperties(const LayerProperties& layer_properties) {
28   if (layer_properties.slot_buffer) {
29     auto slot_id = layer_properties.slot_buffer->slot_id;
30     if (!layer_properties.slot_buffer->bi) {
31       slots_.erase(slot_id);
32     } else {
33       slots_[slot_id] = {
34           .bi = layer_properties.slot_buffer->bi.value(),
35           .fb = {},
36       };
37     }
38   }
39   if (layer_properties.active_slot) {
40     active_slot_id_ = layer_properties.active_slot->slot_id;
41     layer_data_.acquire_fence = layer_properties.active_slot->fence;
42     buffer_updated_ = true;
43   }
44   if (layer_properties.blend_mode) {
45     blend_mode_ = layer_properties.blend_mode.value();
46   }
47   if (layer_properties.color_space) {
48     color_space_ = layer_properties.color_space.value();
49   }
50   if (layer_properties.sample_range) {
51     sample_range_ = layer_properties.sample_range.value();
52   }
53   if (layer_properties.composition_type) {
54     sf_type_ = layer_properties.composition_type.value();
55   }
56   if (layer_properties.display_frame) {
57     layer_data_.pi.display_frame = layer_properties.display_frame.value();
58   }
59   if (layer_properties.alpha) {
60     layer_data_.pi.alpha = layer_properties.alpha.value();
61   }
62   if (layer_properties.source_crop) {
63     layer_data_.pi.source_crop = layer_properties.source_crop.value();
64   }
65   if (layer_properties.transform) {
66     layer_data_.pi.transform = layer_properties.transform.value();
67   }
68   if (layer_properties.z_order) {
69     z_order_ = layer_properties.z_order.value();
70   }
71 }
72 
ImportFb()73 void HwcLayer::ImportFb() {
74   if (!IsLayerUsableAsDevice() || !buffer_updated_ ||
75       !active_slot_id_.has_value()) {
76     return;
77   }
78   buffer_updated_ = false;
79 
80   if (slots_[*active_slot_id_].fb) {
81     return;
82   }
83 
84   auto& fb_importer = parent_->GetPipe().device->GetDrmFbImporter();
85   auto fb = fb_importer.GetOrCreateFbId(&slots_[*active_slot_id_].bi);
86 
87   if (!fb) {
88     ALOGE("Unable to create framebuffer object for layer %p", this);
89     fb_import_failed_ = true;
90     return;
91   }
92 
93   slots_[*active_slot_id_].fb = fb;
94 }
95 
PopulateLayerData()96 void HwcLayer::PopulateLayerData() {
97   ImportFb();
98 
99   if (!active_slot_id_.has_value()) {
100     ALOGE("Internal error: populate layer data called without active slot");
101     return;
102   }
103 
104   if (slots_.count(*active_slot_id_) == 0) {
105     return;
106   }
107 
108   layer_data_.bi = slots_[*active_slot_id_].bi;
109   layer_data_.fb = slots_[*active_slot_id_].fb;
110 
111   if (blend_mode_ != BufferBlendMode::kUndefined) {
112     layer_data_.bi->blend_mode = blend_mode_;
113   }
114   if (color_space_ != BufferColorSpace::kUndefined) {
115     layer_data_.bi->color_space = color_space_;
116   }
117   if (sample_range_ != BufferSampleRange::kUndefined) {
118     layer_data_.bi->sample_range = sample_range_;
119   }
120 }
121 
ClearSlots()122 void HwcLayer::ClearSlots() {
123   slots_.clear();
124   active_slot_id_.reset();
125 }
126 
127 }  // namespace android