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 #include "TestSceneBase.h" 18 #include "tests/common/BitmapAllocationTestUtils.h" 19 #include "utils/Color.h" 20 21 #include <SkBitmap.h> 22 23 using namespace android; 24 using namespace android::uirenderer; 25 26 class BitmapFillrate; 27 28 static bool _BitmapFillrate( 29 BitmapAllocationTestUtils::registerBitmapAllocationScene<BitmapFillrate>( 30 "bitmapFillrate", "Draws multiple large half transparent bitmaps.")); 31 32 class BitmapFillrate : public TestScene { 33 public: BitmapFillrate(BitmapAllocationTestUtils::BitmapAllocator allocator)34 explicit BitmapFillrate(BitmapAllocationTestUtils::BitmapAllocator allocator) 35 : TestScene(), mAllocator(allocator) {} 36 createContent(int width,int height,Canvas & canvas)37 void createContent(int width, int height, Canvas& canvas) override { 38 canvas.drawColor(Color::White, SkBlendMode::kSrcOver); 39 createNode(canvas, 0x909C27B0, 0, 0, width, height); 40 createNode(canvas, 0xA0CDDC39, width / 3, height / 3, width, height); 41 createNode(canvas, 0x90009688, width / 3, 0, width, height); 42 createNode(canvas, 0xA0FF5722, 0, height / 3, width, height); 43 createNode(canvas, 0x9000796B, width / 6, height / 6, width, height); 44 createNode(canvas, 0xA0FFC107, width / 6, 0, width, height); 45 } 46 doFrame(int frameNr)47 void doFrame(int frameNr) override { 48 for (size_t ci = 0; ci < mNodes.size(); ci++) { 49 mNodes[ci]->mutateStagingProperties().setTranslationX(frameNr % 200); 50 mNodes[ci]->mutateStagingProperties().setTranslationY(frameNr % 200); 51 mNodes[ci]->setPropertyFieldsDirty(RenderNode::X | RenderNode::Y); 52 } 53 } 54 55 private: createNode(Canvas & canvas,SkColor color,int left,int top,int width,int height)56 void createNode(Canvas& canvas, SkColor color, int left, int top, int width, int height) { 57 int itemWidth = 2 * width / 3; 58 int itemHeight = 2 * height / 3; 59 auto card = TestUtils::createNode( 60 left, top, left + itemWidth, top + itemHeight, 61 [this, itemWidth, itemHeight, color](RenderProperties& props, Canvas& canvas) { 62 sk_sp<Bitmap> bitmap = 63 mAllocator(itemWidth, itemHeight, kRGBA_8888_SkColorType, 64 [color](SkBitmap& skBitmap) { skBitmap.eraseColor(color); }); 65 canvas.drawBitmap(*bitmap, 0, 0, nullptr); 66 }); 67 canvas.drawRenderNode(card.get()); 68 mNodes.push_back(card); 69 } 70 71 BitmapAllocationTestUtils::BitmapAllocator mAllocator; 72 std::vector<sp<RenderNode> > mNodes; 73 }; 74