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