| John Reck | 16c9d6a | 2015-11-17 15:51:08 -0800 | [diff] [blame] | 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 | class PartialDamageAnimation; |
| 20 | |
| Chris Craik | 27e58b4 | 2015-12-07 10:01:38 -0800 | [diff] [blame] | 21 | static TestScene::Registrar _PartialDamage(TestScene::Info{ |
| John Reck | 16c9d6a | 2015-11-17 15:51:08 -0800 | [diff] [blame] | 22 | "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.", |
| Chris Craik | 27e58b4 | 2015-12-07 10:01:38 -0800 | [diff] [blame] | 26 | TestScene::simpleCreateScene<PartialDamageAnimation> |
| John Reck | 16c9d6a | 2015-11-17 15:51:08 -0800 | [diff] [blame] | 27 | }); |
| 28 | |
| 29 | class PartialDamageAnimation : public TestScene { |
| 30 | public: |
| 31 | std::vector< sp<RenderNode> > cards; |
| Stan Iliev | 06152cd | 2016-07-27 17:55:43 -0400 | [diff] [blame] | 32 | void createContent(int width, int height, Canvas& canvas) override { |
| John Reck | 16c9d6a | 2015-11-17 15:51:08 -0800 | [diff] [blame] | 33 | static SkColor COLORS[] = { |
| 34 | 0xFFF44336, |
| 35 | 0xFF9C27B0, |
| 36 | 0xFF2196F3, |
| 37 | 0xFF4CAF50, |
| 38 | }; |
| 39 | |
| Mike Reed | 260ab72 | 2016-10-07 15:59:20 -0400 | [diff] [blame] | 40 | canvas.drawColor(0xFFFFFFFF, SkBlendMode::kSrcOver); |
| John Reck | 16c9d6a | 2015-11-17 15:51:08 -0800 | [diff] [blame] | 41 | |
| 42 | for (int x = dp(16); x < (width - dp(116)); x += dp(116)) { |
| 43 | for (int y = dp(16); y < (height - dp(116)); y += dp(116)) { |
| 44 | SkColor color = COLORS[static_cast<int>((y / dp(116))) % 4]; |
| 45 | sp<RenderNode> card = TestUtils::createNode(x, y, |
| 46 | x + dp(100), y + dp(100), |
| Stan Iliev | 06152cd | 2016-07-27 17:55:43 -0400 | [diff] [blame] | 47 | [color](RenderProperties& props, Canvas& canvas) { |
| Mike Reed | 260ab72 | 2016-10-07 15:59:20 -0400 | [diff] [blame] | 48 | canvas.drawColor(color, SkBlendMode::kSrcOver); |
| John Reck | 16c9d6a | 2015-11-17 15:51:08 -0800 | [diff] [blame] | 49 | }); |
| 50 | canvas.drawRenderNode(card.get()); |
| 51 | cards.push_back(card); |
| 52 | } |
| 53 | } |
| 54 | } |
| 55 | void doFrame(int frameNr) override { |
| 56 | int curFrame = frameNr % 150; |
| 57 | cards[0]->mutateStagingProperties().setTranslationX(curFrame); |
| 58 | cards[0]->mutateStagingProperties().setTranslationY(curFrame); |
| 59 | cards[0]->setPropertyFieldsDirty(RenderNode::X | RenderNode::Y); |
| 60 | |
| Stan Iliev | 06152cd | 2016-07-27 17:55:43 -0400 | [diff] [blame] | 61 | TestUtils::recordNode(*cards[0], [curFrame](Canvas& canvas) { |
| John Reck | 16c9d6a | 2015-11-17 15:51:08 -0800 | [diff] [blame] | 62 | SkColor color = TestUtils::interpolateColor( |
| 63 | curFrame / 150.0f, 0xFFF44336, 0xFFF8BBD0); |
| Mike Reed | 260ab72 | 2016-10-07 15:59:20 -0400 | [diff] [blame] | 64 | canvas.drawColor(color, SkBlendMode::kSrcOver); |
| John Reck | 16c9d6a | 2015-11-17 15:51:08 -0800 | [diff] [blame] | 65 | }); |
| 66 | } |
| 67 | }; |