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 <SkImagePriv.h> 18 #include "TestSceneBase.h" 19 #include "tests/common/BitmapAllocationTestUtils.h" 20 #include "utils/Color.h" 21 22 class BitmapShaders; 23 24 static bool _BitmapShaders(BitmapAllocationTestUtils::registerBitmapAllocationScene<BitmapShaders>( 25 "bitmapShader", "Draws bitmap shaders with repeat and mirror modes.")); 26 27 class BitmapShaders : public TestScene { 28 public: BitmapShaders(BitmapAllocationTestUtils::BitmapAllocator allocator)29 explicit BitmapShaders(BitmapAllocationTestUtils::BitmapAllocator allocator) 30 : TestScene(), mAllocator(allocator) {} 31 32 sp<RenderNode> card; createContent(int width,int height,Canvas & canvas)33 void createContent(int width, int height, Canvas& canvas) override { 34 canvas.drawColor(Color::Grey_200, SkBlendMode::kSrcOver); 35 sk_sp<Bitmap> hwuiBitmap = 36 mAllocator(200, 200, kRGBA_8888_SkColorType, [](SkBitmap& skBitmap) { 37 skBitmap.eraseColor(Color::White); 38 SkCanvas skCanvas(skBitmap); 39 SkPaint skPaint; 40 skPaint.setColor(Color::Red_500); 41 skCanvas.drawRect(SkRect::MakeWH(100, 100), skPaint); 42 skPaint.setColor(Color::Blue_500); 43 skCanvas.drawRect(SkRect::MakeXYWH(100, 100, 100, 100), skPaint); 44 }); 45 46 SkPaint paint; 47 sk_sp<SkImage> image = hwuiBitmap->makeImage(); 48 sk_sp<SkShader> repeatShader = 49 image->makeShader(SkShader::TileMode::kRepeat_TileMode, 50 SkShader::TileMode::kRepeat_TileMode, nullptr); 51 paint.setShader(std::move(repeatShader)); 52 canvas.drawRoundRect(0, 0, 500, 500, 50.0f, 50.0f, paint); 53 54 sk_sp<SkShader> mirrorShader = 55 image->makeShader(SkShader::TileMode::kMirror_TileMode, 56 SkShader::TileMode::kMirror_TileMode, nullptr); 57 paint.setShader(std::move(mirrorShader)); 58 canvas.drawRoundRect(0, 600, 500, 1100, 50.0f, 50.0f, paint); 59 } 60 doFrame(int frameNr)61 void doFrame(int frameNr) override {} 62 63 BitmapAllocationTestUtils::BitmapAllocator mAllocator; 64 }; 65