1 /* 2 * Copyright (c) 2014-2019, 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 #ifndef __HWC_DISPLAY_BUILTIN_H__ 31 #define __HWC_DISPLAY_BUILTIN_H__ 32 33 #include <hardware/google/light/1.0/ILight.h> 34 #include <limits> 35 #include <string> 36 #include <vector> 37 #include <mutex> 38 39 #include "cpuhint.h" 40 #include "hwc_display.h" 41 42 namespace sdm { 43 44 class HWCDisplayBuiltIn : public HWCDisplay { 45 public: 46 enum { 47 SET_METADATA_DYN_REFRESH_RATE, 48 SET_BINDER_DYN_REFRESH_RATE, 49 SET_DISPLAY_MODE, 50 SET_QDCM_SOLID_FILL_INFO, 51 UNSET_QDCM_SOLID_FILL_INFO, 52 SET_QDCM_SOLID_FILL_RECT, 53 }; 54 55 static int Create(CoreInterface *core_intf, BufferAllocator *buffer_allocator, 56 HWCCallbacks *callbacks, HWCDisplayEventHandler *event_handler, 57 qService::QService *qservice, hwc2_display_t id, int32_t sdm_id, 58 HWCDisplay **hwc_display); 59 static void Destroy(HWCDisplay *hwc_display); 60 virtual int Init(); 61 virtual int Deinit() override; 62 virtual HWC2::Error Validate(uint32_t *out_num_types, uint32_t *out_num_requests); 63 virtual HWC2::Error Present(int32_t *out_retire_fence); 64 virtual HWC2::Error CommitLayerStack(); 65 virtual HWC2::Error GetColorModes(uint32_t *out_num_modes, ColorMode *out_modes); 66 virtual HWC2::Error SetColorMode(ColorMode mode); 67 virtual HWC2::Error GetRenderIntents(ColorMode mode, uint32_t *out_num_intents, 68 RenderIntent *out_intents); 69 virtual HWC2::Error SetColorModeWithRenderIntent(ColorMode mode, RenderIntent intent); 70 virtual HWC2::Error SetColorModeById(int32_t color_mode_id); 71 virtual HWC2::Error SetColorModeFromClientApi(int32_t color_mode_id); 72 virtual HWC2::Error SetColorTransform(const float *matrix, android_color_transform_t hint); 73 virtual HWC2::Error RestoreColorTransform(); 74 virtual int Perform(uint32_t operation, ...); 75 virtual int HandleSecureSession(const std::bitset<kSecureMax> &secure_session, 76 bool *power_on_pending); 77 virtual DisplayError Refresh(); 78 virtual void SetIdleTimeoutMs(uint32_t timeout_ms); 79 virtual HWC2::Error SetFrameDumpConfig(uint32_t count, uint32_t bit_mask_layer_type, 80 int32_t format, bool post_processed); 81 virtual int FrameCaptureAsync(const BufferInfo &output_buffer_info, bool post_processed); GetFrameCaptureStatus()82 virtual int GetFrameCaptureStatus() { return frame_capture_status_; } 83 virtual DisplayError SetDetailEnhancerConfig(const DisplayDetailEnhancerData &de_data); 84 virtual DisplayError ControlPartialUpdate(bool enable, uint32_t *pending); 85 virtual HWC2::Error SetReadbackBuffer(const native_handle_t *buffer, int32_t acquire_fence, 86 bool post_processed_output); 87 virtual HWC2::Error GetReadbackBufferFence(int32_t *release_fence); 88 virtual HWC2::Error SetQSyncMode(QSyncMode qsync_mode); 89 virtual DisplayError ControlIdlePowerCollapse(bool enable, bool synchronous); 90 virtual HWC2::Error SetDisplayDppsAdROI(uint32_t h_start, uint32_t h_end, uint32_t v_start, 91 uint32_t v_end, uint32_t factor_in, uint32_t factor_out); 92 virtual DisplayError SetDynamicDSIClock(uint64_t bitclk); 93 virtual DisplayError GetDynamicDSIClock(uint64_t *bitclk); 94 virtual DisplayError GetSupportedDSIClock(std::vector<uint64_t> *bitclk_rates); 95 virtual HWC2::Error UpdateDisplayId(hwc2_display_t id); 96 virtual HWC2::Error SetPendingRefresh(); 97 virtual DisplayError TeardownConcurrentWriteback(void); SetFastPathComposition(bool enable)98 virtual void SetFastPathComposition(bool enable) { 99 fast_path_composition_ = enable && !readback_buffer_queued_; 100 } 101 102 virtual HWC2::Error SetDisplayedContentSamplingEnabledVndService(bool enabled); 103 virtual HWC2::Error SetDisplayedContentSamplingEnabled(int32_t enabled, uint8_t component_mask, uint64_t max_frames) override; 104 virtual HWC2::Error GetDisplayedContentSamplingAttributes(int32_t* format, int32_t* dataspace, 105 uint8_t* supported_components) override; 106 virtual HWC2::Error GetDisplayedContentSample(uint64_t max_frames, 107 uint64_t timestamp, uint64_t* numFrames, 108 int32_t samples_size[NUM_HISTOGRAM_COLOR_COMPONENTS], 109 uint64_t* samples[NUM_HISTOGRAM_COLOR_COMPONENTS]) override; 110 std::string Dump() override; 111 112 private: 113 HWCDisplayBuiltIn(CoreInterface *core_intf, BufferAllocator *buffer_allocator, 114 HWCCallbacks *callbacks, HWCDisplayEventHandler *event_handler, 115 qService::QService *qservice, hwc2_display_t id, int32_t sdm_id); 116 void SetMetaDataRefreshRateFlag(bool enable); 117 virtual DisplayError SetDisplayMode(uint32_t mode); 118 virtual DisplayError DisablePartialUpdateOneFrame(); 119 void SetQDCMSolidFillInfo(bool enable, const LayerSolidFill &color); 120 void ToggleCPUHint(bool set); 121 void ForceRefreshRate(uint32_t refresh_rate); 122 uint32_t GetOptimalRefreshRate(bool one_updating_layer); 123 void HandleFrameOutput(); 124 void HandleFrameDump(); 125 void HandleFrameCapture(); 126 bool CanSkipCommit(); 127 DisplayError SetMixerResolution(uint32_t width, uint32_t height); 128 DisplayError GetMixerResolution(uint32_t *width, uint32_t *height); 129 130 BufferAllocator *buffer_allocator_ = nullptr; 131 CPUHint *cpu_hint_ = nullptr; 132 133 // Builtin readback buffer configuration 134 LayerBuffer output_buffer_ = {}; 135 bool post_processed_output_ = false; 136 bool readback_buffer_queued_ = false; 137 bool readback_configured_ = false; 138 139 // Members for N frame output dump to file 140 bool dump_output_to_file_ = false; 141 BufferInfo output_buffer_info_ = {}; 142 void *output_buffer_base_ = nullptr; 143 int default_mode_status_ = 0; 144 bool pending_refresh_ = true; 145 bool enable_drop_refresh_ = false; 146 147 // Members for 1 frame capture in a client provided buffer 148 bool frame_capture_buffer_queued_ = false; 149 int frame_capture_status_ = -EAGAIN; 150 151 // Members for HBM feature 152 static constexpr float hbm_threshold_pct_ = 0.5f; 153 float hbm_threshold_px_ = std::numeric_limits<float>::max(); 154 android::sp<hardware::google::light::V1_0::ILight> hardware_ILight_ = nullptr; 155 bool has_init_light_server_ = false; 156 bool high_brightness_mode_ = false; 157 158 // Members for Color sampling feature 159 DisplayError HistogramEvent(int fd, uint32_t blob_id) override; 160 histogram::HistogramCollector histogram; 161 std::mutex sampling_mutex; 162 bool api_sampling_vote = false; 163 bool vndservice_sampling_vote = false; 164 165 }; 166 167 } // namespace sdm 168 169 #endif // __HWC_DISPLAY_BUILTIN_H__ 170