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_FDot6One         (64)
     25 #define SK_FDot6Half        (32)
     26 
     27 #ifdef SK_DEBUG
     28     inline SkFDot6 SkIntToFDot6(S16CPU x) {
     29         SkASSERT(SkToS16(x) == x);
     30         return x << 6;
     31     }
     32 #else
     33     #define SkIntToFDot6(x) ((x) << 6)
     34 #endif
     35 
     36 #define SkFDot6Floor(x)     ((x) >> 6)
     37 #define SkFDot6Ceil(x)      (((x) + 63) >> 6)
     38 #define SkFDot6Round(x)     (((x) + 32) >> 6)
     39 
     40 #define SkFixedToFDot6(x)   ((x) >> 10)
     41 
     42 inline SkFixed SkFDot6ToFixed(SkFDot6 x) {
     43     SkASSERT((x << 10 >> 10) == x);
     44 
     45     return x << 10;
     46 }
     47 
     48 #ifdef SK_SCALAR_IS_FLOAT
     49     #define SkScalarToFDot6(x)  (SkFDot6)((x) * 64)
     50 #else
     51     #define SkScalarToFDot6(x)  ((x) >> 10)
     52 #endif
     53 
     54 inline SkFixed SkFDot6Div(SkFDot6 a, SkFDot6 b) {
     55     SkASSERT(b != 0);
     56 
     57     if (a == (int16_t)a) {
     58         return (a << 16) / b;
     59     } else {
     60         return SkFixedDiv(a, b);
     61     }
     62 }
     63 
     64 #endif
     65 
     66