xref: /aosp_15_r20/external/skia/src/utils/mac/SkCGBase.h (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
1 /*
2  * Copyright 2020 Google Inc.
3  *
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  */
7 
8 #ifndef SkCGBase_DEFINED
9 #define SkCGBase_DEFINED
10 
11 #include "include/private/base/SkFeatures.h"
12 
13 #if defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS)
14 
15 #include "include/core/SkScalar.h"
16 
17 #ifdef SK_BUILD_FOR_MAC
18 #import <ApplicationServices/ApplicationServices.h>
19 #endif
20 
21 #ifdef SK_BUILD_FOR_IOS
22 #include <CoreGraphics/CoreGraphics.h>
23 #endif
24 
25 // Skia extensions for types in CGBase.h
26 
SkScalarToCGFloat(SkScalar scalar)27 static inline CGFloat SkScalarToCGFloat(SkScalar scalar) {
28     return CGFLOAT_IS_DOUBLE ? SkScalarToDouble(scalar) : scalar;
29 }
30 
SkScalarFromCGFloat(CGFloat cgFloat)31 static inline SkScalar SkScalarFromCGFloat(CGFloat cgFloat) {
32     return CGFLOAT_IS_DOUBLE ? SkDoubleToScalar(cgFloat) : cgFloat;
33 }
34 
SkFloatFromCGFloat(CGFloat cgFloat)35 static inline float SkFloatFromCGFloat(CGFloat cgFloat) {
36     return CGFLOAT_IS_DOUBLE ? static_cast<float>(cgFloat) : cgFloat;
37 }
38 
39 #endif
40 #endif //SkCGBase_DEFINED
41