• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 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 package com.android.test.hwui;
18 
19 import static android.graphics.GraphicBuffer.USAGE_HW_TEXTURE;
20 import static android.graphics.GraphicBuffer.USAGE_SW_READ_NEVER;
21 import static android.graphics.GraphicBuffer.USAGE_SW_WRITE_NEVER;
22 import static android.graphics.GraphicBuffer.USAGE_SW_WRITE_RARELY;
23 
24 import android.app.Activity;
25 import android.graphics.Bitmap;
26 import android.graphics.Canvas;
27 import android.graphics.Color;
28 import android.graphics.GraphicBuffer;
29 import android.graphics.Paint;
30 import android.graphics.PixelFormat;
31 import android.graphics.SurfaceTexture;
32 import android.os.Bundle;
33 import android.view.DisplayListCanvas;
34 import android.view.RenderNode;
35 import android.view.Surface;
36 import android.view.ThreadedRenderer;
37 import android.widget.ImageView;
38 
39 public class DrawIntoHwBitmapActivity extends Activity {
40     @Override
onCreate(Bundle savedInstanceState)41     protected void onCreate(Bundle savedInstanceState) {
42         super.onCreate(savedInstanceState);
43         ImageView view = new ImageView(this);
44         view.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
45         setContentView(view);
46         view.setImageBitmap(createBitmap());
47     }
48 
createBitmap()49     Bitmap createBitmap() {
50         RenderNode node = RenderNode.create("HwuiCanvas", null);
51         node.setLeftTopRightBottom(0, 0, 500, 500);
52         node.setClipToBounds(false);
53         DisplayListCanvas canvas = node.start(500, 500);
54         Paint p = new Paint();
55         p.setColor(Color.BLACK);
56         p.setTextSize(20 * getResources().getDisplayMetrics().density);
57         canvas.drawColor(0xFF2196F3);
58         p.setColor(0xFFBBDEFB);
59         canvas.drawRect(0, 0, 500, 100, p);
60         p.setColor(Color.BLACK);
61         canvas.drawText("Hello, World!", 0, 90, p);
62         node.end(canvas);
63         return ThreadedRenderer.createHardwareBitmap(node, 500, 500);
64     }
65 }
66