• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1  /*
2   * Copyright (c) 2020-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 GRAPHIC_LITE_SCREEN_DEVICE_H
17  #define GRAPHIC_LITE_SCREEN_DEVICE_H
18  
19  #include "gfx_utils/color.h"
20  #include "gfx_utils/graphic_assert.h"
21  #include "gfx_utils/rect.h"
22  #include "graphic_semaphore.h"
23  #if ENABLE_WINDOW
24  #include "gfx_utils/pixel_format_utils.h"
25  #endif
26  
27  namespace OHOS {
28  #if ENABLE_WINDOW
29  struct AllocationInfo {
30      uint8_t* virAddr;
31      uint8_t* phyAddr;
32      uint16_t width;
33      uint16_t height;
34      uint32_t stride;
35      ImagePixelFormat pixelFormat;
36  };
37  #endif
38  
39  #ifndef TRANSFORMOPTION
40  #define TRANSFORMOPTION
41  struct TransformOption {
42      TransformAlgorithm algorithm;
43  };
44  #endif
45  
46  /** @brief A semaphore for display buffer flushing. */
47  class FlushSem : public HeapBase {
48  public:
49      /**
50       * Constructor
51       *
52       * @param [in] isFlushing (Optional) True if is flushing, false if not.
53       */
54      FlushSem(bool isFlushing = false) : sem_(1, 1), isFlushing_(isFlushing) {}
55  
56      /**
57       * @brief Destructor
58       */
~FlushSem()59      virtual ~FlushSem() {}
60  
61      /** Notifies the buffer is flushing end */
Notify()62      void Notify()
63      {
64          isFlushing_ = false;
65          sem_.Notify();
66      }
67  
68      /** Waits the buffer is flushing */
Wait()69      void Wait()
70      {
71          while (isFlushing_) {
72              sem_.Wait();
73          }
74      }
75  
76      /** set the flag as flashing */
Flushing()77      void Flushing()
78      {
79          isFlushing_ = true;
80      }
81  
82  private:
83      GraphicSemaphore sem_;
84      bool isFlushing_;
85  };
86  
87  /** @brief A display device. */
88  class ScreenDevice : public HeapBase {
89  public:
90      /**
91       * @brief Constructor
92       */
ScreenDevice()93      ScreenDevice() {}
94  
95      /**
96       * @brief Destructor
97       */
~ScreenDevice()98      virtual ~ScreenDevice() {}
99  
Flush(int16_t x1,int16_t y1,int16_t x2,int16_t y2,const uint8_t * buffer,ColorMode mode)100      virtual void Flush(int16_t x1, int16_t y1, int16_t x2, int16_t y2, const uint8_t* buffer, ColorMode mode) {}
101  
Fill(int16_t x1,int16_t y1,int16_t x2,int16_t y2,const ColorType & color)102      virtual void Fill(int16_t x1, int16_t y1, int16_t x2, int16_t y2, const ColorType& color) {}
103  
104      /**
105       * @brief Hardware accelerated filling interface implemented by the product platform
106       * @param fillArea Indicates the area to be filled
107       * @param color Indicates the color to be filled
108       * @param opa Indicates the transparency
109       * @param dst Indicates the start address of destination memory
110       * @param dstStride Indicates the number of bytes in a single row of destination memory
111       * @param dstColorMode Indicates the color format of destination memory
112       * @return Return true on success, false on failure
113       * @since 5.0
114       * @version 3.0
115       */
HardwareFill(const Rect & fillArea,uint32_t color,OpacityType opa,uint8_t * dst,uint32_t dstStride,ColorMode dstColorMode)116      virtual bool HardwareFill(const Rect& fillArea,
117                                uint32_t color,
118                                OpacityType opa,
119                                uint8_t* dst,
120                                uint32_t dstStride,
121                                ColorMode dstColorMode)
122      {
123          return false;
124      }
125  
126      /**
127       * @brief Hardware accelerated blending interface implemented by the product platform
128       * @param src Indicates the start address of source memory
129       * @param srcRect Indicates the area of ​​the source memory for color blending
130       * @param srcStride Indicates the number of bytes in a single row of source memory
131       * @param srcLineNumber Indicates the number of source memory rows
132       * @param srcColorMode Indicates the source memory color format
133       * @param color 32-bit XRGB8888 value
134       *              (valid when the source memory is in a format with only alph information such as A1)
135       * @param opa Indicates the transparency
136       * @param dst Indicates the start address of destination memory
137       * @param dstStride Indicates the number of bytes in a single row of destination memory
138       * @param dstColorMode Indicates the color format of destination memory
139       * @param x The x coordinate of the upper left vertex of the destination memory for color blending
140       * @param y The y coordinate of the upper left vertex of the destination memory for color blending
141       * @return Return true on success, false on failure
142       * @since 5.0
143       * @version 3.0
144       */
HardwareBlend(const uint8_t * src,const Rect & srcRect,uint32_t srcStride,uint32_t srcLineNumber,ColorMode srcColorMode,uint32_t color,OpacityType opa,uint8_t * dst,uint32_t dstStride,ColorMode dstColorMode,uint32_t x,uint32_t y)145      virtual bool HardwareBlend(const uint8_t* src,
146                                 const Rect& srcRect,
147                                 uint32_t srcStride,
148                                 uint32_t srcLineNumber,
149                                 ColorMode srcColorMode,
150                                 uint32_t color,
151                                 OpacityType opa,
152                                 uint8_t* dst,
153                                 uint32_t dstStride,
154                                 ColorMode dstColorMode,
155                                 uint32_t x,
156                                 uint32_t y)
157      {
158          return false;
159      }
160  
161      /**
162       * @brief Hardware accelerated transformation interface implemented by the product platform
163       * @param src Indicates the start address of the source image
164       * @param srcColorMode Indicates the color format of the source image
165       * @param srcRect Indicates the position of the source image in the destination memory and its width and height
166       * @param transformMatrix  Indicates the transformation matrix
167       * @param opa Indicates the transparency
168       * @param color 32-bit XRGB8888 value
169       *              (valid when the source memory is in a format with only alph information such as A1)
170       * @param mask Indicates the masking rectangle, and the content beyond the rectangle is not drawn
171       * @param dst Indicates the start address of destination memory
172       * @param dstStride Indicates the number of bytes in a single row of destination memory
173       * @param dstColorMode Indicates the color format of destination memory
174       * @param option Indicates the optional setting items for transformation operation
175       * @return Return true on success, false on failure
176       * @since 5.0
177       * @version 3.0
178       */
HardwareTransform(const uint8_t * src,ColorMode srcColorMode,const Rect & srcRect,const Matrix3<float> & transformMatrix,OpacityType opa,uint32_t color,const Rect & mask,uint8_t * dst,uint32_t dstStride,ColorMode dstColorMode,const TransformOption & option)179      virtual bool HardwareTransform(const uint8_t* src,
180                                     ColorMode srcColorMode,
181                                     const Rect& srcRect,
182                                     const Matrix3<float>& transformMatrix,
183                                     OpacityType opa,
184                                     uint32_t color,
185                                     const Rect& mask,
186                                     uint8_t* dst,
187                                     uint32_t dstStride,
188                                     ColorMode dstColorMode,
189                                     const TransformOption& option)
190      {
191          return false;
192      }
193  
SnapShot(uint32_t len,bool justCopy,uint8_t * dest,const Rect & rect,bool justRender)194      virtual void SnapShot(uint32_t len,
195                            bool justCopy,
196                            uint8_t* dest,
197                            const Rect& rect,
198                            bool justRender)
199      {
200      }
201  
RenderFinish(const Rect & mask)202      virtual void RenderFinish(const Rect& mask) {}
203  };
204  } // namespace OHOS
205  #endif // GRAPHIC_LITE_SCREEN_DEVICE_H