Arun Kumar K.R | 51be3d1 | 2017-03-31 19:54:38 -0700 | [diff] [blame] | 1 | /* |
Rajavenu Kyatham | 7338b9e | 2019-12-30 19:52:16 +0530 | [diff] [blame] | 2 | * Copyright (c) 2016 - 2018, 2020 The Linux Foundation. All rights reserved. |
Arun Kumar K.R | 51be3d1 | 2017-03-31 19:54:38 -0700 | [diff] [blame] | 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_TONEMAPPER_H__ |
| 31 | #define __HWC_TONEMAPPER_H__ |
| 32 | |
| 33 | #include <fcntl.h> |
| 34 | #include <sys/mman.h> |
| 35 | |
| 36 | #include <hardware/hwcomposer.h> |
| 37 | |
| 38 | #include <core/layer_stack.h> |
| 39 | #include <utils/sys.h> |
Dileep Marchya | 7061aea | 2017-06-05 12:52:56 +0530 | [diff] [blame] | 40 | #include <utils/sync_task.h> |
Arun Kumar K.R | 51be3d1 | 2017-03-31 19:54:38 -0700 | [diff] [blame] | 41 | #include <vector> |
| 42 | #include "hwc_buffer_sync_handler.h" |
| 43 | #include "hwc_buffer_allocator.h" |
| 44 | |
| 45 | class Tonemapper; |
| 46 | |
| 47 | namespace sdm { |
| 48 | |
Dileep Marchya | 7061aea | 2017-06-05 12:52:56 +0530 | [diff] [blame] | 49 | enum class ToneMapTaskCode : int32_t { |
| 50 | kCodeGetInstance, |
| 51 | kCodeBlit, |
| 52 | kCodeDestroy, |
| 53 | }; |
| 54 | |
| 55 | struct ToneMapGetInstanceContext : public SyncTask<ToneMapTaskCode>::TaskContext { |
| 56 | Layer *layer = nullptr; |
| 57 | }; |
| 58 | |
| 59 | struct ToneMapBlitContext : public SyncTask<ToneMapTaskCode>::TaskContext { |
| 60 | Layer *layer = nullptr; |
Rajavenu Kyatham | 7338b9e | 2019-12-30 19:52:16 +0530 | [diff] [blame] | 61 | shared_ptr<Fence> merged = nullptr; |
| 62 | shared_ptr<Fence> fence = nullptr; |
Dileep Marchya | 7061aea | 2017-06-05 12:52:56 +0530 | [diff] [blame] | 63 | }; |
| 64 | |
Arun Kumar K.R | 51be3d1 | 2017-03-31 19:54:38 -0700 | [diff] [blame] | 65 | struct ToneMapConfig { |
| 66 | int type = 0; |
Arun Kumar K.R | 4461efa | 2017-12-27 15:53:20 +0530 | [diff] [blame] | 67 | PrimariesTransfer blend_cs = {}; |
Arun Kumar K.R | 51be3d1 | 2017-03-31 19:54:38 -0700 | [diff] [blame] | 68 | GammaTransfer transfer = Transfer_Max; |
| 69 | LayerBufferFormat format = kFormatRGBA8888; |
| 70 | bool secure = false; |
| 71 | }; |
| 72 | |
Dileep Marchya | 7061aea | 2017-06-05 12:52:56 +0530 | [diff] [blame] | 73 | class ToneMapSession : public SyncTask<ToneMapTaskCode>::TaskHandler { |
Arun Kumar K.R | 51be3d1 | 2017-03-31 19:54:38 -0700 | [diff] [blame] | 74 | public: |
| 75 | explicit ToneMapSession(HWCBufferAllocator *buffer_allocator); |
| 76 | ~ToneMapSession(); |
| 77 | DisplayError AllocateIntermediateBuffers(const Layer *layer); |
| 78 | void FreeIntermediateBuffers(); |
Rajavenu Kyatham | 7338b9e | 2019-12-30 19:52:16 +0530 | [diff] [blame] | 79 | void UpdateBuffer(const shared_ptr<Fence> &acquire_fence, LayerBuffer *buffer); |
| 80 | void SetReleaseFence(const shared_ptr<Fence> &fd); |
Sushil Chauhan | 32c1869 | 2018-02-04 22:47:54 -0800 | [diff] [blame] | 81 | void SetToneMapConfig(Layer *layer, PrimariesTransfer blend_cs); |
| 82 | bool IsSameToneMapConfig(Layer *layer, PrimariesTransfer blend_cs); |
Arun Kumar K.R | 51be3d1 | 2017-03-31 19:54:38 -0700 | [diff] [blame] | 83 | |
Dileep Marchya | 7061aea | 2017-06-05 12:52:56 +0530 | [diff] [blame] | 84 | // TaskHandler methods implementation. |
| 85 | virtual void OnTask(const ToneMapTaskCode &task_code, |
| 86 | SyncTask<ToneMapTaskCode>::TaskContext *task_context); |
| 87 | |
Arun Kumar K.R | 51be3d1 | 2017-03-31 19:54:38 -0700 | [diff] [blame] | 88 | static const uint8_t kNumIntermediateBuffers = 2; |
Dileep Marchya | 7061aea | 2017-06-05 12:52:56 +0530 | [diff] [blame] | 89 | SyncTask<ToneMapTaskCode> tone_map_task_; |
Arun Kumar K.R | 51be3d1 | 2017-03-31 19:54:38 -0700 | [diff] [blame] | 90 | Tonemapper *gpu_tone_mapper_ = nullptr; |
| 91 | HWCBufferAllocator *buffer_allocator_ = nullptr; |
| 92 | ToneMapConfig tone_map_config_ = {}; |
| 93 | uint8_t current_buffer_index_ = 0; |
| 94 | std::vector<BufferInfo> buffer_info_ = {}; |
Rajavenu Kyatham | 7338b9e | 2019-12-30 19:52:16 +0530 | [diff] [blame] | 95 | shared_ptr<Fence> release_fence_[kNumIntermediateBuffers] = {nullptr, nullptr}; |
Arun Kumar K.R | 51be3d1 | 2017-03-31 19:54:38 -0700 | [diff] [blame] | 96 | bool acquired_ = false; |
| 97 | int layer_index_ = -1; |
| 98 | }; |
| 99 | |
| 100 | class HWCToneMapper { |
| 101 | public: |
| 102 | explicit HWCToneMapper(HWCBufferAllocator *allocator) : buffer_allocator_(allocator) {} |
| 103 | ~HWCToneMapper() {} |
| 104 | |
| 105 | int HandleToneMap(LayerStack *layer_stack); |
| 106 | bool IsActive() { return !tone_map_sessions_.empty(); } |
| 107 | void PostCommit(LayerStack *layer_stack); |
| 108 | void SetFrameDumpConfig(uint32_t count); |
| 109 | void Terminate(); |
| 110 | |
| 111 | private: |
| 112 | void ToneMap(Layer *layer, ToneMapSession *session); |
Sushil Chauhan | 32c1869 | 2018-02-04 22:47:54 -0800 | [diff] [blame] | 113 | DisplayError AcquireToneMapSession(Layer *layer, uint32_t *sess_idx, PrimariesTransfer blend_cs); |
Rajavenu Kyatham | 7338b9e | 2019-12-30 19:52:16 +0530 | [diff] [blame] | 114 | void DumpToneMapOutput(ToneMapSession *session, shared_ptr<sdm::Fence> acquire_fence); |
Arun Kumar K.R | 51be3d1 | 2017-03-31 19:54:38 -0700 | [diff] [blame] | 115 | |
| 116 | std::vector<ToneMapSession*> tone_map_sessions_; |
Arun Kumar K.R | 51be3d1 | 2017-03-31 19:54:38 -0700 | [diff] [blame] | 117 | HWCBufferAllocator *buffer_allocator_ = nullptr; |
| 118 | uint32_t dump_frame_count_ = 0; |
| 119 | uint32_t dump_frame_index_ = 0; |
Sushil Chauhan | 00e26b4 | 2017-07-25 16:43:52 -0700 | [diff] [blame] | 120 | int fb_session_index_ = -1; |
Arun Kumar K.R | 51be3d1 | 2017-03-31 19:54:38 -0700 | [diff] [blame] | 121 | }; |
| 122 | |
| 123 | } // namespace sdm |
| 124 | #endif // __HWC_TONEMAPPER_H__ |