• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef __HWC_DISPLAY_BUILTIN_H__
31 #define __HWC_DISPLAY_BUILTIN_H__
32 
33 #include <thermal_client.h>
34 #include <mutex>
35 #include <limits>
36 #include <string>
37 #include <vector>
38 
39 #include "utils/sync_task.h"
40 #include "utils/constants.h"
41 #include "cpuhint.h"
42 #include "hwc_display.h"
43 #include "hwc_layers.h"
44 
45 #include "gl_layer_stitch.h"
46 
47 namespace sdm {
48 
49 enum class LayerStitchTaskCode : int32_t {
50   kCodeGetInstance,
51   kCodeStitch,
52   kCodeDestroyInstance,
53 };
54 
55 struct LayerStitchGetInstanceContext : public SyncTask<LayerStitchTaskCode>::TaskContext {
56   LayerBuffer *output_buffer = NULL;
57 };
58 
59 struct LayerStitchContext : public SyncTask<LayerStitchTaskCode>::TaskContext {
60   const private_handle_t* src_hnd = nullptr;
61   const private_handle_t* dst_hnd = nullptr;
62   GLRect src_rect = {};
63   GLRect dst_rect = {};
64   GLRect scissor_rect = {};
65   shared_ptr<Fence> src_acquire_fence = nullptr;
66   shared_ptr<Fence> dst_acquire_fence = nullptr;
67   shared_ptr<Fence> release_fence = nullptr;
68 };
69 
70 class HWCDisplayBuiltIn : public HWCDisplay, public SyncTask<LayerStitchTaskCode>::TaskHandler {
71  public:
72   enum {
73     SET_METADATA_DYN_REFRESH_RATE,
74     SET_BINDER_DYN_REFRESH_RATE,
75     SET_DISPLAY_MODE,
76     SET_QDCM_SOLID_FILL_INFO,
77     UNSET_QDCM_SOLID_FILL_INFO,
78     SET_QDCM_SOLID_FILL_RECT,
79   };
80 
81   static int Create(CoreInterface *core_intf, BufferAllocator *buffer_allocator,
82                     HWCCallbacks *callbacks,  HWCDisplayEventHandler *event_handler,
83                     qService::QService *qservice, hwc2_display_t id, int32_t sdm_id,
84                     HWCDisplay **hwc_display);
85   static void Destroy(HWCDisplay *hwc_display);
86   virtual int Init();
87   virtual HWC2::Error Validate(uint32_t *out_num_types, uint32_t *out_num_requests);
88   virtual HWC2::Error Present(shared_ptr<Fence> *out_retire_fence);
89   virtual HWC2::Error CommitLayerStack();
90   virtual HWC2::Error GetColorModes(uint32_t *out_num_modes, ColorMode *out_modes);
91   virtual HWC2::Error SetColorMode(ColorMode mode);
92   virtual HWC2::Error GetRenderIntents(ColorMode mode, uint32_t *out_num_intents,
93                                        RenderIntent *out_intents);
94   virtual HWC2::Error SetColorModeWithRenderIntent(ColorMode mode, RenderIntent intent);
95   virtual HWC2::Error SetColorModeById(int32_t color_mode_id);
96   virtual HWC2::Error SetColorModeFromClientApi(int32_t color_mode_id);
97   virtual HWC2::Error SetColorTransform(const float *matrix, android_color_transform_t hint);
98   virtual HWC2::Error RestoreColorTransform();
99   virtual int Perform(uint32_t operation, ...);
100   virtual int HandleSecureSession(const std::bitset<kSecureMax> &secure_session,
101                                   bool *power_on_pending);
102   virtual void SetIdleTimeoutMs(uint32_t timeout_ms);
103   virtual HWC2::Error SetFrameDumpConfig(uint32_t count, uint32_t bit_mask_layer_type,
104                                          int32_t format, bool post_processed);
105   virtual int FrameCaptureAsync(const BufferInfo &output_buffer_info, bool post_processed);
GetFrameCaptureStatus()106   virtual int GetFrameCaptureStatus() { return frame_capture_status_; }
107   virtual DisplayError SetDetailEnhancerConfig(const DisplayDetailEnhancerData &de_data);
108   virtual DisplayError ControlPartialUpdate(bool enable, uint32_t *pending);
109   virtual HWC2::Error SetReadbackBuffer(const native_handle_t *buffer,
110                                         shared_ptr<Fence> acquire_fence,
111                                         bool post_processed_output, CWBClient client);
112   virtual HWC2::Error GetReadbackBufferFence(shared_ptr<Fence> *release_fence);
113   virtual HWC2::Error SetQSyncMode(QSyncMode qsync_mode);
114   virtual DisplayError ControlIdlePowerCollapse(bool enable, bool synchronous);
115   virtual HWC2::Error SetDisplayDppsAdROI(uint32_t h_start, uint32_t h_end, uint32_t v_start,
116                                           uint32_t v_end, uint32_t factor_in, uint32_t factor_out);
117   virtual DisplayError SetDynamicDSIClock(uint64_t bitclk);
118   virtual DisplayError GetDynamicDSIClock(uint64_t *bitclk);
119   virtual DisplayError GetSupportedDSIClock(std::vector<uint64_t> *bitclk_rates);
120   virtual HWC2::Error UpdateDisplayId(hwc2_display_t id);
121   virtual HWC2::Error SetPendingRefresh();
122   virtual HWC2::Error SetPanelBrightness(float brightness);
123   virtual HWC2::Error GetPanelBrightness(float *brightness);
124   virtual HWC2::Error GetPanelMaxBrightness(uint32_t *max_brightness_level);
125   virtual DisplayError SetCurrentPanelGammaSource(enum PanelGammaSource source) override;
GetCurrentPanelGammaSource()126   virtual PanelGammaSource GetCurrentPanelGammaSource() const override { return current_panel_gamma_source_; };
127   virtual DisplayError TeardownConcurrentWriteback(void);
SetFastPathComposition(bool enable)128   virtual void SetFastPathComposition(bool enable) {
129     fast_path_composition_ = enable && !readback_buffer_queued_;
130   }
131   virtual HWC2::Error SetFrameTriggerMode(uint32_t mode);
132   virtual HWC2::Error SetBLScale(uint32_t level);
133   virtual HWC2::Error UpdatePowerMode(HWC2::PowerMode mode);
134   virtual HWC2::Error SetClientTarget(buffer_handle_t target, shared_ptr<Fence> acquire_fence,
135                                       int32_t dataspace, hwc_region_t damage);
136   virtual bool IsSmartPanelConfig(uint32_t config_id);
137   virtual bool HasSmartPanelConfig(void);
138   virtual int Deinit();
139   virtual bool IsQsyncCallbackNeeded(bool *qsync_enabled, int32_t *refresh_rate,
140                                      int32_t *qsync_refresh_rate);
141   virtual int PostInit();
142 
143   virtual HWC2::Error SetDisplayedContentSamplingEnabledVndService(bool enabled);
144   virtual HWC2::Error SetDisplayedContentSamplingEnabled(int32_t enabled, uint8_t component_mask,
145                                                          uint64_t max_frames);
146   virtual HWC2::Error GetDisplayedContentSamplingAttributes(int32_t *format, int32_t *dataspace,
147                                                             uint8_t *supported_components);
148   virtual HWC2::Error GetDisplayedContentSample(
149       uint64_t max_frames, uint64_t timestamp, uint64_t *numFrames,
150       int32_t samples_size[NUM_HISTOGRAM_COLOR_COMPONENTS],
151       uint64_t *samples[NUM_HISTOGRAM_COLOR_COMPONENTS]);
152   void Dump(std::ostringstream *os) override;
153   virtual HWC2::Error SetPowerMode(HWC2::PowerMode mode, bool teardown);
154   virtual bool HasReadBackBufferSupport();
155 
156   virtual bool IsHbmSupported() override;
157   virtual HWC2::Error SetHbm(HbmState state, HbmClient client) override;
158   virtual HbmState GetHbm() override;
159 
160  private:
161   HWCDisplayBuiltIn(CoreInterface *core_intf, BufferAllocator *buffer_allocator,
162                     HWCCallbacks *callbacks, HWCDisplayEventHandler *event_handler,
163                     qService::QService *qservice, hwc2_display_t id, int32_t sdm_id);
164   void SetMetaDataRefreshRateFlag(bool enable);
165   virtual DisplayError SetDisplayMode(uint32_t mode);
166   virtual DisplayError DisablePartialUpdateOneFrame();
167   void ProcessBootAnimCompleted(void);
168   void SetQDCMSolidFillInfo(bool enable, const LayerSolidFill &color);
169   void ToggleCPUHint(bool set);
170   void ForceRefreshRate(uint32_t refresh_rate);
171   uint32_t GetOptimalRefreshRate(bool one_updating_layer);
172   void HandleFrameOutput();
173   void HandleFrameDump();
174   void HandleFrameCapture();
175   bool CanSkipCommit();
176   DisplayError SetMixerResolution(uint32_t width, uint32_t height);
177   DisplayError GetMixerResolution(uint32_t *width, uint32_t *height);
178   HWC2::Error CommitStitchLayers();
179   void AppendStitchLayer();
180   bool InitLayerStitch();
181   void InitStitchTarget();
182   bool AllocateStitchBuffer();
183   void CacheAvrStatus();
184   void PostCommitStitchLayers();
185   int GetBwCode(const DisplayConfigVariableInfo &attr);
186   void SetBwLimitHint(bool enable);
187   void SetPartialUpdate(DisplayConfigFixedInfo fixed_info);
188   HWC2::Error ApplyHbmLocked() REQUIRES(hbm_mutex);
189 
190   // SyncTask methods.
191   void OnTask(const LayerStitchTaskCode &task_code,
192               SyncTask<LayerStitchTaskCode>::TaskContext *task_context);
193 
194   constexpr static int kBwLow = 2;
195   constexpr static int kBwMedium = 3;
196   constexpr static int kBwHigh = 4;
197 
198   BufferAllocator *buffer_allocator_ = nullptr;
199   CPUHint *cpu_hint_ = nullptr;
200   CWBClient cwb_client_ = kCWBClientNone;
201 
202   // Builtin readback buffer configuration
203   LayerBuffer output_buffer_ = {};
204   bool post_processed_output_ = false;
205   bool readback_buffer_queued_ = false;
206   bool readback_configured_ = false;
207 
208   // Members for N frame output dump to file
209   bool dump_output_to_file_ = false;
210   BufferInfo output_buffer_info_ = {};
211   void *output_buffer_base_ = nullptr;
212   bool pending_refresh_ = true;
213   bool enable_optimize_refresh_ = false;
214 
215   // Members for 1 frame capture in a client provided buffer
216   bool frame_capture_buffer_queued_ = false;
217   int frame_capture_status_ = -EAGAIN;
218   bool is_primary_ = false;
219   bool disable_layer_stitch_ = true;
220   HWCLayer* stitch_target_ = nullptr;
221   SyncTask<LayerStitchTaskCode> layer_stitch_task_;
222   GLLayerStitch* gl_layer_stitch_ = nullptr;
223   BufferInfo buffer_info_ = {};
224   DisplayConfigVariableInfo fb_config_ = {};
225 
226   enum PanelGammaSource current_panel_gamma_source_ = kGammaDefault;
227 
228   bool qsync_enabled_ = false;
229   bool qsync_reconfigured_ = false;
230   // Members for Color sampling feature
231   DisplayError HistogramEvent(int fd, uint32_t blob_id) override;
232   histogram::HistogramCollector histogram;
233   std::mutex sampling_mutex;
234   bool api_sampling_vote = false;
235   bool vndservice_sampling_vote = false;
236   int curr_refresh_rate_ = 0;
237   bool is_smart_panel_ = false;
238   const char *kDisplayBwName = "display_bw";
239   bool enable_bw_limits_ = false;
240 
241   // Members for HBM feature
242   static constexpr const char kHighBrightnessModeNode[] =
243       "/sys/class/backlight/panel0-backlight/hbm_mode";
244   static constexpr float hbm_threshold_pct_ = 0.5f;
245   const bool mHasHbmNode = !access(kHighBrightnessModeNode, F_OK);
246   std::mutex hbm_mutex;
247   float hbm_threshold_px_ = std::numeric_limits<float>::max();
248   bool has_config_hbm_threshold_ = false;
249   bool high_brightness_mode_ = false;
250   HbmState mHbmSates[CLIENT_MAX] GUARDED_BY(hbm_mutex) = {HbmState::OFF};
251   HbmState mCurHbmState GUARDED_BY(hbm_mutex) = HbmState::OFF;
252 };
253 
254 }  // namespace sdm
255 
256 #endif  // __HWC_DISPLAY_BUILTIN_H__
257