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 | |
| 24 | RoundRectShapeCache::RoundRectShapeCache(): ShapeCache<RoundRectShapeCacheEntry>() { |
| 25 | } |
| 26 | |
| 27 | PathTexture* RoundRectShapeCache::getRoundRect(float width, float height, |
| 28 | float rx, float ry, SkPaint* paint) { |
| 29 | RoundRectShapeCacheEntry entry(width, height, rx, ry, paint); |
| 30 | PathTexture* texture = get(entry); |
| 31 | |
| 32 | if (!texture) { |
| 33 | SkPath path; |
| 34 | SkRect r; |
| 35 | r.set(0.0f, 0.0f, width, height); |
| 36 | path.addRoundRect(r, rx, ry, SkPath::kCW_Direction); |
| 37 | |
| 38 | texture = addTexture(entry, &path, paint); |
| 39 | } |
| 40 | |
| 41 | return texture; |
| 42 | } |
| 43 | |
| 44 | CircleShapeCache::CircleShapeCache(): ShapeCache<CircleShapeCacheEntry>() { |
| 45 | } |
| 46 | |
| 47 | PathTexture* CircleShapeCache::getCircle(float radius, SkPaint* paint) { |
| 48 | CircleShapeCacheEntry entry(radius, paint); |
| 49 | PathTexture* texture = get(entry); |
| 50 | |
| 51 | if (!texture) { |
| 52 | SkPath path; |
| 53 | path.addCircle(radius, radius, radius, SkPath::kCW_Direction); |
| 54 | |
| 55 | texture = addTexture(entry, &path, paint); |
| 56 | } |
| 57 | |
| 58 | return texture; |
| 59 | } |
| 60 | |
| 61 | }; // namespace uirenderer |
| 62 | }; // namespace android |