blob: 0d7cd9cb9a72c16c1c9f5f32885f977e1c16e0ca [file] [log] [blame]
Romain Guy01d58e42011-01-19 21:54:02 -08001/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#define LOG_TAG "OpenGLRenderer"
18
19#include "ShapeCache.h"
20
21namespace android {
22namespace uirenderer {
23
Romain Guyff26a0c2011-01-20 11:35:46 -080024///////////////////////////////////////////////////////////////////////////////
25// Rounded rects
26///////////////////////////////////////////////////////////////////////////////
27
28RoundRectShapeCache::RoundRectShapeCache(): ShapeCache<RoundRectShapeCacheEntry>(
29 "round rect", PROPERTY_SHAPE_CACHE_SIZE, DEFAULT_SHAPE_CACHE_SIZE) {
Romain Guy01d58e42011-01-19 21:54:02 -080030}
31
32PathTexture* RoundRectShapeCache::getRoundRect(float width, float height,
33 float rx, float ry, SkPaint* paint) {
34 RoundRectShapeCacheEntry entry(width, height, rx, ry, paint);
35 PathTexture* texture = get(entry);
36
37 if (!texture) {
38 SkPath path;
39 SkRect r;
40 r.set(0.0f, 0.0f, width, height);
41 path.addRoundRect(r, rx, ry, SkPath::kCW_Direction);
42
43 texture = addTexture(entry, &path, paint);
44 }
45
46 return texture;
47}
48
Romain Guyff26a0c2011-01-20 11:35:46 -080049///////////////////////////////////////////////////////////////////////////////
50// Circles
51///////////////////////////////////////////////////////////////////////////////
52
53CircleShapeCache::CircleShapeCache(): ShapeCache<CircleShapeCacheEntry>(
54 "circle", PROPERTY_SHAPE_CACHE_SIZE, DEFAULT_SHAPE_CACHE_SIZE) {
Romain Guy01d58e42011-01-19 21:54:02 -080055}
56
57PathTexture* CircleShapeCache::getCircle(float radius, SkPaint* paint) {
58 CircleShapeCacheEntry entry(radius, paint);
59 PathTexture* texture = get(entry);
60
61 if (!texture) {
62 SkPath path;
63 path.addCircle(radius, radius, radius, SkPath::kCW_Direction);
64
65 texture = addTexture(entry, &path, paint);
66 }
67
68 return texture;
69}
70
Romain Guyc1cd9ba32011-01-23 14:18:41 -080071///////////////////////////////////////////////////////////////////////////////
72// Ovals
73///////////////////////////////////////////////////////////////////////////////
74
75OvalShapeCache::OvalShapeCache(): ShapeCache<OvalShapeCacheEntry>(
76 "oval", PROPERTY_SHAPE_CACHE_SIZE, DEFAULT_SHAPE_CACHE_SIZE) {
77}
78
79PathTexture* OvalShapeCache::getOval(float width, float height, SkPaint* paint) {
80 OvalShapeCacheEntry entry(width, height, paint);
81 PathTexture* texture = get(entry);
82
83 if (!texture) {
84 SkPath path;
85 SkRect r;
86 r.set(0.0f, 0.0f, width, height);
87 path.addOval(r, SkPath::kCW_Direction);
88
89 texture = addTexture(entry, &path, paint);
90 }
91
92 return texture;
93}
94
95///////////////////////////////////////////////////////////////////////////////
96// Rects
97///////////////////////////////////////////////////////////////////////////////
98
99RectShapeCache::RectShapeCache(): ShapeCache<RectShapeCacheEntry>(
100 "rect", PROPERTY_SHAPE_CACHE_SIZE, DEFAULT_SHAPE_CACHE_SIZE) {
101}
102
103PathTexture* RectShapeCache::getRect(float width, float height, SkPaint* paint) {
104 RectShapeCacheEntry entry(width, height, paint);
105 PathTexture* texture = get(entry);
106
107 if (!texture) {
108 SkPath path;
109 path.addRect(0.0f, 0.0f, width, height, SkPath::kCW_Direction);
110
111 texture = addTexture(entry, &path, paint);
112 }
113
114 return texture;
115}
116
Romain Guy8b2f5262011-01-23 16:15:02 -0800117///////////////////////////////////////////////////////////////////////////////
118// Arcs
119///////////////////////////////////////////////////////////////////////////////
120
121ArcShapeCache::ArcShapeCache(): ShapeCache<ArcShapeCacheEntry>(
122 "arc", PROPERTY_SHAPE_CACHE_SIZE, DEFAULT_SHAPE_CACHE_SIZE) {
123}
124
125PathTexture* ArcShapeCache::getArc(float width, float height,
126 float startAngle, float sweepAngle, bool useCenter, SkPaint* paint) {
127 ArcShapeCacheEntry entry(width, height, startAngle, sweepAngle, useCenter, paint);
128 PathTexture* texture = get(entry);
129
130 if (!texture) {
131 SkPath path;
132 SkRect r;
133 r.set(0.0f, 0.0f, width, height);
134 if (useCenter) {
135 path.moveTo(r.centerX(), r.centerY());
136 }
137 path.arcTo(r, startAngle, sweepAngle, !useCenter);
138 if (useCenter) {
139 path.close();
140 }
141
142 texture = addTexture(entry, &path, paint);
143 }
144
145 return texture;
146}
147
Romain Guy01d58e42011-01-19 21:54:02 -0800148}; // namespace uirenderer
149}; // namespace android