blob: 53d031825159b72a4513fa566abcb67f5944717e [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 SkFlattenable::InitializeFlattenables();
reed@android.com8a1c16f2008-12-17 15:59:43 +000056#ifdef BUILD_EMBOSS_TABLE
57 SkEmbossMask_BuildTable();
58#endif
59#ifdef BUILD_RADIALGRADIENT_TABLE
60 SkRadialGradient_BuildTable();
61#endif
62
reed@android.com5e5adfd2009-03-07 03:39:23 +000063#ifdef SK_DEBUGx
reed@android.com8a1c16f2008-12-17 15:59:43 +000064 int i;
65
66 static const struct {
67 const char* fTypeName;
68 size_t fSizeOf;
69 } gTypeSize[] = {
70 typesizeline(char),
71 typesizeline(short),
72 typesizeline(int),
73 typesizeline(long),
74 typesizeline(size_t),
75 typesizeline(void*),
76
77 typesizeline(S8CPU),
78 typesizeline(U8CPU),
79 typesizeline(S16CPU),
80 typesizeline(U16CPU),
81
82 typesizeline(SkPoint),
83 typesizeline(SkRect),
84 typesizeline(SkMatrix),
85 typesizeline(SkPath),
86 typesizeline(SkGlyph),
87 typesizeline(SkRefCnt),
88
89 typesizeline(SkPaint),
90 typesizeline(SkCanvas),
91 typesizeline(SkBlitter),
92 typesizeline(SkShader),
93 typesizeline(SkXfermode),
94 typesizeline(SkPathEffect)
95 };
96
97#ifdef SK_CPU_BENDIAN
98 SkDebugf("SkGraphics: big-endian\n");
99#else
100 SkDebugf("SkGraphics: little-endian\n");
101#endif
102
103 {
104 char test = 0xFF;
105 int itest = test; // promote to int, see if it sign-extended
106 if (itest < 0)
107 SkDebugf("SkGraphics: char is signed\n");
108 else
109 SkDebugf("SkGraphics: char is unsigned\n");
110 }
reed@android.com5e5adfd2009-03-07 03:39:23 +0000111 for (i = 0; i < (int)SK_ARRAY_COUNT(gTypeSize); i++) {
112 SkDebugf("SkGraphics: sizeof(%s) = %d\n",
113 gTypeSize[i].fTypeName, gTypeSize[i].fSizeOf);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000114 }
reed@google.com073c9072011-11-08 20:03:48 +0000115 SkDebugf("SkGraphics: font cache limit %dK\n",
116 GetFontCacheLimit() >> 10);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000117
118#endif
reed@android.com8a1c16f2008-12-17 15:59:43 +0000119}
120
reed@android.com8a1c16f2008-12-17 15:59:43 +0000121void SkGraphics::Term() {
caryclark@google.comf86ab842011-12-16 17:11:17 +0000122 PurgeFontCache();
bungeman@google.comb24b4fa2012-09-04 13:49:59 +0000123 SkPaint::Term();
reed@android.com8a1c16f2008-12-17 15:59:43 +0000124}
125
caryclark@google.com54c782c2011-11-21 20:42:14 +0000126///////////////////////////////////////////////////////////////////////////////
127
128static const char kFontCacheLimitStr[] = "font-cache-limit";
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000129static const size_t kFontCacheLimitLen = sizeof(kFontCacheLimitStr) - 1;
caryclark@google.com54c782c2011-11-21 20:42:14 +0000130
131static const struct {
132 const char* fStr;
133 size_t fLen;
134 size_t (*fFunc)(size_t);
135} gFlags[] = {
reed@google.com09837012012-04-23 15:04:44 +0000136 { kFontCacheLimitStr, kFontCacheLimitLen, SkGraphics::SetFontCacheLimit }
caryclark@google.com54c782c2011-11-21 20:42:14 +0000137};
138
139/* flags are of the form param; or param=value; */
140void SkGraphics::SetFlags(const char* flags) {
141 if (!flags) {
142 return;
143 }
144 const char* nextSemi;
145 do {
146 size_t len = strlen(flags);
147 const char* paramEnd = flags + len;
148 const char* nextEqual = strchr(flags, '=');
149 if (nextEqual && paramEnd > nextEqual) {
150 paramEnd = nextEqual;
151 }
152 nextSemi = strchr(flags, ';');
153 if (nextSemi && paramEnd > nextSemi) {
154 paramEnd = nextSemi;
155 }
156 size_t paramLen = paramEnd - flags;
157 for (int i = 0; i < (int)SK_ARRAY_COUNT(gFlags); ++i) {
158 if (paramLen != gFlags[i].fLen) {
159 continue;
160 }
161 if (strncmp(flags, gFlags[i].fStr, paramLen) == 0) {
162 size_t val = 0;
163 if (nextEqual) {
164 val = (size_t) atoi(nextEqual + 1);
165 }
166 (gFlags[i].fFunc)(val);
167 break;
168 }
169 }
170 flags = nextSemi + 1;
171 } while (nextSemi);
172}