blob: a5678d48482aafb9eb75e85afd5ce4e03cab9778 [file] [log] [blame]
Chris Craik8c271ca2014-03-25 10:33:01 -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 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:
John Reck1bcacfd2017-11-03 10:12:19 -070028 RevealClip() : mShouldClip(false), mX(0), mY(0), mRadius(0) {}
Chris Craik8c271ca2014-03-25 10:33:01 -070029
Chris Craikaf4d04c2014-07-29 12:50:14 -070030 void set(bool shouldClip, float x, float y, float radius) {
Chris Craik8c271ca2014-03-25 10:33:01 -070031 mShouldClip = shouldClip;
Chris Craik8c271ca2014-03-25 10:33:01 -070032 mX = x;
33 mY = y;
34 mRadius = radius;
35
36 mPath.rewind();
37 if (mShouldClip) {
38 mPath.addCircle(x, y, radius);
39 }
40 }
41
John Reck1bcacfd2017-11-03 10:12:19 -070042 bool willClip() const { return mShouldClip; }
Chris Craik8c271ca2014-03-25 10:33:01 -070043
Chris Craikaf4d04c2014-07-29 12:50:14 -070044 void getBounds(Rect* outBounds) const {
John Reck1bcacfd2017-11-03 10:12:19 -070045 outBounds->set(mX - mRadius, mY - mRadius, mX + mRadius, mY + mRadius);
John Reckd3de42c2014-07-15 14:29:33 -070046 }
John Recke248bd12015-08-05 13:53:53 -070047
Chris Craikaf4d04c2014-07-29 12:50:14 -070048 float getRadius() const { return mRadius; }
John Recke248bd12015-08-05 13:53:53 -070049 float getX() const { return mX; }
50 float getY() const { return mY; }
John Reckd3de42c2014-07-15 14:29:33 -070051
Chris Craik8c271ca2014-03-25 10:33:01 -070052 const SkPath* getPath() const {
Chris Craike84a2082014-12-22 14:28:49 -080053 if (!mShouldClip) return nullptr;
Chris Craik8c271ca2014-03-25 10:33:01 -070054
55 return &mPath;
56 }
57
58private:
59 bool mShouldClip;
Chris Craik8c271ca2014-03-25 10:33:01 -070060 float mX;
61 float mY;
62 float mRadius;
63 SkPath mPath;
64};
65
66} /* namespace uirenderer */
67} /* namespace android */
68
69#endif /* REVEALCLIP_H */