blob: 5e8e549624b902bb4055327bde4a944afd5c0910 [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"
17#include "SkGlobals.h"
18#include "SkMath.h"
19#include "SkMatrix.h"
20#include "SkPath.h"
21#include "SkPathEffect.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() {
reed@android.com8a1c16f2008-12-17 15:59:43 +000055 SkGlobals::Init();
56
reed@android.com8a1c16f2008-12-17 15:59:43 +000057#ifdef BUILD_EMBOSS_TABLE
58 SkEmbossMask_BuildTable();
59#endif
60#ifdef BUILD_RADIALGRADIENT_TABLE
61 SkRadialGradient_BuildTable();
62#endif
63
reed@android.com5e5adfd2009-03-07 03:39:23 +000064#ifdef SK_DEBUGx
reed@android.com8a1c16f2008-12-17 15:59:43 +000065 int i;
66
67 static const struct {
68 const char* fTypeName;
69 size_t fSizeOf;
70 } gTypeSize[] = {
71 typesizeline(char),
72 typesizeline(short),
73 typesizeline(int),
74 typesizeline(long),
75 typesizeline(size_t),
76 typesizeline(void*),
77
78 typesizeline(S8CPU),
79 typesizeline(U8CPU),
80 typesizeline(S16CPU),
81 typesizeline(U16CPU),
82
83 typesizeline(SkPoint),
84 typesizeline(SkRect),
85 typesizeline(SkMatrix),
86 typesizeline(SkPath),
87 typesizeline(SkGlyph),
88 typesizeline(SkRefCnt),
89
90 typesizeline(SkPaint),
91 typesizeline(SkCanvas),
92 typesizeline(SkBlitter),
93 typesizeline(SkShader),
94 typesizeline(SkXfermode),
95 typesizeline(SkPathEffect)
96 };
97
98#ifdef SK_CPU_BENDIAN
99 SkDebugf("SkGraphics: big-endian\n");
100#else
101 SkDebugf("SkGraphics: little-endian\n");
102#endif
103
104 {
105 char test = 0xFF;
106 int itest = test; // promote to int, see if it sign-extended
107 if (itest < 0)
108 SkDebugf("SkGraphics: char is signed\n");
109 else
110 SkDebugf("SkGraphics: char is unsigned\n");
111 }
reed@android.com5e5adfd2009-03-07 03:39:23 +0000112 for (i = 0; i < (int)SK_ARRAY_COUNT(gTypeSize); i++) {
113 SkDebugf("SkGraphics: sizeof(%s) = %d\n",
114 gTypeSize[i].fTypeName, gTypeSize[i].fSizeOf);
reed@android.com8a1c16f2008-12-17 15:59:43 +0000115 }
reed@android.com8a1c16f2008-12-17 15:59:43 +0000116
117#endif
reed@android.com8a1c16f2008-12-17 15:59:43 +0000118}
119
reed@google.com7db9fe62011-04-11 11:57:54 +0000120///////////////////////////////////////////////////////////////////////////////
reed@android.com8a1c16f2008-12-17 15:59:43 +0000121
122#include "SkGlyphCache.h"
reed@google.comd40da642011-10-20 13:18:37 +0000123#include "SkTypefaceCache.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +0000124
125void SkGraphics::Term() {
126 SkGraphics::SetFontCacheUsed(0);
reed@google.comd40da642011-10-20 13:18:37 +0000127 SkTypefaceCache::PurgeAll();
reed@android.com8a1c16f2008-12-17 15:59:43 +0000128 SkGlobals::Term();
129}
130
131size_t SkGraphics::GetFontCacheUsed() {
132 return SkGlyphCache::GetCacheUsed();
133}
134
135bool SkGraphics::SetFontCacheUsed(size_t usageInBytes) {
136 return SkGlyphCache::SetCacheUsed(usageInBytes);
137}
138
reed@google.com77407ca2011-11-08 13:48:32 +0000139#ifndef SK_DEFAULT_FONT_CACHE_LIMIT
140 #define SK_DEFAULT_FONT_CACHE_LIMIT (1024 * 1024)
141#endif
142
143#define SK_MIN_FONT_CACHE_LIMIT (256 * 1024)
144
145static size_t gFontCacheLimit = SK_DEFAULT_FONT_CACHE_LIMIT;
146
147size_t SkGraphics::GetFontCacheLimit() {
148 return gFontCacheLimit;
149}
150
151size_t SkGraphics::SetFontCacheLimit(size_t bytes) {
152 if (bytes < SK_MIN_FONT_CACHE_LIMIT) {
153 bytes = SK_MIN_FONT_CACHE_LIMIT;
reed@android.com9aa8b322010-04-13 13:22:54 +0000154 }
reed@google.com77407ca2011-11-08 13:48:32 +0000155 gFontCacheLimit = bytes;
156
157 // trigger a purge if the new size is smaller that our currently used amount
158 if (bytes < GetFontCacheUsed()) {
159 SetFontCacheUsed(bytes);
reed@android.com9aa8b322010-04-13 13:22:54 +0000160 }
161}
162