11fedd9168715d7a8e645acdd5c8d06ffa982fd51John Reck/* 21fedd9168715d7a8e645acdd5c8d06ffa982fd51John Reck * Copyright (C) 2017 The Android Open Source Project 31fedd9168715d7a8e645acdd5c8d06ffa982fd51John Reck * 41fedd9168715d7a8e645acdd5c8d06ffa982fd51John Reck * Licensed under the Apache License, Version 2.0 (the "License"); 51fedd9168715d7a8e645acdd5c8d06ffa982fd51John Reck * you may not use this file except in compliance with the License. 61fedd9168715d7a8e645acdd5c8d06ffa982fd51John Reck * You may obtain a copy of the License at 71fedd9168715d7a8e645acdd5c8d06ffa982fd51John Reck * 81fedd9168715d7a8e645acdd5c8d06ffa982fd51John Reck * http://www.apache.org/licenses/LICENSE-2.0 91fedd9168715d7a8e645acdd5c8d06ffa982fd51John Reck * 101fedd9168715d7a8e645acdd5c8d06ffa982fd51John Reck * Unless required by applicable law or agreed to in writing, software 111fedd9168715d7a8e645acdd5c8d06ffa982fd51John Reck * distributed under the License is distributed on an "AS IS" BASIS, 121fedd9168715d7a8e645acdd5c8d06ffa982fd51John Reck * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 131fedd9168715d7a8e645acdd5c8d06ffa982fd51John Reck * See the License for the specific language governing permissions and 141fedd9168715d7a8e645acdd5c8d06ffa982fd51John Reck * limitations under the License. 151fedd9168715d7a8e645acdd5c8d06ffa982fd51John Reck */ 161fedd9168715d7a8e645acdd5c8d06ffa982fd51John Reck 171fedd9168715d7a8e645acdd5c8d06ffa982fd51John Reckpackage com.android.test.hwui; 181fedd9168715d7a8e645acdd5c8d06ffa982fd51John Reck 191fedd9168715d7a8e645acdd5c8d06ffa982fd51John Reckimport static android.graphics.GraphicBuffer.USAGE_HW_TEXTURE; 201fedd9168715d7a8e645acdd5c8d06ffa982fd51John Reckimport static android.graphics.GraphicBuffer.USAGE_SW_READ_NEVER; 211fedd9168715d7a8e645acdd5c8d06ffa982fd51John Reckimport static android.graphics.GraphicBuffer.USAGE_SW_WRITE_NEVER; 221fedd9168715d7a8e645acdd5c8d06ffa982fd51John Reckimport static android.graphics.GraphicBuffer.USAGE_SW_WRITE_RARELY; 231fedd9168715d7a8e645acdd5c8d06ffa982fd51John Reck 241fedd9168715d7a8e645acdd5c8d06ffa982fd51John Reckimport android.app.Activity; 251fedd9168715d7a8e645acdd5c8d06ffa982fd51John Reckimport android.graphics.Bitmap; 261fedd9168715d7a8e645acdd5c8d06ffa982fd51John Reckimport android.graphics.Canvas; 271fedd9168715d7a8e645acdd5c8d06ffa982fd51John Reckimport android.graphics.Color; 281fedd9168715d7a8e645acdd5c8d06ffa982fd51John Reckimport android.graphics.GraphicBuffer; 291fedd9168715d7a8e645acdd5c8d06ffa982fd51John Reckimport android.graphics.Paint; 301fedd9168715d7a8e645acdd5c8d06ffa982fd51John Reckimport android.graphics.PixelFormat; 311fedd9168715d7a8e645acdd5c8d06ffa982fd51John Reckimport android.graphics.SurfaceTexture; 321fedd9168715d7a8e645acdd5c8d06ffa982fd51John Reckimport android.os.Bundle; 331fedd9168715d7a8e645acdd5c8d06ffa982fd51John Reckimport android.view.DisplayListCanvas; 341fedd9168715d7a8e645acdd5c8d06ffa982fd51John Reckimport android.view.RenderNode; 351fedd9168715d7a8e645acdd5c8d06ffa982fd51John Reckimport android.view.Surface; 361fedd9168715d7a8e645acdd5c8d06ffa982fd51John Reckimport android.view.ThreadedRenderer; 371fedd9168715d7a8e645acdd5c8d06ffa982fd51John Reckimport android.widget.ImageView; 381fedd9168715d7a8e645acdd5c8d06ffa982fd51John Reck 391fedd9168715d7a8e645acdd5c8d06ffa982fd51John Reckpublic class DrawIntoHwBitmapActivity extends Activity { 401fedd9168715d7a8e645acdd5c8d06ffa982fd51John Reck @Override 411fedd9168715d7a8e645acdd5c8d06ffa982fd51John Reck protected void onCreate(Bundle savedInstanceState) { 421fedd9168715d7a8e645acdd5c8d06ffa982fd51John Reck super.onCreate(savedInstanceState); 431fedd9168715d7a8e645acdd5c8d06ffa982fd51John Reck ImageView view = new ImageView(this); 441fedd9168715d7a8e645acdd5c8d06ffa982fd51John Reck view.setScaleType(ImageView.ScaleType.CENTER_INSIDE); 451fedd9168715d7a8e645acdd5c8d06ffa982fd51John Reck setContentView(view); 461fedd9168715d7a8e645acdd5c8d06ffa982fd51John Reck view.setImageBitmap(createBitmap()); 471fedd9168715d7a8e645acdd5c8d06ffa982fd51John Reck } 481fedd9168715d7a8e645acdd5c8d06ffa982fd51John Reck 491fedd9168715d7a8e645acdd5c8d06ffa982fd51John Reck Bitmap createBitmap() { 501fedd9168715d7a8e645acdd5c8d06ffa982fd51John Reck RenderNode node = RenderNode.create("HwuiCanvas", null); 511fedd9168715d7a8e645acdd5c8d06ffa982fd51John Reck node.setLeftTopRightBottom(0, 0, 500, 500); 521fedd9168715d7a8e645acdd5c8d06ffa982fd51John Reck node.setClipToBounds(false); 531fedd9168715d7a8e645acdd5c8d06ffa982fd51John Reck DisplayListCanvas canvas = node.start(500, 500); 541fedd9168715d7a8e645acdd5c8d06ffa982fd51John Reck Paint p = new Paint(); 551fedd9168715d7a8e645acdd5c8d06ffa982fd51John Reck p.setColor(Color.BLACK); 561fedd9168715d7a8e645acdd5c8d06ffa982fd51John Reck p.setTextSize(20 * getResources().getDisplayMetrics().density); 571fedd9168715d7a8e645acdd5c8d06ffa982fd51John Reck canvas.drawColor(0xFF2196F3); 581fedd9168715d7a8e645acdd5c8d06ffa982fd51John Reck p.setColor(0xFFBBDEFB); 591fedd9168715d7a8e645acdd5c8d06ffa982fd51John Reck canvas.drawRect(0, 0, 500, 100, p); 601fedd9168715d7a8e645acdd5c8d06ffa982fd51John Reck p.setColor(Color.BLACK); 611fedd9168715d7a8e645acdd5c8d06ffa982fd51John Reck canvas.drawText("Hello, World!", 0, 90, p); 621fedd9168715d7a8e645acdd5c8d06ffa982fd51John Reck node.end(canvas); 631fedd9168715d7a8e645acdd5c8d06ffa982fd51John Reck return ThreadedRenderer.createHardwareBitmap(node, 500, 500); 641fedd9168715d7a8e645acdd5c8d06ffa982fd51John Reck } 651fedd9168715d7a8e645acdd5c8d06ffa982fd51John Reck} 66