blob: 07c420721fa548c1f008118429cb4f480ad0303b [file] [log] [blame]
Romain Guy7fbcc042010-08-04 15:40:07 -07001/*
Romain Guyc46d07a2013-03-15 19:06:39 -07002 * Copyright (C) 2013 The Android Open Source Project
Romain Guy7fbcc042010-08-04 15:40:07 -07003 *
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"
Romain Guyc46d07a2013-03-15 19:06:39 -070018#define ATRACE_TAG ATRACE_TAG_VIEW
Romain Guy7fbcc042010-08-04 15:40:07 -070019
Romain Guyc46d07a2013-03-15 19:06:39 -070020#include <SkBitmap.h>
21#include <SkCanvas.h>
22#include <SkPaint.h>
23#include <SkPath.h>
24#include <SkRect.h>
Romain Guya2341a92010-09-08 18:04:33 -070025
Romain Guyc46d07a2013-03-15 19:06:39 -070026#include <utils/JenkinsHash.h>
27#include <utils/Trace.h>
Romain Guyca89e2a2013-03-08 17:44:20 -080028
29#include "Caches.h"
Romain Guy7fbcc042010-08-04 15:40:07 -070030#include "PathCache.h"
Romain Guyc46d07a2013-03-15 19:06:39 -070031
32#include "thread/Signal.h"
33#include "thread/Task.h"
34#include "thread/TaskProcessor.h"
Romain Guy7fbcc042010-08-04 15:40:07 -070035
36namespace android {
37namespace uirenderer {
38
Romain Guyca89e2a2013-03-08 17:44:20 -080039///////////////////////////////////////////////////////////////////////////////
Romain Guyc46d07a2013-03-15 19:06:39 -070040// Cache entries
41///////////////////////////////////////////////////////////////////////////////
42
43PathDescription::PathDescription():
44 type(kShapeNone),
45 join(SkPaint::kDefault_Join),
46 cap(SkPaint::kDefault_Cap),
47 style(SkPaint::kFill_Style),
48 miter(4.0f),
49 strokeWidth(1.0f),
50 pathEffect(NULL) {
51 memset(&shape, 0, sizeof(Shape));
52}
53
54PathDescription::PathDescription(ShapeType type, SkPaint* paint):
55 type(type),
56 join(paint->getStrokeJoin()),
57 cap(paint->getStrokeCap()),
58 style(paint->getStyle()),
59 miter(paint->getStrokeMiter()),
60 strokeWidth(paint->getStrokeWidth()),
61 pathEffect(paint->getPathEffect()) {
62 memset(&shape, 0, sizeof(Shape));
63}
64
65hash_t PathDescription::hash() const {
66 uint32_t hash = JenkinsHashMix(0, type);
67 hash = JenkinsHashMix(hash, join);
68 hash = JenkinsHashMix(hash, cap);
69 hash = JenkinsHashMix(hash, style);
70 hash = JenkinsHashMix(hash, android::hash_type(miter));
71 hash = JenkinsHashMix(hash, android::hash_type(strokeWidth));
72 hash = JenkinsHashMix(hash, android::hash_type(pathEffect));
73 hash = JenkinsHashMixBytes(hash, (uint8_t*) &shape, sizeof(Shape));
74 return JenkinsHashWhiten(hash);
75}
76
77int PathDescription::compare(const PathDescription& rhs) const {
78 return memcmp(this, &rhs, sizeof(PathDescription));
79}
80
81///////////////////////////////////////////////////////////////////////////////
82// Utilities
83///////////////////////////////////////////////////////////////////////////////
84
85bool PathCache::canDrawAsConvexPath(SkPath* path, SkPaint* paint) {
86 // NOTE: This should only be used after PathTessellator handles joins properly
87 return paint->getPathEffect() == NULL && path->getConvexity() == SkPath::kConvex_Convexity;
88}
89
90void PathCache::computePathBounds(const SkPath* path, const SkPaint* paint,
91 float& left, float& top, float& offset, uint32_t& width, uint32_t& height) {
92 const SkRect& bounds = path->getBounds();
93 PathCache::computeBounds(bounds, paint, left, top, offset, width, height);
94}
95
96void PathCache::computeBounds(const SkRect& bounds, const SkPaint* paint,
97 float& left, float& top, float& offset, uint32_t& width, uint32_t& height) {
98 const float pathWidth = fmax(bounds.width(), 1.0f);
99 const float pathHeight = fmax(bounds.height(), 1.0f);
100
101 left = bounds.fLeft;
102 top = bounds.fTop;
103
104 offset = (int) floorf(fmax(paint->getStrokeWidth(), 1.0f) * 1.5f + 0.5f);
105
106 width = uint32_t(pathWidth + offset * 2.0 + 0.5);
107 height = uint32_t(pathHeight + offset * 2.0 + 0.5);
108}
109
110static void initBitmap(SkBitmap& bitmap, uint32_t width, uint32_t height) {
111 bitmap.setConfig(SkBitmap::kA8_Config, width, height);
112 bitmap.allocPixels();
113 bitmap.eraseColor(0);
114}
115
116static void initPaint(SkPaint& paint) {
117 // Make sure the paint is opaque, color, alpha, filter, etc.
118 // will be applied later when compositing the alpha8 texture
119 paint.setColor(0xff000000);
120 paint.setAlpha(255);
121 paint.setColorFilter(NULL);
122 paint.setMaskFilter(NULL);
123 paint.setShader(NULL);
124 SkXfermode* mode = SkXfermode::Create(SkXfermode::kSrc_Mode);
125 SkSafeUnref(paint.setXfermode(mode));
126}
127
128static void drawPath(const SkPath *path, const SkPaint* paint, SkBitmap& bitmap,
129 float left, float top, float offset, uint32_t width, uint32_t height) {
130 initBitmap(bitmap, width, height);
131
132 SkPaint pathPaint(*paint);
133 initPaint(pathPaint);
134
135 SkCanvas canvas(bitmap);
136 canvas.translate(-left + offset, -top + offset);
137 canvas.drawPath(*path, pathPaint);
138}
139
140static PathTexture* createTexture(float left, float top, float offset,
141 uint32_t width, uint32_t height, uint32_t id) {
142 PathTexture* texture = new PathTexture();
143 texture->left = left;
144 texture->top = top;
145 texture->offset = offset;
146 texture->width = width;
147 texture->height = height;
148 texture->generation = id;
149 return texture;
150}
151
152///////////////////////////////////////////////////////////////////////////////
153// Cache constructor/destructor
154///////////////////////////////////////////////////////////////////////////////
155
156PathCache::PathCache():
157 mCache(LruCache<PathDescription, PathTexture*>::kUnlimitedCapacity),
158 mSize(0), mMaxSize(MB(DEFAULT_PATH_CACHE_SIZE)) {
159 char property[PROPERTY_VALUE_MAX];
160 if (property_get(PROPERTY_PATH_CACHE_SIZE, property, NULL) > 0) {
161 INIT_LOGD(" Setting %s cache size to %sMB", name, property);
162 setMaxSize(MB(atof(property)));
163 } else {
164 INIT_LOGD(" Using default %s cache size of %.2fMB", name, DEFAULT_PATH_CACHE_SIZE);
165 }
166 init();
167}
168
169PathCache::~PathCache() {
170 mCache.clear();
171}
172
173void PathCache::init() {
174 mCache.setOnEntryRemovedListener(this);
175
176 GLint maxTextureSize;
177 glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxTextureSize);
178 mMaxTextureSize = maxTextureSize;
179
180 mDebugEnabled = readDebugLevel() & kDebugCaches;
181}
182
183///////////////////////////////////////////////////////////////////////////////
184// Size management
185///////////////////////////////////////////////////////////////////////////////
186
187uint32_t PathCache::getSize() {
188 return mSize;
189}
190
191uint32_t PathCache::getMaxSize() {
192 return mMaxSize;
193}
194
195void PathCache::setMaxSize(uint32_t maxSize) {
196 mMaxSize = maxSize;
197 while (mSize > mMaxSize) {
198 mCache.removeOldest();
199 }
200}
201
202///////////////////////////////////////////////////////////////////////////////
203// Callbacks
204///////////////////////////////////////////////////////////////////////////////
205
206void PathCache::operator()(PathDescription& entry, PathTexture*& texture) {
207 removeTexture(texture);
208}
209
210///////////////////////////////////////////////////////////////////////////////
211// Caching
212///////////////////////////////////////////////////////////////////////////////
213
214void PathCache::removeTexture(PathTexture* texture) {
215 if (texture) {
216 const uint32_t size = texture->width * texture->height;
217 mSize -= size;
218
219 PATH_LOGD("PathCache::delete name, size, mSize = %d, %d, %d",
220 texture->id, size, mSize);
221 if (mDebugEnabled) {
222 ALOGD("Shape deleted, size = %d", size);
223 }
224
225 if (texture->id) {
226 glDeleteTextures(1, &texture->id);
227 }
228 delete texture;
229 }
230}
231
232void PathCache::purgeCache(uint32_t width, uint32_t height) {
233 const uint32_t size = width * height;
234 // Don't even try to cache a bitmap that's bigger than the cache
235 if (size < mMaxSize) {
236 while (mSize + size > mMaxSize) {
237 mCache.removeOldest();
238 }
239 }
240}
241
242void PathCache::trim() {
243 while (mSize > mMaxSize) {
244 mCache.removeOldest();
245 }
246}
247
248PathTexture* PathCache::addTexture(const PathDescription& entry, const SkPath *path,
249 const SkPaint* paint) {
250 ATRACE_CALL();
251
252 float left, top, offset;
253 uint32_t width, height;
254 computePathBounds(path, paint, left, top, offset, width, height);
255
256 if (!checkTextureSize(width, height)) return NULL;
257
258 purgeCache(width, height);
259
260 SkBitmap bitmap;
261 drawPath(path, paint, bitmap, left, top, offset, width, height);
262
263 PathTexture* texture = createTexture(left, top, offset, width, height,
264 path->getGenerationID());
265 addTexture(entry, &bitmap, texture);
266
267 return texture;
268}
269
270void PathCache::addTexture(const PathDescription& entry, SkBitmap* bitmap, PathTexture* texture) {
271 generateTexture(*bitmap, texture);
272
273 uint32_t size = texture->width * texture->height;
274 if (size < mMaxSize) {
275 mSize += size;
276 PATH_LOGD("PathCache::get/create: name, size, mSize = %d, %d, %d",
277 texture->id, size, mSize);
278 if (mDebugEnabled) {
279 ALOGD("Shape created, size = %d", size);
280 }
281 mCache.put(entry, texture);
282 } else {
283 texture->cleanup = true;
284 }
285}
286
287void PathCache::clear() {
288 mCache.clear();
289}
290
291void PathCache::generateTexture(SkBitmap& bitmap, Texture* texture) {
292 SkAutoLockPixels alp(bitmap);
293 if (!bitmap.readyToDraw()) {
294 ALOGE("Cannot generate texture from bitmap");
295 return;
296 }
297
298 glGenTextures(1, &texture->id);
299
300 glBindTexture(GL_TEXTURE_2D, texture->id);
301 // Textures are Alpha8
302 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
303
304 texture->blend = true;
305 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, texture->width, texture->height, 0,
306 GL_ALPHA, GL_UNSIGNED_BYTE, bitmap.getPixels());
307
308 texture->setFilter(GL_LINEAR);
309 texture->setWrap(GL_CLAMP_TO_EDGE);
310}
311
312///////////////////////////////////////////////////////////////////////////////
Romain Guyca89e2a2013-03-08 17:44:20 -0800313// Path precaching
314///////////////////////////////////////////////////////////////////////////////
Romain Guyfdd6fc12012-04-27 11:47:13 -0700315
Romain Guy5dc7fa72013-03-11 20:48:31 -0700316PathCache::PathProcessor::PathProcessor(Caches& caches):
317 TaskProcessor<SkBitmap*>(&caches.tasks), mMaxTextureSize(caches.maxTextureSize) {
Romain Guyfdd6fc12012-04-27 11:47:13 -0700318}
Romain Guy33f6beb2012-02-16 19:24:51 -0800319
Romain Guy5dc7fa72013-03-11 20:48:31 -0700320void PathCache::PathProcessor::onProcess(const sp<Task<SkBitmap*> >& task) {
321 sp<PathTask> t = static_cast<PathTask* >(task.get());
322 ATRACE_NAME("pathPrecache");
323
324 float left, top, offset;
325 uint32_t width, height;
326 PathCache::computePathBounds(t->path, t->paint, left, top, offset, width, height);
327
328 PathTexture* texture = t->texture;
329 texture->left = left;
330 texture->top = top;
331 texture->offset = offset;
332 texture->width = width;
333 texture->height = height;
334
335 if (width <= mMaxTextureSize && height <= mMaxTextureSize) {
336 SkBitmap* bitmap = new SkBitmap();
Romain Guyc46d07a2013-03-15 19:06:39 -0700337 drawPath(t->path, t->paint, *bitmap, left, top, offset, width, height);
Romain Guy5dc7fa72013-03-11 20:48:31 -0700338 t->setResult(bitmap);
339 } else {
Romain Guy0f809f32013-03-13 14:31:46 -0700340 texture->width = 0;
341 texture->height = 0;
Romain Guy5dc7fa72013-03-11 20:48:31 -0700342 t->setResult(NULL);
Romain Guyca89e2a2013-03-08 17:44:20 -0800343 }
Romain Guy33f6beb2012-02-16 19:24:51 -0800344}
345
Romain Guy7fbcc042010-08-04 15:40:07 -0700346///////////////////////////////////////////////////////////////////////////////
Romain Guyc46d07a2013-03-15 19:06:39 -0700347// Paths
Romain Guy7fbcc042010-08-04 15:40:07 -0700348///////////////////////////////////////////////////////////////////////////////
349
Romain Guyc5cbee72013-03-20 19:15:02 -0700350void PathCache::remove(const path_pair_t& pair) {
Romain Guyc46d07a2013-03-15 19:06:39 -0700351 Vector<PathDescription> pathsToRemove;
352 LruCache<PathDescription, PathTexture*>::Iterator i(mCache);
Romain Guy059e12c2012-11-28 17:35:51 -0800353
354 while (i.next()) {
Romain Guyc46d07a2013-03-15 19:06:39 -0700355 const PathDescription& key = i.key();
356 if (key.type == kShapePath &&
Romain Guyc5cbee72013-03-20 19:15:02 -0700357 (key.shape.path.mPath == pair.getFirst() ||
358 key.shape.path.mPath == pair.getSecond())) {
Romain Guy059e12c2012-11-28 17:35:51 -0800359 pathsToRemove.push(key);
Romain Guya2341a92010-09-08 18:04:33 -0700360 }
361 }
Romain Guy9e108412010-11-09 14:35:20 -0800362
363 for (size_t i = 0; i < pathsToRemove.size(); i++) {
Romain Guy059e12c2012-11-28 17:35:51 -0800364 mCache.remove(pathsToRemove.itemAt(i));
Romain Guy9e108412010-11-09 14:35:20 -0800365 }
Romain Guyfe48f652010-11-11 15:36:56 -0800366}
367
368void PathCache::removeDeferred(SkPath* path) {
Romain Guyca89e2a2013-03-08 17:44:20 -0800369 Mutex::Autolock l(mLock);
Romain Guyc5cbee72013-03-20 19:15:02 -0700370 mGarbage.push(path_pair_t(path, const_cast<SkPath*>(path->getSourcePath())));
Romain Guyfe48f652010-11-11 15:36:56 -0800371}
372
373void PathCache::clearGarbage() {
Romain Guyca89e2a2013-03-08 17:44:20 -0800374 Mutex::Autolock l(mLock);
Romain Guyfe48f652010-11-11 15:36:56 -0800375 size_t count = mGarbage.size();
376 for (size_t i = 0; i < count; i++) {
377 remove(mGarbage.itemAt(i));
378 }
379 mGarbage.clear();
Romain Guya2341a92010-09-08 18:04:33 -0700380}
381
Romain Guyca89e2a2013-03-08 17:44:20 -0800382/**
383 * To properly handle path mutations at draw time we always make a copy
384 * of paths objects when recording display lists. The source path points
385 * to the path we originally copied the path from. This ensures we use
386 * the original path as a cache key the first time a path is inserted
387 * in the cache. The source path is also used to reclaim garbage when a
388 * Dalvik Path object is collected.
389 */
390static SkPath* getSourcePath(SkPath* path) {
Romain Guy4bcb7462012-02-23 17:08:38 -0800391 const SkPath* sourcePath = path->getSourcePath();
392 if (sourcePath && sourcePath->getGenerationID() == path->getGenerationID()) {
Romain Guyca89e2a2013-03-08 17:44:20 -0800393 return const_cast<SkPath*>(sourcePath);
Romain Guy4bcb7462012-02-23 17:08:38 -0800394 }
Romain Guyca89e2a2013-03-08 17:44:20 -0800395 return path;
396}
397
398PathTexture* PathCache::get(SkPath* path, SkPaint* paint) {
399 path = getSourcePath(path);
Romain Guy4bcb7462012-02-23 17:08:38 -0800400
Romain Guyc46d07a2013-03-15 19:06:39 -0700401 PathDescription entry(kShapePath, paint);
402 entry.shape.path.mPath = path;
403
Romain Guy7fbcc042010-08-04 15:40:07 -0700404 PathTexture* texture = mCache.get(entry);
405
406 if (!texture) {
407 texture = addTexture(entry, path, paint);
Romain Guyca89e2a2013-03-08 17:44:20 -0800408 } else {
409 // A bitmap is attached to the texture, this means we need to
410 // upload it as a GL texture
Romain Guy5dc7fa72013-03-11 20:48:31 -0700411 const sp<Task<SkBitmap*> >& task = texture->task();
412 if (task != NULL) {
Romain Guyca89e2a2013-03-08 17:44:20 -0800413 // But we must first wait for the worker thread to be done
414 // producing the bitmap, so let's wait
Romain Guy5dc7fa72013-03-11 20:48:31 -0700415 SkBitmap* bitmap = task->getResult();
Romain Guyca89e2a2013-03-08 17:44:20 -0800416 if (bitmap) {
417 addTexture(entry, bitmap, texture);
Romain Guy5dc7fa72013-03-11 20:48:31 -0700418 texture->clearTask();
Romain Guyca89e2a2013-03-08 17:44:20 -0800419 } else {
Romain Guy0f809f32013-03-13 14:31:46 -0700420 ALOGW("Path too large to be rendered into a texture");
Romain Guy5dc7fa72013-03-11 20:48:31 -0700421 texture->clearTask();
Romain Guyca89e2a2013-03-08 17:44:20 -0800422 texture = NULL;
423 mCache.remove(entry);
424 }
425 } else if (path->getGenerationID() != texture->generation) {
426 mCache.remove(entry);
427 texture = addTexture(entry, path, paint);
428 }
Romain Guy7fbcc042010-08-04 15:40:07 -0700429 }
430
Romain Guy7fbcc042010-08-04 15:40:07 -0700431 return texture;
432}
433
Romain Guyca89e2a2013-03-08 17:44:20 -0800434void PathCache::precache(SkPath* path, SkPaint* paint) {
Romain Guy5dc7fa72013-03-11 20:48:31 -0700435 if (!Caches::getInstance().tasks.canRunTasks()) {
436 return;
437 }
438
Romain Guyca89e2a2013-03-08 17:44:20 -0800439 path = getSourcePath(path);
440
Romain Guyc46d07a2013-03-15 19:06:39 -0700441 PathDescription entry(kShapePath, paint);
442 entry.shape.path.mPath = path;
443
Romain Guyca89e2a2013-03-08 17:44:20 -0800444 PathTexture* texture = mCache.get(entry);
445
446 bool generate = false;
447 if (!texture) {
448 generate = true;
449 } else if (path->getGenerationID() != texture->generation) {
450 mCache.remove(entry);
451 generate = true;
452 }
453
454 if (generate) {
455 // It is important to specify the generation ID so we do not
456 // attempt to precache the same path several times
Romain Guy5dc7fa72013-03-11 20:48:31 -0700457 texture = createTexture(0.0f, 0.0f, 0.0f, 0, 0, path->getGenerationID());
458 sp<PathTask> task = new PathTask(path, paint, texture);
459 texture->setTask(task);
Romain Guyca89e2a2013-03-08 17:44:20 -0800460
461 // During the precaching phase we insert path texture objects into
462 // the cache that do not point to any GL texture. They are instead
463 // treated as a task for the precaching worker thread. This is why
464 // we do not check the cache limit when inserting these objects.
465 // The conversion into GL texture will happen in get(), when a client
466 // asks for a path texture. This is also when the cache limit will
467 // be enforced.
468 mCache.put(entry, texture);
Romain Guy5dc7fa72013-03-11 20:48:31 -0700469
470 if (mProcessor == NULL) {
471 mProcessor = new PathProcessor(Caches::getInstance());
472 }
473 mProcessor->add(task);
Romain Guyca89e2a2013-03-08 17:44:20 -0800474 }
475}
476
Romain Guyc46d07a2013-03-15 19:06:39 -0700477///////////////////////////////////////////////////////////////////////////////
478// Rounded rects
479///////////////////////////////////////////////////////////////////////////////
480
481PathTexture* PathCache::getRoundRect(float width, float height,
482 float rx, float ry, SkPaint* paint) {
483 PathDescription entry(kShapeRoundRect, paint);
484 entry.shape.roundRect.mWidth = width;
485 entry.shape.roundRect.mHeight = height;
486 entry.shape.roundRect.mRx = rx;
487 entry.shape.roundRect.mRy = ry;
488
489 PathTexture* texture = get(entry);
490
491 if (!texture) {
492 SkPath path;
493 SkRect r;
494 r.set(0.0f, 0.0f, width, height);
495 path.addRoundRect(r, rx, ry, SkPath::kCW_Direction);
496
497 texture = addTexture(entry, &path, paint);
498 }
499
500 return texture;
501}
502
503///////////////////////////////////////////////////////////////////////////////
504// Circles
505///////////////////////////////////////////////////////////////////////////////
506
507PathTexture* PathCache::getCircle(float radius, SkPaint* paint) {
508 PathDescription entry(kShapeCircle, paint);
509 entry.shape.circle.mRadius = radius;
510
511 PathTexture* texture = get(entry);
512
513 if (!texture) {
514 SkPath path;
515 path.addCircle(radius, radius, radius, SkPath::kCW_Direction);
516
517 texture = addTexture(entry, &path, paint);
518 }
519
520 return texture;
521}
522
523///////////////////////////////////////////////////////////////////////////////
524// Ovals
525///////////////////////////////////////////////////////////////////////////////
526
527PathTexture* PathCache::getOval(float width, float height, SkPaint* paint) {
528 PathDescription entry(kShapeOval, paint);
529 entry.shape.oval.mWidth = width;
530 entry.shape.oval.mHeight = height;
531
532 PathTexture* texture = get(entry);
533
534 if (!texture) {
535 SkPath path;
536 SkRect r;
537 r.set(0.0f, 0.0f, width, height);
538 path.addOval(r, SkPath::kCW_Direction);
539
540 texture = addTexture(entry, &path, paint);
541 }
542
543 return texture;
544}
545
546///////////////////////////////////////////////////////////////////////////////
547// Rects
548///////////////////////////////////////////////////////////////////////////////
549
550PathTexture* PathCache::getRect(float width, float height, SkPaint* paint) {
551 PathDescription entry(kShapeRect, paint);
552 entry.shape.rect.mWidth = width;
553 entry.shape.rect.mHeight = height;
554
555 PathTexture* texture = get(entry);
556
557 if (!texture) {
558 SkPath path;
559 SkRect r;
560 r.set(0.0f, 0.0f, width, height);
561 path.addRect(r, SkPath::kCW_Direction);
562
563 texture = addTexture(entry, &path, paint);
564 }
565
566 return texture;
567}
568
569///////////////////////////////////////////////////////////////////////////////
570// Arcs
571///////////////////////////////////////////////////////////////////////////////
572
573PathTexture* PathCache::getArc(float width, float height,
574 float startAngle, float sweepAngle, bool useCenter, SkPaint* paint) {
575 PathDescription entry(kShapeArc, paint);
576 entry.shape.arc.mWidth = width;
577 entry.shape.arc.mHeight = height;
578 entry.shape.arc.mStartAngle = startAngle;
579 entry.shape.arc.mSweepAngle = sweepAngle;
580 entry.shape.arc.mUseCenter = useCenter;
581
582 PathTexture* texture = get(entry);
583
584 if (!texture) {
585 SkPath path;
586 SkRect r;
587 r.set(0.0f, 0.0f, width, height);
588 if (useCenter) {
589 path.moveTo(r.centerX(), r.centerY());
590 }
591 path.arcTo(r, startAngle, sweepAngle, !useCenter);
592 if (useCenter) {
593 path.close();
594 }
595
596 texture = addTexture(entry, &path, paint);
597 }
598
599 return texture;
600}
601
Romain Guy7fbcc042010-08-04 15:40:07 -0700602}; // namespace uirenderer
603}; // namespace android