1 /*
2  * Copyright (c) 2014-2016, 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 
38 namespace sdm {
39 
40 class HWCDisplayPrimary : public HWCDisplay {
41  public:
42   enum {
43     SET_METADATA_DYN_REFRESH_RATE,
44     SET_BINDER_DYN_REFRESH_RATE,
45     SET_DISPLAY_MODE,
46     SET_QDCM_SOLID_FILL_INFO,
47     UNSET_QDCM_SOLID_FILL_INFO,
48     SET_QDCM_SOLID_FILL_RECT,
49   };
50 
51   static int Create(CoreInterface *core_intf, BufferAllocator *buffer_allocator,
52                     HWCCallbacks *callbacks, qService::QService *qservice,
53                     HWCDisplay **hwc_display);
54   static void Destroy(HWCDisplay *hwc_display);
55   virtual int Init();
56   virtual HWC2::Error Validate(uint32_t *out_num_types, uint32_t *out_num_requests);
57   virtual HWC2::Error Present(int32_t *out_retire_fence);
58   virtual HWC2::Error GetColorModes(uint32_t *out_num_modes, android_color_mode_t *out_modes);
59   virtual HWC2::Error SetColorMode(android_color_mode_t mode);
60   virtual HWC2::Error SetColorTransform(const float *matrix, android_color_transform_t hint);
61   virtual HWC2::Error RestoreColorTransform();
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 
72  private:
73   HWCDisplayPrimary(CoreInterface *core_intf, BufferAllocator *buffer_allocator,
74                     HWCCallbacks *callbacks, qService::QService *qservice);
75   void SetMetaDataRefreshRateFlag(bool enable);
76   virtual DisplayError SetDisplayMode(uint32_t mode);
77   virtual DisplayError DisablePartialUpdateOneFrame();
78   void ProcessBootAnimCompleted(void);
79   void SetQDCMSolidFillInfo(bool enable, uint32_t color);
80   void ToggleCPUHint(bool set);
81   void ForceRefreshRate(uint32_t refresh_rate);
82   uint32_t GetOptimalRefreshRate(bool one_updating_layer);
83   void HandleFrameOutput();
84   void HandleFrameCapture();
85   void HandleFrameDump();
86   DisplayError SetMixerResolution(uint32_t width, uint32_t height);
87   DisplayError GetMixerResolution(uint32_t *width, uint32_t *height);
88 
89   BufferAllocator *buffer_allocator_ = nullptr;
90   CPUHint *cpu_hint_ = nullptr;
91   bool handle_idle_timeout_ = false;
92 
93   // Primary output buffer configuration
94   LayerBuffer output_buffer_ = {};
95   bool post_processed_output_ = false;
96 
97   // Members for 1 frame capture in a client provided buffer
98   bool frame_capture_buffer_queued_ = false;
99   int frame_capture_status_ = -EAGAIN;
100 
101   // Members for N frame output dump to file
102   bool dump_output_to_file_ = false;
103   BufferInfo output_buffer_info_ = {};
104   void *output_buffer_base_ = nullptr;
105   int default_mode_status_ = 0;
106 };
107 
108 }  // namespace sdm
109 
110 #endif  // __HWC_DISPLAY_PRIMARY_H__
111