• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "cpudraw.h"
17 
18 #include <scoped_bytrace.h>
19 
Contain(int32_t x2,int32_t y2)20 bool CpudrawRect::Contain(int32_t x2, int32_t y2)
21 {
22     return x <= x2 && x2 <= x + w && y <= y2 && y2 <= y + h;
23 }
24 
Cpudraw(uint32_t * vaddr,int32_t width,int32_t height)25 Cpudraw::Cpudraw(uint32_t *vaddr, int32_t width, int32_t height)
26     : addr(vaddr), width(width), height(height)
27 {
28 }
29 
SetColor(const uint32_t & color)30 void Cpudraw::SetColor(const uint32_t &color)
31 {
32     this->color = color;
33 }
34 
SetBorder(const int32_t & border)35 void Cpudraw::SetBorder(const int32_t &border)
36 {
37     this->border = border;
38 }
39 
DrawBorder(const struct CpudrawRect & rect)40 void Cpudraw::DrawBorder(const struct CpudrawRect &rect)
41 {
42     DrawBorder(rect.x, rect.y, rect.w, rect.h);
43 }
44 
DrawBorder(const int32_t & x,const int32_t & y,const int32_t & w,const int32_t & h)45 void Cpudraw::DrawBorder(const int32_t &x, const int32_t &y, const int32_t &w, const int32_t &h)
46 {
47     ScopedBytrace trace(__func__);
48     DrawRect(x, y, border, h);
49     DrawRect(x + w - border, y, border, h);
50     DrawRect(x, y, w, border);
51     DrawRect(x, y + h - border, w, border);
52 }
53 
DrawRect(const struct CpudrawRect & rect)54 void Cpudraw::DrawRect(const struct CpudrawRect &rect)
55 {
56     DrawRect(rect.x, rect.y, rect.w, rect.h);
57 }
58 
DrawRect(const int32_t & x,const int32_t & y,const int32_t & w,const int32_t & h)59 void Cpudraw::DrawRect(const int32_t &x, const int32_t &y, const int32_t &w, const int32_t &h)
60 {
61     ScopedBytrace trace(__func__);
62     for (int32_t j = Max(y, 0); j < Min(y + h, height); j++) {
63         for (int32_t i = Max(x, 0); i < Min(x + w, width); i++) {
64             addr[j * width + i] = color;
65         }
66     }
67 }
68 
Min(const int32_t & a,const int32_t & b)69 int32_t Cpudraw::Min(const int32_t &a, const int32_t &b)
70 {
71     return a < b ? a : b;
72 }
73 
Max(const int32_t & a,const int32_t & b)74 int32_t Cpudraw::Max(const int32_t &a, const int32_t &b)
75 {
76     return a > b ? a : b;
77 }
78