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