Home | History | Annotate | Download | only in core
      1 /*
      2  * Copyright (C) 2006 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 #ifndef SkFDot6_DEFINED
     18 #define SkFDot6_DEFINED
     19 
     20 #include "SkMath.h"
     21 
     22 typedef int32_t SkFDot6;
     23 
     24 #define SK_FDot61           (64)
     25 #define SK_FDot6Half        (32)
     26 
     27 #ifdef SK_DEBUG
     28     inline SkFDot6 SkIntToFDot6(S16CPU x)
     29     {
     30         SkASSERT(SkToS16(x) == x);
     31         return x << 6;
     32     }
     33 #else
     34     #define SkIntToFDot6(x) ((x) << 6)
     35 #endif
     36 
     37 #define SkFDot6Floor(x)     ((x) >> 6)
     38 #define SkFDot6Ceil(x)      (((x) + 63) >> 6)
     39 #define SkFDot6Round(x)     (((x) + 32) >> 6)
     40 
     41 #define SkFixedToFDot6(x)   ((x) >> 10)
     42 
     43 inline SkFixed SkFDot6ToFixed(SkFDot6 x)
     44 {
     45     SkASSERT((x << 10 >> 10) == x);
     46 
     47     return x << 10;
     48 }
     49 
     50 #ifdef SK_SCALAR_IS_FLOAT
     51     #define SkScalarToFDot6(x)  (SkFDot6)((x) * 64)
     52 #else
     53     #define SkScalarToFDot6(x)  ((x) >> 10)
     54 #endif
     55 
     56 inline SkFixed SkFDot6Div(SkFDot6 a, SkFDot6 b)
     57 {
     58     SkASSERT(b != 0);
     59 
     60     if (a == (int16_t)a)
     61         return (a << 16) / b;
     62     else
     63         return SkFixedDiv(a, b);
     64 }
     65 
     66 #endif
     67 
     68