• 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 #ifndef RENDER_SERVICE_CLIENT_CORE_COMMON_RS_OBJ_GEOMETRY_H
16 #define RENDER_SERVICE_CLIENT_CORE_COMMON_RS_OBJ_GEOMETRY_H
17 
18 #include <cmath>
19 
20 #include "common/rs_common_def.h"
21 #include "common/rs_vector4.h"
22 namespace OHOS {
23 namespace Rosen {
24 class RSTransform {
25 public:
26     RSTransform() = default;
27     RSTransform(const RSTransform& other) = default;
28     ~RSTransform() = default;
29     float pivotX_ { 0.5f };
30     float pivotY_ { 0.5f };
31     float pivotZ_ { 0.0f };
32     float scaleX_ { 1.0f };
33     float scaleY_ { 1.0f };
34     float scaleZ_ { 1.0f };
35     float skewX_ {0.0f};
36     float skewY_ {0.0f};
37     float skewZ_ {0.0f};
38     float perspX_ {0.0f};
39     float perspY_ {0.0f};
40     float perspZ_ {0.0f};
41     float perspW_ {1.0f};
42     float rotation_ { 0.0f };
43     float rotationX_ { 0.0f };
44     float rotationY_ { 0.0f };
45     float translateX_ { 0.0f };
46     float translateY_ { 0.0f };
47     float translateZ_ { 0.0f };
48     float cameraDistance_ { 0.0f };
49     Quaternion quaternion_ { 0.0f, 0.0f, 0.0f, 1.0f };
50 };
51 
52 class RSObjGeometry {
53 public:
RSObjGeometry()54     RSObjGeometry() : x_(-INFINITY), y_(-INFINITY), z_(0.0f), width_(-INFINITY), height_(-INFINITY),
55         isZApplicableCamera3D_(true) {}
56 
57     virtual ~RSObjGeometry() = default;
58 
SetX(float x)59     void SetX(float x)
60     {
61         x_ = x;
62     }
SetY(float y)63     void SetY(float y)
64     {
65         y_ = y;
66     }
SetZ(float z)67     void SetZ(float z)
68     {
69         z_ = z;
70     }
SetWidth(float w)71     void SetWidth(float w)
72     {
73         width_ = w;
74     }
SetHeight(float h)75     void SetHeight(float h)
76     {
77         height_ = h;
78     }
SetPosition(float x,float y)79     void SetPosition(float x, float y)
80     {
81         SetX(x);
82         SetY(y);
83     }
SetSize(float w,float h)84     void SetSize(float w, float h)
85     {
86         SetWidth(w);
87         SetHeight(h);
88     }
SetRect(float x,float y,float w,float h)89     void SetRect(float x, float y, float w, float h)
90     {
91         SetPosition(x, y);
92         SetSize(w, h);
93     }
SetPivotX(float x)94     void SetPivotX(float x)
95     {
96         if (!trans_) {
97             trans_ = std::make_optional<RSTransform>();
98         }
99         trans_->pivotX_ = x;
100     }
SetPivotY(float y)101     void SetPivotY(float y)
102     {
103         if (!trans_) {
104             trans_ = std::make_optional<RSTransform>();
105         }
106         trans_->pivotY_ = y;
107     }
SetPivotZ(float z)108     void SetPivotZ(float z)
109     {
110         if (!trans_) {
111             trans_ = std::make_optional<RSTransform>();
112         }
113         trans_->pivotZ_ = z;
114     }
SetPivot(float x,float y)115     void SetPivot(float x, float y)
116     {
117         SetPivotX(x);
118         SetPivotY(y);
119     }
SetScaleX(float x)120     void SetScaleX(float x)
121     {
122         if (!trans_) {
123             trans_ = std::make_optional<RSTransform>();
124         }
125         trans_->scaleX_ = x;
126     }
SetScaleY(float y)127     void SetScaleY(float y)
128     {
129         if (!trans_) {
130             trans_ = std::make_optional<RSTransform>();
131         }
132         trans_->scaleY_ = y;
133     }
SetScaleZ(float z)134     void SetScaleZ(float z)
135     {
136         if (!trans_) {
137             trans_ = std::make_optional<RSTransform>();
138         }
139         trans_->scaleZ_ = z;
140     }
SetScale(float x,float y)141     void SetScale(float x, float y)
142     {
143         SetScaleX(x);
144         SetScaleY(y);
145     }
SetScale(float x,float y,float z)146     void SetScale(float x, float y, float z)
147     {
148         SetScaleX(x);
149         SetScaleY(y);
150         SetScaleZ(z);
151     }
SetSkewX(float x)152     void SetSkewX(float x)
153     {
154         if (!trans_) {
155             trans_ = std::make_optional<RSTransform>();
156         }
157         trans_->skewX_ = x;
158     }
SetSkewY(float y)159     void SetSkewY(float y)
160     {
161         if (!trans_) {
162             trans_ = std::make_optional<RSTransform>();
163         }
164         trans_->skewY_ = y;
165     }
SetSkewZ(float z)166     void SetSkewZ(float z)
167     {
168         if (!trans_) {
169             trans_ = std::make_optional<RSTransform>();
170         }
171         trans_->skewZ_ = z;
172     }
SetSkew(float x,float y)173     void SetSkew(float x, float y)
174     {
175         SetSkewX(x);
176         SetSkewY(y);
177     }
SetSkew(float x,float y,float z)178     void SetSkew(float x, float y, float z)
179     {
180         SetSkewX(x);
181         SetSkewY(y);
182         SetSkewZ(z);
183     }
SetPerspX(float x)184     void SetPerspX(float x)
185     {
186         if (!trans_) {
187             trans_ = std::make_optional<RSTransform>();
188         }
189         trans_->perspX_ = x;
190     }
SetPerspY(float y)191     void SetPerspY(float y)
192     {
193         if (!trans_) {
194             trans_ = std::make_optional<RSTransform>();
195         }
196         trans_->perspY_ = y;
197     }
SetPerspZ(float z)198     void SetPerspZ(float z)
199     {
200         if (!trans_) {
201             trans_ = std::make_optional<RSTransform>();
202         }
203         trans_->perspZ_ = z;
204     }
SetPerspW(float w)205     void SetPerspW(float w)
206     {
207         if (!trans_) {
208             trans_ = std::make_optional<RSTransform>();
209         }
210         trans_->perspW_ = w;
211     }
SetPersp(float x,float y)212     void SetPersp(float x, float y)
213     {
214         SetPerspX(x);
215         SetPerspY(y);
216     }
SetPersp(float x,float y,float z,float w)217     void SetPersp(float x, float y, float z, float w)
218     {
219         SetPerspX(x);
220         SetPerspY(y);
221         SetPerspZ(z);
222         SetPerspW(w);
223     }
SetRotation(float rotation)224     void SetRotation(float rotation)
225     {
226         if (!trans_) {
227             trans_ = std::make_optional<RSTransform>();
228         }
229         trans_->rotation_ = rotation;
230     }
SetRotationX(float rotationX)231     void SetRotationX(float rotationX)
232     {
233         if (!trans_) {
234             trans_ = std::make_optional<RSTransform>();
235         }
236         trans_->rotationX_ = rotationX;
237     }
SetRotationY(float rotationY)238     void SetRotationY(float rotationY)
239     {
240         if (!trans_) {
241             trans_ = std::make_optional<RSTransform>();
242         }
243         trans_->rotationY_ = rotationY;
244     }
SetTranslateX(float translateX)245     void SetTranslateX(float translateX)
246     {
247         if (!trans_) {
248             trans_ = std::make_optional<RSTransform>();
249         }
250         trans_->translateX_ = translateX;
251     }
SetTranslateY(float translateY)252     void SetTranslateY(float translateY)
253     {
254         if (!trans_) {
255             trans_ = std::make_optional<RSTransform>();
256         }
257         trans_->translateY_ = translateY;
258     }
SetTranslateZ(float translateZ)259     void SetTranslateZ(float translateZ)
260     {
261         if (!trans_) {
262             trans_ = std::make_optional<RSTransform>();
263         }
264         if (!ROSEN_EQ(trans_->translateZ_, translateZ)) {
265             trans_->translateZ_ = translateZ;
266         }
267     }
SetCameraDistance(float cameraDistance)268     void SetCameraDistance(float cameraDistance)
269     {
270         if (!trans_) {
271             trans_ = std::make_optional<RSTransform>();
272         }
273         trans_->cameraDistance_ = cameraDistance;
274     }
SetQuaternion(const Quaternion & quaternion)275     void SetQuaternion(const Quaternion& quaternion)
276     {
277         if (!trans_) {
278             trans_ = std::make_optional<RSTransform>();
279         }
280         trans_->quaternion_ = quaternion;
281     }
SetZApplicableCamera3D(bool isApplicable)282     void SetZApplicableCamera3D(bool isApplicable)
283     {
284         isZApplicableCamera3D_ = isApplicable;
285     }
286 
GetX()287     float GetX() const
288     {
289         return x_;
290     }
GetWidth()291     float GetWidth() const
292     {
293         return width_;
294     }
GetY()295     float GetY() const
296     {
297         return y_;
298     }
GetHeight()299     float GetHeight() const
300     {
301         return height_;
302     }
GetZ()303     float GetZ() const
304     {
305         return z_;
306     }
GetPivotX()307     float GetPivotX() const
308     {
309         return trans_ ? trans_->pivotX_ : 0.5f;
310     }
GetPivotY()311     float GetPivotY() const
312     {
313         return trans_ ? trans_->pivotY_ : 0.5f;
314     }
GetPivotZ()315     float GetPivotZ() const
316     {
317         return trans_ ? trans_->pivotZ_ : 0.f;
318     }
GetScaleX()319     float GetScaleX() const
320     {
321         return trans_ ? trans_->scaleX_ : 1.f;
322     }
GetScaleY()323     float GetScaleY() const
324     {
325         return trans_ ? trans_->scaleY_ : 1.f;
326     }
GetScaleZ()327     float GetScaleZ() const
328     {
329         return trans_ ? trans_->scaleZ_ : 1.f;
330     }
GetSkewX()331     float GetSkewX() const
332     {
333         return trans_ ? trans_->skewX_ : 0.f;
334     }
GetSkewY()335     float GetSkewY() const
336     {
337         return trans_ ? trans_->skewY_ : 0.f;
338     }
GetSkewZ()339     float GetSkewZ() const
340     {
341         return trans_ ? trans_->skewZ_ : 0.f;
342     }
GetPerspX()343     float GetPerspX() const
344     {
345         return trans_ ? trans_->perspX_ : 0.f;
346     }
GetPerspY()347     float GetPerspY() const
348     {
349         return trans_ ? trans_->perspY_ : 0.f;
350     }
GetPerspZ()351     float GetPerspZ() const
352     {
353         return trans_ ? trans_->perspZ_ : 0.f;
354     }
GetPerspW()355     float GetPerspW() const
356     {
357         return trans_ ? trans_->perspW_ : 1.f;
358     }
GetRotation()359     float GetRotation() const
360     {
361         return trans_ ? trans_->rotation_ : 0.f;
362     }
GetRotationX()363     float GetRotationX() const
364     {
365         return trans_ ? trans_->rotationX_ : 0.f;
366     }
GetRotationY()367     float GetRotationY() const
368     {
369         return trans_ ? trans_->rotationY_ : 0.f;
370     }
GetTranslateX()371     float GetTranslateX() const
372     {
373         return trans_ ? trans_->translateX_ : 0.f;
374     }
GetTranslateY()375     float GetTranslateY() const
376     {
377         return trans_ ? trans_->translateY_ : 0.f;
378     }
GetTranslateZ()379     float GetTranslateZ() const
380     {
381         return trans_ ? trans_->translateZ_ : 0.f;
382     }
GetCameraDistance()383     float GetCameraDistance() const
384     {
385         return trans_ ? trans_->cameraDistance_ : 0.f;
386     }
GetQuaternion()387     Quaternion GetQuaternion() const
388     {
389         return trans_ ? trans_->quaternion_ : Quaternion();
390     }
IsEmpty()391     bool IsEmpty() const
392     {
393         return width_ <= 0 && height_ <= 0;
394     }
GetZApplicableCamera3D()395     bool GetZApplicableCamera3D() const
396     {
397         return isZApplicableCamera3D_;
398     }
Round()399     void Round()
400     {
401         x_ = std::floor(x_);
402         y_ = std::floor(y_);
403     }
404     RSObjGeometry& operator=(const RSObjGeometry& geo)
405     {
406         if (&geo != this) {
407             SetRect(geo.x_, geo.y_, geo.width_, geo.height_);
408             SetZ(geo.z_);
409             trans_ = geo.trans_;
410         }
411         return *this;
412     }
413 
414 protected:
415     float x_;
416     float y_;
417     float z_;
418     float width_;
419     float height_;
420     bool isZApplicableCamera3D_;
421     std::optional<RSTransform> trans_;
422 };
423 } // namespace Rosen
424 } // namespace OHOS
425 #endif // RENDER_SERVICE_CLIENT_CORE_COMMON_RS_OBJ_GEOMETRY_H
426