1/* Copyright (c) 2012 - 2016, The Linux Foundation. All rights reserved. 2* 3* Redistribution and use in source and binary forms, with or without 4* modification, are permitted provided that the following conditions are 5* met: 6* * Redistributions of source code must retain the above copyright 7* notice, this list of conditions and the following disclaimer. 8* * Redistributions in binary form must reproduce the above 9* copyright notice, this list of conditions and the following 10* disclaimer in the documentation and/or other materials provided 11* with the distribution. 12* * Neither the name of The Linux Foundation nor the names of its 13* contributors may be used to endorse or promote products derived 14* from this software without specific prior written permission. 15* 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* Portions formerly licensed under Apache License, Version 2.0, are re licensed 30* under section 4 of Apache License, Version 2.0. 31 32* Copyright (C) 2010 The Android Open Source Project 33 34* Not a Contribution. 35 36* Licensed under the Apache License, Version 2.0 (the "License"); 37* you may not use this file except in compliance with the License. 38* You may obtain a copy of the License at 39 40* http://www.apache.org/licenses/LICENSE-2.0 41 42* Unless required by applicable law or agreed to in writing, software 43* distributed under the License is distributed on an "AS IS" BASIS, 44* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 45* See the License for the specific language governing permissions and 46* limitations under the License. 47*/ 48 49/*! @file blit_engine.h 50 @brief Interface file for Blit based compositior. 51 52 @details The client can use this interface to get the blit composition done 53 54*/ 55 56#include <hardware/hwcomposer.h> 57#include <core/layer_stack.h> 58#include <copybit.h> 59#include "blit_engine.h" 60 61#ifndef __BLIT_ENGINE_C2D_H__ 62#define __BLIT_ENGINE_C2D_H__ 63 64namespace sdm { 65 66// C2D Blit implemented by the client 67// This class implements the BlitEngine Interface which is used to get the 68// Blit composition using C2D 69class BlitEngineC2d : public BlitEngine { 70 public: 71 BlitEngineC2d(); 72 virtual ~BlitEngineC2d(); 73 74 virtual int Init(); 75 virtual void DeInit(); 76 virtual int Prepare(LayerStack *layer_stack); 77 virtual int PreCommit(hwc_display_contents_1_t *content_list, LayerStack *layer_stack); 78 virtual int Commit(hwc_display_contents_1_t *content_list, LayerStack *layer_stack); 79 virtual void PostCommit(LayerStack *layer_stack); 80 virtual bool BlitActive(); 81 virtual void SetFrameDumpConfig(uint32_t count); 82 83 84 private: 85 static const uint32_t kNumBlitTargetBuffers = 3; 86 87 struct Range { 88 int current; 89 int end; 90 }; 91 92 struct RegionIterator : public copybit_region_t { 93 explicit RegionIterator(LayerRectArray rect); 94 private: 95 static int iterate(copybit_region_t const *self, copybit_rect_t *rect); 96 LayerRectArray rect_array; 97 mutable Range r; 98 }; 99 100 int AllocateBlitTargetBuffers(uint32_t width, uint32_t height, uint32_t format, uint32_t usage); 101 void FreeBlitTargetBuffers(); 102 int ClearTargetBuffer(private_handle_t* hnd, const LayerRect& rect); 103 int DrawRectUsingCopybit(hwc_layer_1_t *hwc_layer, Layer *layer, LayerRect blit_rect, 104 LayerRect blit_dest_Rect); 105 void SetReleaseFence(int fence_fd); 106 void DumpBlitTargetBuffer(int fd); 107 108 copybit_device_t *blit_engine_c2d_ = NULL; 109 private_handle_t *blit_target_buffer_[kNumBlitTargetBuffers]; 110 uint32_t current_blit_target_index_ = 0; 111 int release_fence_fd_[kNumBlitTargetBuffers]; 112 uint32_t num_blit_target_ = 0; 113 int blit_target_start_index_ = 0; 114 bool blit_active_ = false; 115 uint32_t dump_frame_count_ = 0; 116 uint32_t dump_frame_index_ = 0; 117}; 118 119} // namespace sdm 120 121#endif // __BLIT_ENGINE_C2D_H__ 122