1 /*
2  * Copyright (c) 2014-2016, 2018 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_PRIMARY_H__
31 #define __HWC_DISPLAY_PRIMARY_H__
32 
33 #include <string>
34 
35 #include "cpuhint.h"
36 #include "hwc_display.h"
37 #include "display_null.h"
38 
39 namespace sdm {
40 
41 class HWCDisplayPrimary : public HWCDisplay {
42  public:
43   enum {
44     SET_METADATA_DYN_REFRESH_RATE,
45     SET_BINDER_DYN_REFRESH_RATE,
46     SET_DISPLAY_MODE,
47     SET_QDCM_SOLID_FILL_INFO,
48     UNSET_QDCM_SOLID_FILL_INFO,
49     SET_QDCM_SOLID_FILL_RECT,
50   };
51 
52   static int Create(CoreInterface *core_intf, BufferAllocator *buffer_allocator,
53                     HWCCallbacks *callbacks, qService::QService *qservice,
54                     HWCDisplay **hwc_display);
55   static void Destroy(HWCDisplay *hwc_display);
56   virtual int Init();
57   virtual HWC2::Error Validate(uint32_t *out_num_types, uint32_t *out_num_requests);
58   virtual HWC2::Error Present(int32_t *out_retire_fence);
59   virtual HWC2::Error GetColorModes(uint32_t *out_num_modes, android_color_mode_t *out_modes);
60   virtual HWC2::Error SetColorMode(android_color_mode_t mode);
61   virtual HWC2::Error SetColorTransform(const float *matrix, android_color_transform_t hint);
62   virtual int Perform(uint32_t operation, ...);
63   virtual void SetSecureDisplay(bool secure_display_active);
64   virtual DisplayError Refresh();
65   virtual void SetIdleTimeoutMs(uint32_t timeout_ms);
66   virtual void SetFrameDumpConfig(uint32_t count, uint32_t bit_mask_layer_type);
67   virtual int FrameCaptureAsync(const BufferInfo &output_buffer_info, bool post_processed);
GetFrameCaptureStatus()68   virtual int GetFrameCaptureStatus() { return frame_capture_status_; }
69   virtual DisplayError SetDetailEnhancerConfig(const DisplayDetailEnhancerData &de_data);
70   virtual DisplayError ControlPartialUpdate(bool enable, uint32_t *pending);
71   virtual DisplayError SetStandByMode(bool enable);
72 
73  private:
74   HWCDisplayPrimary(CoreInterface *core_intf, BufferAllocator *buffer_allocator,
75                     HWCCallbacks *callbacks, qService::QService *qservice);
76   void SetMetaDataRefreshRateFlag(bool enable);
77   virtual DisplayError SetDisplayMode(uint32_t mode);
78   virtual DisplayError DisablePartialUpdateOneFrame();
79   void ProcessBootAnimCompleted(void);
80   void SetQDCMSolidFillInfo(bool enable, uint32_t color);
81   void ToggleCPUHint(bool set);
82   void ForceRefreshRate(uint32_t refresh_rate);
83   uint32_t GetOptimalRefreshRate(bool one_updating_layer);
84   void HandleFrameOutput();
85   void HandleFrameCapture();
86   void HandleFrameDump();
87   DisplayError SetMixerResolution(uint32_t width, uint32_t height);
88   DisplayError GetMixerResolution(uint32_t *width, uint32_t *height);
89 
90   BufferAllocator *buffer_allocator_ = nullptr;
91   CPUHint *cpu_hint_ = nullptr;
92   bool handle_idle_timeout_ = false;
93 
94   // Primary output buffer configuration
95   LayerBuffer output_buffer_ = {};
96   bool post_processed_output_ = false;
97 
98   // Members for 1 frame capture in a client provided buffer
99   bool frame_capture_buffer_queued_ = false;
100   int frame_capture_status_ = -EAGAIN;
101 
102   // Members for N frame output dump to file
103   bool dump_output_to_file_ = false;
104   BufferInfo output_buffer_info_ = {};
105   void *output_buffer_base_ = nullptr;
106   int default_mode_status_ = 0;
107 
108   //Null display
109   DisplayNull display_null_;
110   DisplayInterface *stored_display_intf_ = NULL;
111 
112 };
113 
114 }  // namespace sdm
115 
116 #endif  // __HWC_DISPLAY_PRIMARY_H__
117