1 /* 2 * Copyright (C) 2015 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 #include "TestSceneBase.h" 18 #include "utils/Color.h" 19 20 class OpPropAnimation; 21 22 static TestScene::Registrar _Shapes(TestScene::Info{ 23 "opprops", "A minimal demonstration of CanvasProperty drawing operations.", 24 TestScene::simpleCreateScene<OpPropAnimation>}); 25 26 class OpPropAnimation : public TestScene { 27 public: 28 sp<CanvasPropertyPaint> mPaint = new CanvasPropertyPaint(SkPaint()); 29 30 sp<CanvasPropertyPrimitive> mRoundRectLeft = new CanvasPropertyPrimitive(0); 31 sp<CanvasPropertyPrimitive> mRoundRectTop = new CanvasPropertyPrimitive(0); 32 sp<CanvasPropertyPrimitive> mRoundRectRight = new CanvasPropertyPrimitive(0); 33 sp<CanvasPropertyPrimitive> mRoundRectBottom = new CanvasPropertyPrimitive(0); 34 sp<CanvasPropertyPrimitive> mRoundRectRx = new CanvasPropertyPrimitive(0); 35 sp<CanvasPropertyPrimitive> mRoundRectRy = new CanvasPropertyPrimitive(0); 36 37 sp<CanvasPropertyPrimitive> mCircleX = new CanvasPropertyPrimitive(0); 38 sp<CanvasPropertyPrimitive> mCircleY = new CanvasPropertyPrimitive(0); 39 sp<CanvasPropertyPrimitive> mCircleRadius = new CanvasPropertyPrimitive(0); 40 41 sp<RenderNode> content; createContent(int width,int height,Canvas & canvas)42 void createContent(int width, int height, Canvas& canvas) override { 43 content = TestUtils::createNode(0, 0, width, height, [this, width, height]( 44 RenderProperties& props, 45 Canvas& canvas) { 46 mPaint->value.setAntiAlias(true); 47 mPaint->value.setColor(Color::Blue_500); 48 49 mRoundRectRight->value = width / 2; 50 mRoundRectBottom->value = height / 2; 51 52 mCircleX->value = width * 0.75; 53 mCircleY->value = height * 0.75; 54 55 canvas.drawColor(Color::White, SkBlendMode::kSrcOver); 56 canvas.drawRoundRect(mRoundRectLeft.get(), mRoundRectTop.get(), mRoundRectRight.get(), 57 mRoundRectBottom.get(), mRoundRectRx.get(), mRoundRectRy.get(), 58 mPaint.get()); 59 canvas.drawCircle(mCircleX.get(), mCircleY.get(), mCircleRadius.get(), mPaint.get()); 60 }); 61 canvas.drawRenderNode(content.get()); 62 } 63 doFrame(int frameNr)64 void doFrame(int frameNr) override { 65 float value = (abs((frameNr % 200) - 100)) / 100.0f; 66 mRoundRectRx->value = dp(10) + value * dp(40); 67 mRoundRectRy->value = dp(10) + value * dp(80); 68 mCircleRadius->value = value * dp(200); 69 content->setPropertyFieldsDirty(RenderNode::GENERIC); 70 } 71 }; 72