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 #include <SkCanvas.h>
24 #include <SkPaint.h>
25 #include <SkRefCnt.h>
26 
27 class HwBitmap565;
28 
29 static TestScene::Registrar _HwBitmap565(TestScene::Info{
30         "hwBitmap565", "Draws composite shader with hardware bitmap",
31         TestScene::simpleCreateScene<HwBitmap565>});
32 
33 class HwBitmap565 : public TestScene {
34 public:
35     sp<RenderNode> card;
createContent(int width,int height,Canvas & canvas)36     void createContent(int width, int height, Canvas& canvas) override {
37         canvas.drawColor(Color::Grey_200, SkBlendMode::kSrcOver);
38 
39         sk_sp<Bitmap> hardwareBitmap = BitmapAllocationTestUtils::allocateHardwareBitmap(
40                 200, 200, kRGB_565_SkColorType, [](SkBitmap& skBitmap) {
41                     skBitmap.eraseColor(Color::White);
42                     SkCanvas skCanvas(skBitmap);
43                     SkPaint skPaint;
44                     skPaint.setColor(Color::Red_500);
45                     skCanvas.drawRect(SkRect::MakeWH(100, 100), skPaint);
46                     skPaint.setColor(Color::Blue_500);
47                     skCanvas.drawRect(SkRect::MakeXYWH(100, 100, 100, 100), skPaint);
48                 });
49         canvas.drawBitmap(*hardwareBitmap, 10.0f, 10.0f, nullptr);
50     }
51 
doFrame(int frameNr)52     void doFrame(int frameNr) override {}
53 };