blob: fb1b000a995eb4fce60e68db95b71bc93ea8fed5 [file] [log] [blame]
John Reck16c9d6a2015-11-17 15:51:08 -08001/*
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
19class PartialDamageAnimation;
20
Chris Craik27e58b42015-12-07 10:01:38 -080021static TestScene::Registrar _PartialDamage(TestScene::Info{
John Reck1bcacfd2017-11-03 10:12:19 -070022 "partialdamage",
23 "Tests the partial invalidation path. Draws a grid of rects and animates 1 "
24 "of them, should be low CPU & GPU load if EGL_EXT_buffer_age or "
25 "EGL_KHR_partial_update is supported by the device & are enabled in hwui.",
26 TestScene::simpleCreateScene<PartialDamageAnimation>});
John Reck16c9d6a2015-11-17 15:51:08 -080027
28class PartialDamageAnimation : public TestScene {
29public:
John Reck1bcacfd2017-11-03 10:12:19 -070030 std::vector<sp<RenderNode> > cards;
Stan Iliev06152cd2016-07-27 17:55:43 -040031 void createContent(int width, int height, Canvas& canvas) override {
John Reck16c9d6a2015-11-17 15:51:08 -080032 static SkColor COLORS[] = {
John Reck1bcacfd2017-11-03 10:12:19 -070033 0xFFF44336, 0xFF9C27B0, 0xFF2196F3, 0xFF4CAF50,
John Reck16c9d6a2015-11-17 15:51:08 -080034 };
35
Mike Reed260ab722016-10-07 15:59:20 -040036 canvas.drawColor(0xFFFFFFFF, SkBlendMode::kSrcOver);
John Reck16c9d6a2015-11-17 15:51:08 -080037
38 for (int x = dp(16); x < (width - dp(116)); x += dp(116)) {
39 for (int y = dp(16); y < (height - dp(116)); y += dp(116)) {
40 SkColor color = COLORS[static_cast<int>((y / dp(116))) % 4];
John Reck1bcacfd2017-11-03 10:12:19 -070041 sp<RenderNode> card =
42 TestUtils::createNode(x, y, x + dp(100), y + dp(100),
43 [color](RenderProperties& props, Canvas& canvas) {
44 canvas.drawColor(color, SkBlendMode::kSrcOver);
45 });
John Reck16c9d6a2015-11-17 15:51:08 -080046 canvas.drawRenderNode(card.get());
47 cards.push_back(card);
48 }
49 }
50 }
51 void doFrame(int frameNr) override {
52 int curFrame = frameNr % 150;
53 cards[0]->mutateStagingProperties().setTranslationX(curFrame);
54 cards[0]->mutateStagingProperties().setTranslationY(curFrame);
55 cards[0]->setPropertyFieldsDirty(RenderNode::X | RenderNode::Y);
56
Stan Iliev06152cd2016-07-27 17:55:43 -040057 TestUtils::recordNode(*cards[0], [curFrame](Canvas& canvas) {
John Reck1bcacfd2017-11-03 10:12:19 -070058 SkColor color = TestUtils::interpolateColor(curFrame / 150.0f, 0xFFF44336, 0xFFF8BBD0);
Mike Reed260ab722016-10-07 15:59:20 -040059 canvas.drawColor(color, SkBlendMode::kSrcOver);
John Reck16c9d6a2015-11-17 15:51:08 -080060 });
61 }
62};