Home | History | Annotate | Download | only in core
      1 
      2 /*
      3  * Copyright 2006 The Android Open Source Project
      4  *
      5  * Use of this source code is governed by a BSD-style license that can be
      6  * found in the LICENSE file.
      7  */
      8 
      9 
     10 #include "SkGraphics.h"
     11 
     12 #include "Sk64.h"
     13 #include "SkBlitter.h"
     14 #include "SkCanvas.h"
     15 #include "SkFloat.h"
     16 #include "SkGeometry.h"
     17 #include "SkMath.h"
     18 #include "SkMatrix.h"
     19 #include "SkPath.h"
     20 #include "SkPathEffect.h"
     21 #include "SkPixelRef.h"
     22 #include "SkRefCnt.h"
     23 #include "SkRTConf.h"
     24 #include "SkScalerContext.h"
     25 #include "SkShader.h"
     26 #include "SkStream.h"
     27 #include "SkTSearch.h"
     28 #include "SkTime.h"
     29 #include "SkUtils.h"
     30 #include "SkXfermode.h"
     31 
     32 void SkGraphics::GetVersion(int32_t* major, int32_t* minor, int32_t* patch) {
     33     if (major) {
     34         *major = SKIA_VERSION_MAJOR;
     35     }
     36     if (minor) {
     37         *minor = SKIA_VERSION_MINOR;
     38     }
     39     if (patch) {
     40         *patch = SKIA_VERSION_PATCH;
     41     }
     42 }
     43 
     44 #define typesizeline(type)  { #type , sizeof(type) }
     45 
     46 #ifdef BUILD_EMBOSS_TABLE
     47     extern void SkEmbossMask_BuildTable();
     48 #endif
     49 
     50 #ifdef BUILD_RADIALGRADIENT_TABLE
     51     extern void SkRadialGradient_BuildTable();
     52 #endif
     53 
     54 void SkGraphics::Init() {
     55 #ifdef SK_DEVELOPER
     56     skRTConfRegistry().possiblyDumpFile();
     57     skRTConfRegistry().validate();
     58     SkDebugf("Non-default runtime configuration options:\n");
     59     skRTConfRegistry().printNonDefault( );
     60 #endif
     61 
     62     SkFlattenable::InitializeFlattenables();
     63 #ifdef BUILD_EMBOSS_TABLE
     64     SkEmbossMask_BuildTable();
     65 #endif
     66 #ifdef BUILD_RADIALGRADIENT_TABLE
     67     SkRadialGradient_BuildTable();
     68 #endif
     69 
     70 #ifdef SK_DEBUGx
     71     int i;
     72 
     73     static const struct {
     74         const char* fTypeName;
     75         size_t      fSizeOf;
     76     } gTypeSize[] = {
     77         typesizeline(char),
     78         typesizeline(short),
     79         typesizeline(int),
     80         typesizeline(long),
     81         typesizeline(size_t),
     82         typesizeline(void*),
     83 
     84         typesizeline(S8CPU),
     85         typesizeline(U8CPU),
     86         typesizeline(S16CPU),
     87         typesizeline(U16CPU),
     88 
     89         typesizeline(SkPoint),
     90         typesizeline(SkRect),
     91         typesizeline(SkMatrix),
     92         typesizeline(SkPath),
     93         typesizeline(SkGlyph),
     94         typesizeline(SkRefCnt),
     95 
     96         typesizeline(SkPaint),
     97         typesizeline(SkCanvas),
     98         typesizeline(SkBlitter),
     99         typesizeline(SkShader),
    100         typesizeline(SkXfermode),
    101         typesizeline(SkPathEffect)
    102     };
    103 
    104 #ifdef SK_CPU_BENDIAN
    105     SkDebugf("SkGraphics: big-endian\n");
    106 #else
    107     SkDebugf("SkGraphics: little-endian\n");
    108 #endif
    109 
    110     {
    111         char    test = 0xFF;
    112         int     itest = test;   // promote to int, see if it sign-extended
    113         if (itest < 0)
    114             SkDebugf("SkGraphics: char is signed\n");
    115         else
    116             SkDebugf("SkGraphics: char is unsigned\n");
    117     }
    118     for (i = 0; i < (int)SK_ARRAY_COUNT(gTypeSize); i++) {
    119         SkDebugf("SkGraphics: sizeof(%s) = %d\n",
    120                  gTypeSize[i].fTypeName, gTypeSize[i].fSizeOf);
    121     }
    122     SkDebugf("SkGraphics: font cache limit %dK\n",
    123              GetFontCacheLimit() >> 10);
    124 
    125 #endif
    126 
    127 }
    128 
    129 void SkGraphics::Term() {
    130     PurgeFontCache();
    131     SkPaint::Term();
    132 }
    133 
    134 ///////////////////////////////////////////////////////////////////////////////
    135 
    136 static const char kFontCacheLimitStr[] = "font-cache-limit";
    137 static const size_t kFontCacheLimitLen = sizeof(kFontCacheLimitStr) - 1;
    138 
    139 static const struct {
    140     const char* fStr;
    141     size_t fLen;
    142     size_t (*fFunc)(size_t);
    143 } gFlags[] = {
    144     { kFontCacheLimitStr, kFontCacheLimitLen, SkGraphics::SetFontCacheLimit }
    145 };
    146 
    147 /* flags are of the form param; or param=value; */
    148 void SkGraphics::SetFlags(const char* flags) {
    149     if (!flags) {
    150         return;
    151     }
    152     const char* nextSemi;
    153     do {
    154         size_t len = strlen(flags);
    155         const char* paramEnd = flags + len;
    156         const char* nextEqual = strchr(flags, '=');
    157         if (nextEqual && paramEnd > nextEqual) {
    158             paramEnd = nextEqual;
    159         }
    160         nextSemi = strchr(flags, ';');
    161         if (nextSemi && paramEnd > nextSemi) {
    162             paramEnd = nextSemi;
    163         }
    164         size_t paramLen = paramEnd - flags;
    165         for (int i = 0; i < (int)SK_ARRAY_COUNT(gFlags); ++i) {
    166             if (paramLen != gFlags[i].fLen) {
    167                 continue;
    168             }
    169             if (strncmp(flags, gFlags[i].fStr, paramLen) == 0) {
    170                 size_t val = 0;
    171                 if (nextEqual) {
    172                     val = (size_t) atoi(nextEqual + 1);
    173                 }
    174                 (gFlags[i].fFunc)(val);
    175                 break;
    176             }
    177         }
    178         flags = nextSemi + 1;
    179     } while (nextSemi);
    180 }
    181