1 /* 2 * Copyright (c) 2022 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 /** 17 * @file renderer_base.h 18 * @brief Defines Base renderer 19 * @since 1.0 20 * @version 1.0. 21 */ 22 23 #ifndef GRAPHIC_LITE_RENDER_BASE_H 24 #define GRAPHIC_LITE_RENDER_BASE_H 25 26 #include "gfx_utils/diagram/common/common_basics.h" 27 #include "render/render_buffer.h" 28 #include "render/render_pixfmt_rgba_blend.h" 29 #include "gfx_utils/color.h" 30 namespace OHOS { 31 class RenderBase { 32 public: RenderBase()33 RenderBase() : pixfmtType_(nullptr), clipBox_(1, 1, 0, 0) {} 34 RenderBase(RenderPixfmtRgbaBlend & ren)35 explicit RenderBase(RenderPixfmtRgbaBlend& ren) 36 : pixfmtType_(&ren), clipBox_(0, 0, ren.GetWidth() - 1, ren.GetHeight() - 1) {} 37 38 /** 39 * @brief afferent pixfmt_type param. 40 */ 41 void Attach(RenderPixfmtRgbaBlend& ren); 42 43 /** 44 * @brief Gets the width to render. 45 */ GetWidth()46 uint32_t GetWidth() const 47 { 48 return pixfmtType_->GetWidth(); 49 } 50 51 /** 52 * @brief Gets the height to render. 53 */ GetHeight()54 uint32_t GetHeight() const 55 { 56 return pixfmtType_->GetHeight(); 57 } 58 59 /** 60 * @brief ClipBox Sets the size of the clipping box. 61 * @param x1 rectangular starting point x coordinate. 62 * @param y1 rectangular starting point y coordinate. 63 * @param x2 rectangular diagonal x coordinate. 64 * @param y2 rectangular diagonal y coordinate. 65 * @return Returns whether the rectangle was created successfully. 66 */ 67 bool ClipBox(int32_t x1, int32_t y1, int32_t x2, int32_t y2); 68 69 /** 70 * @brief ResetClipping Set the size of the clipping box according to the visibility, 71 * The visibility is set to normal, and the invisibility is set to one pixel. 72 * @param visibility Visible. 73 */ 74 void ResetClipping(bool visibility); 75 76 /** 77 * @brief ClipBoxNaked Sets the size of the box. 78 * @param x1 rectangular starting point x coordinate. 79 * @param y1 rectangular starting point y coordinate. 80 * @param x2 rectangular starting point x coordinate. 81 * @param y2 rectangular starting point y coordinate. 82 */ 83 void ClipBoxNaked(int32_t x1, int32_t y1, int32_t x2, int32_t y2); 84 85 /** 86 * @brief inbox determines whether the point (x, y) is within the rectangle. 87 * @param x coordinate of x point. 88 * @param y coordinate of y point. 89 * @return Return whether. 90 */ Inbox(int32_t x,int32_t y)91 bool Inbox(int32_t x, int32_t y) const 92 { 93 return x >= clipBox_.GetLeft() && y >= clipBox_.GetTop() && 94 x <= clipBox_.GetRight() && y <= clipBox_.GetBottom(); 95 } 96 97 /** 98 * @brief GetClipBox Get cut box. 99 * @return Return to the corresponding box. 100 */ GetClipBox()101 const Rect32& GetClipBox() const 102 { 103 return clipBox_; 104 } 105 106 /** 107 * @return Returns the minimum value of the x-axis of the box. 108 */ GetXMin()109 int32_t GetXMin() const 110 { 111 return clipBox_.GetLeft(); 112 } 113 114 /** 115 * @return Returns the minimum value of the y-axis of the box. 116 */ GetYMin()117 int32_t GetYMin() const 118 { 119 return clipBox_.GetTop(); 120 } 121 122 /** 123 * @return Returns the maximum value of the x-axis of the box. 124 */ GetXMax()125 int32_t GetXMax() const 126 { 127 return clipBox_.GetRight(); 128 } 129 130 /** 131 * @return Returns the maximum value of the Y-axis of the box. 132 */ GetYMax()133 int32_t GetYMax() const 134 { 135 return clipBox_.GetBottom(); 136 } 137 138 /** 139 * @brief Clear clear the pixels in the rectangle under getwidth() width and getheight() height with color. 140 * @param color colour. 141 */ 142 void Clear(const Rgba8T& color); 143 144 /** 145 * @brief BlendHLine Render scanlines within a certain range of the X axis on the Y axis. 146 * @param x1 Scan line left coordinate. 147 * @param y Scan line Y-axis coordinates. 148 * @param x2 Scan line right coordinate. 149 * @param c The color of the rendered scanline. 150 * @param colors Scan line corresponding color array. 151 */ 152 void BlendHLine(int32_t x1, int32_t y, int32_t x2, const Rgba8T& color, uint8_t cover); 153 154 /** 155 * @brief BlendSolidHSpan Renders a scan line of a solid line within a certain range of the Y axis. 156 * @param x scan line X-axis start coordinate. 157 * @param y scan line Y-axis start coordinate. 158 * @param len Scan line length. 159 * @param c The color of the rendered scanline. 160 * @param colors Scan line corresponding color array. 161 */ 162 void BlendSolidHSpan(int32_t x, int32_t y, int32_t len, const Rgba8T& color, const uint8_t* covers); 163 164 /** 165 * @brief CopyColorHSpan Copy colors within a certain Y-axis range 166 * @param x Scan line X-axis start coordinate 167 * @param y Scan line Y-axis start coordinate 168 * @param len Scan line length. 169 * @param colors Scan line corresponding color array. 170 */ 171 void CopyColorHSpan(int32_t x, int32_t y, int32_t len, const Rgba8T* colors); 172 173 /** 174 * @brief BlendColorHSpan Mix colors within a certain height. 175 * @param x Scan line X-axis start coordinate 176 * @param y Scan line Y-axis start coordinate 177 * @param len Scan line length. 178 * @param colors Scan line corresponding color array. 179 * @param covers Scan line corresponding coverage array. 180 * @param cover Coverage 181 */ 182 void BlendColorHSpan(int32_t x, int32_t y, int32_t len, const Rgba8T* colors, const uint8_t* covers, 183 uint8_t cover = COVER_FULL); 184 185 /** 186 * @brief ColorHSpanHandler Handle ColorHSpan params. 187 * @param x Scan line X-axis start coordinate 188 * @param y Scan line Y-axis start coordinate 189 * @param len Scan line length. 190 * @param colors Scan line corresponding color array. 191 * @param covers Scan line corresponding coverage array. 192 * @return Returns true if should run the follow programs. 193 */ 194 bool ColorHSpanHandler(int32_t& x, const int32_t& y, int32_t& len, const Rgba8T*& colors, 195 const uint8_t*& covers) const; 196 197 private: 198 RenderPixfmtRgbaBlend* pixfmtType_; 199 Rect32 clipBox_; 200 }; 201 } // namespace OHOS 202 #endif 203