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 <surface.h> 20 #include "hdi_layer_info.h" 21 #include "sync_fence.h" 22 23 namespace OHOS { 24 namespace Rosen { 25 enum LayerType : uint32_t { 26 LAYER_STATUS, 27 LAYER_LAUNCHER, 28 LAYER_NAVIGATION, 29 LAYER_EXTRA 30 }; 31 32 using YUVPixel = struct { 33 uint8_t y; 34 uint8_t u; 35 uint8_t v; 36 }; 37 38 class LayerContext : public IBufferConsumerListenerClazz { 39 public: 40 LayerContext(GraphicIRect dst, GraphicIRect src, uint32_t zorder, LayerType layerType); 41 virtual ~LayerContext(); 42 static constexpr uint32_t PIXEL_LINE_ALIGNMENT = 32; 43 static constexpr uint32_t RBGA_R_MOVEBITS = 24; 44 static constexpr uint32_t RBGA_B_MOVEBITS = 16; 45 static constexpr uint32_t RBGA_G_MOVEBITS = 8; 46 static constexpr uint32_t PIXEL_YCBCR420_UV_NUM = 2; 47 static constexpr float PIXEL_YCBCR420_BYTE = 1.5; 48 49 void OnBufferAvailable() override; 50 SurfaceError DrawBufferColor(); 51 SurfaceError FillHDILayer(); 52 const std::shared_ptr<HdiLayerInfo> GetHdiLayer(); 53 void SetTestClientStatus(bool status); 54 void SetTestRotateStatus(bool status); 55 void SetTestYUVStatus(bool status); 56 LayerType GetLayerType() const; GetPreBuffer()57 sptr<SurfaceBuffer> GetPreBuffer() const 58 { 59 return prevBuffer_; 60 } GetPreFence()61 sptr<SyncFence> GetPreFence() const 62 { 63 return prevFence_; 64 } 65 66 private: 67 const std::vector<uint32_t> colors_ = {0xff0000ff, 0xffff00ff, 0xaa00ff00, 0xff00ffaa, 0xff0f0f00}; 68 GraphicIRect dst_; 69 GraphicIRect src_; 70 uint32_t colorIndex_ = 0; 71 uint32_t frameCounter_ = 0; 72 uint32_t color_ = 0xffff1111; 73 uint32_t zorder_ = 0; 74 sptr<SyncFence> prevFence_; 75 OHOS::sptr<Surface> pSurface_; 76 OHOS::sptr<IConsumerSurface> cSurface_; 77 OHOS::sptr<SurfaceBuffer> prevBuffer_; 78 std::shared_ptr<HdiLayerInfo> hdiLayer_; 79 LayerType layerType_ = LayerType::LAYER_EXTRA; 80 bool testClient_ = false; 81 bool testRotate_ = false; 82 bool testYUV_ = false; 83 84 void DrawColor(void *image, int width, int height); 85 void DrawExtraColor(void *image, uint32_t width, uint32_t height); 86 void DrawBaseColor(void *image, uint32_t width, uint32_t height); 87 void DrawYUVColor(void *image, uint32_t width, uint32_t height, YUVPixel pixelValueYUV); 88 void ConvertRBGA2YUV(uint32_t pixelValueRBGA, YUVPixel *pixelValueYUV); 89 void SetLayerTransformType(); 90 void SetLayerCompositionType(); 91 }; 92 } // namespace Rosen 93 } // namespace OHOS 94 95 #endif // LAYER_CONTEXT_H