• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 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 #pragma once
18 
19 #include <SkCanvas.h>
20 #include <SkDrawable.h>
21 #include <utils/RefBase.h>
22 #include "CanvasProperty.h"
23 
24 namespace android {
25 namespace uirenderer {
26 namespace skiapipeline {
27 
28 class AnimatedRoundRect : public SkDrawable {
29 public:
AnimatedRoundRect(uirenderer::CanvasPropertyPrimitive * left,uirenderer::CanvasPropertyPrimitive * top,uirenderer::CanvasPropertyPrimitive * right,uirenderer::CanvasPropertyPrimitive * bottom,uirenderer::CanvasPropertyPrimitive * rx,uirenderer::CanvasPropertyPrimitive * ry,uirenderer::CanvasPropertyPaint * p)30     AnimatedRoundRect(uirenderer::CanvasPropertyPrimitive* left,
31                       uirenderer::CanvasPropertyPrimitive* top,
32                       uirenderer::CanvasPropertyPrimitive* right,
33                       uirenderer::CanvasPropertyPrimitive* bottom,
34                       uirenderer::CanvasPropertyPrimitive* rx,
35                       uirenderer::CanvasPropertyPrimitive* ry, uirenderer::CanvasPropertyPaint* p)
36             : mLeft(left), mTop(top), mRight(right), mBottom(bottom), mRx(rx), mRy(ry), mPaint(p) {}
37 
38 protected:
onGetBounds()39     virtual SkRect onGetBounds() override {
40         return SkRect::MakeLTRB(mLeft->value, mTop->value, mRight->value, mBottom->value);
41     }
onDraw(SkCanvas * canvas)42     virtual void onDraw(SkCanvas* canvas) override {
43         SkRect rect = SkRect::MakeLTRB(mLeft->value, mTop->value, mRight->value, mBottom->value);
44         canvas->drawRoundRect(rect, mRx->value, mRy->value, mPaint->value);
45     }
46 
47 private:
48     sp<uirenderer::CanvasPropertyPrimitive> mLeft;
49     sp<uirenderer::CanvasPropertyPrimitive> mTop;
50     sp<uirenderer::CanvasPropertyPrimitive> mRight;
51     sp<uirenderer::CanvasPropertyPrimitive> mBottom;
52     sp<uirenderer::CanvasPropertyPrimitive> mRx;
53     sp<uirenderer::CanvasPropertyPrimitive> mRy;
54     sp<uirenderer::CanvasPropertyPaint> mPaint;
55 };
56 
57 class AnimatedCircle : public SkDrawable {
58 public:
AnimatedCircle(uirenderer::CanvasPropertyPrimitive * x,uirenderer::CanvasPropertyPrimitive * y,uirenderer::CanvasPropertyPrimitive * radius,uirenderer::CanvasPropertyPaint * paint)59     AnimatedCircle(uirenderer::CanvasPropertyPrimitive* x, uirenderer::CanvasPropertyPrimitive* y,
60                    uirenderer::CanvasPropertyPrimitive* radius,
61                    uirenderer::CanvasPropertyPaint* paint)
62             : mX(x), mY(y), mRadius(radius), mPaint(paint) {}
63 
64 protected:
onGetBounds()65     virtual SkRect onGetBounds() override {
66         const float x = mX->value;
67         const float y = mY->value;
68         const float radius = mRadius->value;
69         return SkRect::MakeLTRB(x - radius, y - radius, x + radius, y + radius);
70     }
onDraw(SkCanvas * canvas)71     virtual void onDraw(SkCanvas* canvas) override {
72         canvas->drawCircle(mX->value, mY->value, mRadius->value, mPaint->value);
73     }
74 
75 private:
76     sp<uirenderer::CanvasPropertyPrimitive> mX;
77     sp<uirenderer::CanvasPropertyPrimitive> mY;
78     sp<uirenderer::CanvasPropertyPrimitive> mRadius;
79     sp<uirenderer::CanvasPropertyPaint> mPaint;
80 };
81 
82 }  // namespace skiapipeline
83 }  // namespace uirenderer
84 }  // namespace android
85