• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
19 #include <SkBlendMode.h>
20 
21 class PartialDamageAnimation;
22 
23 static TestScene::Registrar _PartialDamage(TestScene::Info{
24         "partialdamage",
25         "Tests the partial invalidation path. Draws a grid of rects and animates 1 "
26         "of them, should be low CPU & GPU load if EGL_EXT_buffer_age or "
27         "EGL_KHR_partial_update is supported by the device & are enabled in hwui.",
28         TestScene::simpleCreateScene<PartialDamageAnimation>});
29 
30 class PartialDamageAnimation : public TestScene {
31 public:
32     std::vector<sp<RenderNode> > cards;
createContent(int width,int height,Canvas & canvas)33     void createContent(int width, int height, Canvas& canvas) override {
34         static SkColor COLORS[] = {
35                 0xFFF44336, 0xFF9C27B0, 0xFF2196F3, 0xFF4CAF50,
36         };
37 
38         canvas.drawColor(0xFFFFFFFF, SkBlendMode::kSrcOver);
39 
40         for (int x = dp(16); x < (width - dp(116)); x += dp(116)) {
41             for (int y = dp(16); y < (height - dp(116)); y += dp(116)) {
42                 SkColor color = COLORS[static_cast<int>((y / dp(116))) % 4];
43                 sp<RenderNode> card =
44                         TestUtils::createNode(x, y, x + dp(100), y + dp(100),
45                                               [color](RenderProperties& props, Canvas& canvas) {
46                                                   canvas.drawColor(color, SkBlendMode::kSrcOver);
47                                               });
48                 canvas.drawRenderNode(card.get());
49                 cards.push_back(card);
50             }
51         }
52     }
doFrame(int frameNr)53     void doFrame(int frameNr) override {
54         int curFrame = frameNr % 150;
55         cards[0]->mutateStagingProperties().setTranslationX(curFrame);
56         cards[0]->mutateStagingProperties().setTranslationY(curFrame);
57         cards[0]->setPropertyFieldsDirty(RenderNode::X | RenderNode::Y);
58 
59         TestUtils::recordNode(*cards[0], [curFrame](Canvas& canvas) {
60             SkColor color = TestUtils::interpolateColor(curFrame / 150.0f, 0xFFF44336, 0xFFF8BBD0);
61             canvas.drawColor(color, SkBlendMode::kSrcOver);
62         });
63     }
64 };
65