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