Debian Codegraph @

tests/HwAccelerationTest/src/com/android/test/hwui/BitmapMeshLayerActivity.java

raw symbols SCIP
1 /*
2 * Copyright (C) 2011 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 android.app.Activity;
20 import android.content.Context;
21 import android.graphics.Bitmap;
22 import android.graphics.BitmapFactory;
23 import android.graphics.Canvas;
24 import android.graphics.Paint;
25 import android.os.Bundle;
26 import android.view.View;
27
28 @SuppressWarnings({"UnusedDeclaration"})
29 public class BitmapMeshLayerActivity extends Activity {
30 @Override
31 protected void onCreate(Bundle savedInstanceState) {
32 super.onCreate(savedInstanceState);
33 final BitmapMeshView view = new BitmapMeshView(this);
34 view.setLayerType(View.LAYER_TYPE_HARDWARE, null);
35 setContentView(view);
36 }
37
38 static class BitmapMeshView extends View {
39 private Paint mBitmapPaint;
40 private final Bitmap mBitmap1;
41 private float[] mVertices;
42 private int[] mColors;
43
44 BitmapMeshView(Context c) {
45 super(c);
46
47 mBitmap1 = BitmapFactory.decodeResource(c.getResources(), R.drawable.sunset1);
48
49 final float width = mBitmap1.getWidth() / 3.0f;
50 final float height = mBitmap1.getHeight() / 3.0f;
51
52 mVertices = new float[] {
53 0.0f, 0.0f, width, 0.0f, width * 2, 0.0f, width * 3, 0.0f,
54 0.0f, height, width, height, width * 2, height, width * 4, height,
55 0.0f, height * 2, width, height * 2, width * 2, height * 2, width * 3, height * 2,
56 0.0f, height * 4, width, height * 4, width * 2, height * 4, width * 4, height * 4,
57 };
58
59 mColors = new int[] {
60 0xffff0000, 0xff00ff00, 0xff0000ff, 0xffff0000,
61 0xff0000ff, 0xffff0000, 0xff00ff00, 0xff00ff00,
62 0xff00ff00, 0xff0000ff, 0xffff0000, 0xff00ff00,
63 0x00ff0000, 0x0000ff00, 0x000000ff, 0x00ff0000,
64 };
65 }
66
67 @Override
68 protected void onDraw(Canvas canvas) {
69 super.onDraw(canvas);
70
71 canvas.translate(100, 100);
72 canvas.drawBitmapMesh(mBitmap1, 3, 3, mVertices, 0, null, 0, null);
73
74 canvas.translate(400, 0);
75 canvas.drawBitmapMesh(mBitmap1, 3, 3, mVertices, 0, mColors, 0, null);
76 }
77 }
78 }