Romain Guy | 01d58e4 | 2011-01-19 21:54:02 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
| 21 | namespace android { |
| 22 | namespace uirenderer { |
| 23 | |
Romain Guy | ff26a0c | 2011-01-20 11:35:46 -0800 | [diff] [blame] | 24 | /////////////////////////////////////////////////////////////////////////////// |
| 25 | // Rounded rects |
| 26 | /////////////////////////////////////////////////////////////////////////////// |
| 27 | |
| 28 | RoundRectShapeCache::RoundRectShapeCache(): ShapeCache<RoundRectShapeCacheEntry>( |
| 29 | "round rect", PROPERTY_SHAPE_CACHE_SIZE, DEFAULT_SHAPE_CACHE_SIZE) { |
Romain Guy | 01d58e4 | 2011-01-19 21:54:02 -0800 | [diff] [blame] | 30 | } |
| 31 | |
| 32 | PathTexture* 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 Guy | ff26a0c | 2011-01-20 11:35:46 -0800 | [diff] [blame] | 49 | /////////////////////////////////////////////////////////////////////////////// |
| 50 | // Circles |
| 51 | /////////////////////////////////////////////////////////////////////////////// |
| 52 | |
| 53 | CircleShapeCache::CircleShapeCache(): ShapeCache<CircleShapeCacheEntry>( |
| 54 | "circle", PROPERTY_SHAPE_CACHE_SIZE, DEFAULT_SHAPE_CACHE_SIZE) { |
Romain Guy | 01d58e4 | 2011-01-19 21:54:02 -0800 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | PathTexture* 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 | |
| 71 | }; // namespace uirenderer |
| 72 | }; // namespace android |