gfx/skia/trunk/src/core/SkGraphics.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/skia/trunk/src/core/SkGraphics.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,181 @@
     1.4 +
     1.5 +/*
     1.6 + * Copyright 2006 The Android Open Source Project
     1.7 + *
     1.8 + * Use of this source code is governed by a BSD-style license that can be
     1.9 + * found in the LICENSE file.
    1.10 + */
    1.11 +
    1.12 +
    1.13 +#include "SkGraphics.h"
    1.14 +
    1.15 +#include "SkBlitter.h"
    1.16 +#include "SkCanvas.h"
    1.17 +#include "SkFloat.h"
    1.18 +#include "SkGeometry.h"
    1.19 +#include "SkMath.h"
    1.20 +#include "SkMatrix.h"
    1.21 +#include "SkPath.h"
    1.22 +#include "SkPathEffect.h"
    1.23 +#include "SkPixelRef.h"
    1.24 +#include "SkRefCnt.h"
    1.25 +#include "SkRTConf.h"
    1.26 +#include "SkScalerContext.h"
    1.27 +#include "SkShader.h"
    1.28 +#include "SkStream.h"
    1.29 +#include "SkTSearch.h"
    1.30 +#include "SkTime.h"
    1.31 +#include "SkUtils.h"
    1.32 +#include "SkXfermode.h"
    1.33 +
    1.34 +void SkGraphics::GetVersion(int32_t* major, int32_t* minor, int32_t* patch) {
    1.35 +    if (major) {
    1.36 +        *major = SKIA_VERSION_MAJOR;
    1.37 +    }
    1.38 +    if (minor) {
    1.39 +        *minor = SKIA_VERSION_MINOR;
    1.40 +    }
    1.41 +    if (patch) {
    1.42 +        *patch = SKIA_VERSION_PATCH;
    1.43 +    }
    1.44 +}
    1.45 +
    1.46 +#define typesizeline(type)  { #type , sizeof(type) }
    1.47 +
    1.48 +#ifdef BUILD_EMBOSS_TABLE
    1.49 +    extern void SkEmbossMask_BuildTable();
    1.50 +#endif
    1.51 +
    1.52 +#ifdef BUILD_RADIALGRADIENT_TABLE
    1.53 +    extern void SkRadialGradient_BuildTable();
    1.54 +#endif
    1.55 +
    1.56 +void SkGraphics::Init() {
    1.57 +#ifdef SK_DEVELOPER
    1.58 +    skRTConfRegistry().possiblyDumpFile();
    1.59 +    skRTConfRegistry().validate();
    1.60 +    if (skRTConfRegistry().hasNonDefault()) {
    1.61 +        SkDebugf("Non-default runtime configuration options:\n");
    1.62 +        skRTConfRegistry().printNonDefault();
    1.63 +    }
    1.64 +#endif
    1.65 +
    1.66 +#ifdef BUILD_EMBOSS_TABLE
    1.67 +    SkEmbossMask_BuildTable();
    1.68 +#endif
    1.69 +#ifdef BUILD_RADIALGRADIENT_TABLE
    1.70 +    SkRadialGradient_BuildTable();
    1.71 +#endif
    1.72 +
    1.73 +#ifdef SK_DEBUGx
    1.74 +    int i;
    1.75 +
    1.76 +    static const struct {
    1.77 +        const char* fTypeName;
    1.78 +        size_t      fSizeOf;
    1.79 +    } gTypeSize[] = {
    1.80 +        typesizeline(char),
    1.81 +        typesizeline(short),
    1.82 +        typesizeline(int),
    1.83 +        typesizeline(long),
    1.84 +        typesizeline(size_t),
    1.85 +        typesizeline(void*),
    1.86 +
    1.87 +        typesizeline(S8CPU),
    1.88 +        typesizeline(U8CPU),
    1.89 +        typesizeline(S16CPU),
    1.90 +        typesizeline(U16CPU),
    1.91 +
    1.92 +        typesizeline(SkPoint),
    1.93 +        typesizeline(SkRect),
    1.94 +        typesizeline(SkMatrix),
    1.95 +        typesizeline(SkPath),
    1.96 +        typesizeline(SkGlyph),
    1.97 +        typesizeline(SkRefCnt),
    1.98 +
    1.99 +        typesizeline(SkPaint),
   1.100 +        typesizeline(SkCanvas),
   1.101 +        typesizeline(SkBlitter),
   1.102 +        typesizeline(SkShader),
   1.103 +        typesizeline(SkXfermode),
   1.104 +        typesizeline(SkPathEffect)
   1.105 +    };
   1.106 +
   1.107 +#ifdef SK_CPU_BENDIAN
   1.108 +    SkDebugf("SkGraphics: big-endian\n");
   1.109 +#else
   1.110 +    SkDebugf("SkGraphics: little-endian\n");
   1.111 +#endif
   1.112 +
   1.113 +    {
   1.114 +        char    test = 0xFF;
   1.115 +        int     itest = test;   // promote to int, see if it sign-extended
   1.116 +        if (itest < 0)
   1.117 +            SkDebugf("SkGraphics: char is signed\n");
   1.118 +        else
   1.119 +            SkDebugf("SkGraphics: char is unsigned\n");
   1.120 +    }
   1.121 +    for (i = 0; i < (int)SK_ARRAY_COUNT(gTypeSize); i++) {
   1.122 +        SkDebugf("SkGraphics: sizeof(%s) = %d\n",
   1.123 +                 gTypeSize[i].fTypeName, gTypeSize[i].fSizeOf);
   1.124 +    }
   1.125 +    SkDebugf("SkGraphics: font cache limit %dK\n",
   1.126 +             GetFontCacheLimit() >> 10);
   1.127 +
   1.128 +#endif
   1.129 +
   1.130 +}
   1.131 +
   1.132 +void SkGraphics::Term() {
   1.133 +    PurgeFontCache();
   1.134 +    SkPaint::Term();
   1.135 +    SkXfermode::Term();
   1.136 +}
   1.137 +
   1.138 +///////////////////////////////////////////////////////////////////////////////
   1.139 +
   1.140 +static const char kFontCacheLimitStr[] = "font-cache-limit";
   1.141 +static const size_t kFontCacheLimitLen = sizeof(kFontCacheLimitStr) - 1;
   1.142 +
   1.143 +static const struct {
   1.144 +    const char* fStr;
   1.145 +    size_t fLen;
   1.146 +    size_t (*fFunc)(size_t);
   1.147 +} gFlags[] = {
   1.148 +    { kFontCacheLimitStr, kFontCacheLimitLen, SkGraphics::SetFontCacheLimit }
   1.149 +};
   1.150 +
   1.151 +/* flags are of the form param; or param=value; */
   1.152 +void SkGraphics::SetFlags(const char* flags) {
   1.153 +    if (!flags) {
   1.154 +        return;
   1.155 +    }
   1.156 +    const char* nextSemi;
   1.157 +    do {
   1.158 +        size_t len = strlen(flags);
   1.159 +        const char* paramEnd = flags + len;
   1.160 +        const char* nextEqual = strchr(flags, '=');
   1.161 +        if (nextEqual && paramEnd > nextEqual) {
   1.162 +            paramEnd = nextEqual;
   1.163 +        }
   1.164 +        nextSemi = strchr(flags, ';');
   1.165 +        if (nextSemi && paramEnd > nextSemi) {
   1.166 +            paramEnd = nextSemi;
   1.167 +        }
   1.168 +        size_t paramLen = paramEnd - flags;
   1.169 +        for (int i = 0; i < (int)SK_ARRAY_COUNT(gFlags); ++i) {
   1.170 +            if (paramLen != gFlags[i].fLen) {
   1.171 +                continue;
   1.172 +            }
   1.173 +            if (strncmp(flags, gFlags[i].fStr, paramLen) == 0) {
   1.174 +                size_t val = 0;
   1.175 +                if (nextEqual) {
   1.176 +                    val = (size_t) atoi(nextEqual + 1);
   1.177 +                }
   1.178 +                (gFlags[i].fFunc)(val);
   1.179 +                break;
   1.180 +            }
   1.181 +        }
   1.182 +        flags = nextSemi + 1;
   1.183 +    } while (nextSemi);
   1.184 +}

mercurial