1 /* 2 * Copyright (c) 2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef LAYER_CONTEXT_H 17 #define LAYER_CONTEXT_H 18 19 #include <display_type.h> 20 #include <surface.h> 21 #include "hdi_layer_info.h" 22 #include "sync_fence.h" 23 24 namespace OHOS { 25 namespace Rosen { 26 enum LayerType : uint32_t { 27 LAYER_STATUS, 28 LAYER_LAUNCHER, 29 LAYER_NAVIGATION, 30 LAYER_EXTRA 31 }; 32 33 using YUVPixel = struct { 34 uint8_t y; 35 uint8_t u; 36 uint8_t v; 37 }; 38 39 class LayerContext : public IBufferConsumerListenerClazz { 40 public: 41 LayerContext(IRect dst, IRect src, uint32_t zorder, LayerType layerType); 42 virtual ~LayerContext(); 43 static constexpr uint32_t PIXEL_LINE_ALIGNMENT = 32; 44 static constexpr uint32_t RBGA_R_MOVEBITS = 24; 45 static constexpr uint32_t RBGA_B_MOVEBITS = 16; 46 static constexpr uint32_t RBGA_G_MOVEBITS = 8; 47 static constexpr uint32_t PIXEL_YCBCR420_UV_NUM = 2; 48 static constexpr float PIXEL_YCBCR420_BYTE = 1.5; 49 50 void OnBufferAvailable() override; 51 SurfaceError DrawBufferColor(); 52 SurfaceError FillHDILayer(); 53 const std::shared_ptr<HdiLayerInfo> GetHdiLayer(); 54 void SetTestClientStatus(bool status); 55 void SetTestRotateStatus(bool status); 56 void SetTestYUVStatus(bool status); 57 LayerType GetLayerType() const; GetPreBuffer()58 sptr<SurfaceBuffer> GetPreBuffer() const 59 { 60 return prevBuffer_; 61 } GetPreFence()62 sptr<SyncFence> GetPreFence() const 63 { 64 return prevFence_; 65 } 66 67 private: 68 const std::vector<uint32_t> colors_ = {0xff0000ff, 0xffff00ff, 0xaa00ff00, 0xff00ffaa, 0xff0f0f00}; 69 IRect dst_; 70 IRect src_; 71 uint32_t colorIndex_ = 0; 72 uint32_t frameCounter_ = 0; 73 uint32_t color_ = 0xffff1111; 74 uint32_t zorder_ = 0; 75 sptr<SyncFence> prevFence_; 76 OHOS::sptr<Surface> pSurface_; 77 OHOS::sptr<Surface> cSurface_; 78 OHOS::sptr<SurfaceBuffer> prevBuffer_; 79 std::shared_ptr<HdiLayerInfo> hdiLayer_; 80 LayerType layerType_ = LayerType::LAYER_EXTRA; 81 bool testClient_ = false; 82 bool testRotate_ = false; 83 bool testYUV_ = false; 84 85 void DrawColor(void *image, int width, int height); 86 void DrawExtraColor(void *image, uint32_t width, uint32_t height); 87 void DrawBaseColor(void *image, uint32_t width, uint32_t height); 88 void DrawYUVColor(void *image, uint32_t width, uint32_t height, YUVPixel pixelValueYUV); 89 void ConvertRBGA2YUV(uint32_t pixelValueRBGA, YUVPixel *pixelValueYUV); 90 void SetLayerTransformType(); 91 void SetLayerCompositionType(); 92 }; 93 } // namespace Rosen 94 } // namespace OHOS 95 96 #endif // LAYER_CONTEXT_H