1 /*
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 REVEALCLIP_H
17 #define REVEALCLIP_H
18 
19 #include <SkPath.h>
20 
21 #include "Rect.h"
22 
23 namespace android {
24 namespace uirenderer {
25 
26 class RevealClip {
27 public:
RevealClip()28     RevealClip() : mShouldClip(false), mX(0), mY(0), mRadius(0) {}
29 
set(bool shouldClip,float x,float y,float radius)30     void set(bool shouldClip, float x, float y, float radius) {
31         mShouldClip = shouldClip;
32         mX = x;
33         mY = y;
34         mRadius = radius;
35 
36         mPath.rewind();
37         if (mShouldClip) {
38             mPath.addCircle(x, y, radius);
39         }
40     }
41 
willClip()42     bool willClip() const { return mShouldClip; }
43 
getBounds(Rect * outBounds)44     void getBounds(Rect* outBounds) const {
45         outBounds->set(mX - mRadius, mY - mRadius, mX + mRadius, mY + mRadius);
46     }
47 
getRadius()48     float getRadius() const { return mRadius; }
getX()49     float getX() const { return mX; }
getY()50     float getY() const { return mY; }
51 
getPath()52     const SkPath* getPath() const {
53         if (!mShouldClip) return nullptr;
54 
55         return &mPath;
56     }
57 
58 private:
59     bool mShouldClip;
60     float mX;
61     float mY;
62     float mRadius;
63     SkPath mPath;
64 };
65 
66 } /* namespace uirenderer */
67 } /* namespace android */
68 
69 #endif /* REVEALCLIP_H */
70