blob: f42be507203d06d8416ccb1b881f76f6bb314b01 [file] [log] [blame]
Chris Craikb49f4462014-03-20 12:44:20 -07001/*
2 * Copyright (C) 2014 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#ifndef OUTLINE_H
17#define OUTLINE_H
18
19#include <SkPath.h>
20
21#include "Rect.h"
22
23namespace android {
24namespace uirenderer {
25
26class Outline {
27public:
28 Outline()
29 : mShouldClip(false)
30 , mType(kOutlineType_None)
31 , mRadius(0) {}
32
33 void setRoundRect(int left, int top, int right, int bottom, int radius) {
34 mType = kOutlineType_RoundRect;
35 mBounds.set(left, top, right, bottom);
36 mRadius = radius;
37 mPath.reset();
38 mPath.addRoundRect(SkRect::MakeLTRB(left, top, right, bottom),
39 radius, radius);
40 }
41
42 void setConvexPath(const SkPath* outline) {
43 if (!outline) {
44 setEmpty();
45 return;
46 }
47 mType = kOutlineType_ConvexPath;
48 mPath = *outline;
49 mBounds.set(outline->getBounds());
50 }
51
52 void setEmpty() {
53 mType = kOutlineType_None;
54 mPath.reset();
55 }
56
57 void setShouldClip(bool clip) {
58 mShouldClip = clip;
59 }
60
61
62 bool willClip() const {
63 // only round rect outlines can be used for clipping
64 return mShouldClip && (mType == kOutlineType_RoundRect);
65 }
66
67 const SkPath* getPath() {
68 if (mType == kOutlineType_None) return NULL;
69
70 return &mPath;
71 }
72
73private:
74 enum OutlineType {
75 kOutlineType_None = 0,
76 kOutlineType_ConvexPath = 1,
77 kOutlineType_RoundRect = 2
78 };
79
80 bool mShouldClip;
81 OutlineType mType;
82 Rect mBounds;
83 float mRadius;
84 SkPath mPath;
85};
86
87} /* namespace uirenderer */
88} /* namespace android */
89
90#endif /* OUTLINE_H */