blob: d71a70e4a0586161a965a09c40e9b87fec54029b [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
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
reed@android.com8a1c16f2008-12-17 15:59:43 +00009
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"
reed@android.com8a1c16f2008-12-17 15:59:43 +000017#include "SkMath.h"
18#include "SkMatrix.h"
19#include "SkPath.h"
20#include "SkPathEffect.h"
caryclark@google.com9d0c6ec2011-12-20 20:26:56 +000021#include "SkPixelRef.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +000022#include "SkRandom.h"
23#include "SkRefCnt.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
reed@google.com77407ca2011-11-08 13:48:32 +000032void 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
reed@android.com8a1c16f2008-12-17 15:59:43 +000044#define typesizeline(type) { #type , sizeof(type) }
reed@android.com8a1c16f2008-12-17 15:59:43 +000045
reed@android.com8a1c16f2008-12-17 15:59:43 +000046#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
reed@android.com34245c72009-11-03 04:00:48 +000054void SkGraphics::Init() {
caryclark@google.comd26147a2011-12-15 14:16:43 +000055#if !SK_ALLOW_STATIC_GLOBAL_INITIALIZERS
56 SkFlattenable::InitializeFlattenables();
caryclark@google.comd26147a2011-12-15 14:16:43 +000057#endif
reed@android.com8a1c16f2008-12-17 15:59:43 +000058#ifdef BUILD_EMBOSS_TABLE
59 SkEmbossMask_BuildTable();
60#endif
61#ifdef BUILD_RADIALGRADIENT_TABLE
62 SkRadialGradient_BuildTable();
63#endif
64
reed@android.com5e5adfd2009-03-07 03:39:23 +000065#ifdef SK_DEBUGx
reed@android.com8a1c16f2008-12-17 15:59:43 +000066 int i;
67
68 static const struct {
69 const char* fTypeName;
70 size_t fSizeOf;
71 } gTypeSize[] = {
72 typesizeline(char),
73 typesizeline(short),
74 typesizeline(int),
75 typesizeline(long),
76 typesizeline(size_t),
77 typesizeline(void*),
78
79 typesizeline(S8CPU),
80 typesizeline(U8CPU),
81 typesizeline(S16CPU),
82 typesizeline(U16CPU),
83
84 typesizeline(SkPoint),
85 typesizeline(SkRect),
86 typesizeline(SkMatrix),
87 typesizeline(SkPath),
88 typesizeline(SkGlyph),
89 typesizeline(SkRefCnt),
90
91 typesizeline(SkPaint),
92 typesizeline(SkCanvas),
93 typesizeline(SkBlitter),
94 typesizeline(SkShader),
95 typesizeline(SkXfermode),
96 typesizeline(SkPathEffect)
97 };
98
99#ifdef SK_CPU_BENDIAN
100 SkDebugf("SkGraphics: big-endian\n");
101#else
102 SkDebugf("SkGraphics: little-endian\n");
103#endif
104
105 {
106 char test = 0xFF;
107 int itest = test; // promote to int, see if it sign-extended
108 if (itest < 0)
109 SkDebugf("SkGraphics: char is signed\n");
110 else
111 SkDebugf("SkGraphics: char is unsigned\n");
112 }
reed@android.com5e5adfd2009-03-07 03:39:23 +0000113 for (i = 0; i < (int)SK_ARRAY_COUNT(gTypeSize); i++) {
114 SkDebugf("SkGraphics: sizeof(%s) = %d\n",
115 gTypeSize[i].fTypeName, gTypeSize[i].fSizeOf);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000116 }
reed@google.com073c9072011-11-08 20:03:48 +0000117 SkDebugf("SkGraphics: font cache limit %dK\n",
118 GetFontCacheLimit() >> 10);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000119
120#endif
reed@android.com8a1c16f2008-12-17 15:59:43 +0000121}
122
reed@android.com8a1c16f2008-12-17 15:59:43 +0000123void SkGraphics::Term() {
caryclark@google.comf86ab842011-12-16 17:11:17 +0000124 PurgeFontCache();
reed@android.com8a1c16f2008-12-17 15:59:43 +0000125}
126
caryclark@google.com54c782c2011-11-21 20:42:14 +0000127///////////////////////////////////////////////////////////////////////////////
128
129static const char kFontCacheLimitStr[] = "font-cache-limit";
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000130static const size_t kFontCacheLimitLen = sizeof(kFontCacheLimitStr) - 1;
caryclark@google.com54c782c2011-11-21 20:42:14 +0000131
132static const struct {
133 const char* fStr;
134 size_t fLen;
135 size_t (*fFunc)(size_t);
136} gFlags[] = {
reed@google.com09837012012-04-23 15:04:44 +0000137 { kFontCacheLimitStr, kFontCacheLimitLen, SkGraphics::SetFontCacheLimit }
caryclark@google.com54c782c2011-11-21 20:42:14 +0000138};
139
140/* flags are of the form param; or param=value; */
141void SkGraphics::SetFlags(const char* flags) {
142 if (!flags) {
143 return;
144 }
145 const char* nextSemi;
146 do {
147 size_t len = strlen(flags);
148 const char* paramEnd = flags + len;
149 const char* nextEqual = strchr(flags, '=');
150 if (nextEqual && paramEnd > nextEqual) {
151 paramEnd = nextEqual;
152 }
153 nextSemi = strchr(flags, ';');
154 if (nextSemi && paramEnd > nextSemi) {
155 paramEnd = nextSemi;
156 }
157 size_t paramLen = paramEnd - flags;
158 for (int i = 0; i < (int)SK_ARRAY_COUNT(gFlags); ++i) {
159 if (paramLen != gFlags[i].fLen) {
160 continue;
161 }
162 if (strncmp(flags, gFlags[i].fStr, paramLen) == 0) {
163 size_t val = 0;
164 if (nextEqual) {
165 val = (size_t) atoi(nextEqual + 1);
166 }
167 (gFlags[i].fFunc)(val);
168 break;
169 }
170 }
171 flags = nextSemi + 1;
172 } while (nextSemi);
173}