Home | History | Annotate | Download | only in test
      1 /*
      2  * Copyright (C) 2018 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.amm.test;
     18 
     19 import android.content.Context;
     20 import android.view.WindowManager;
     21 import android.widget.TextView;
     22 
     23 class ThreadedRendererUse {
     24 
     25   private TextView mTextView;
     26 
     27   /**
     28    * Cause a threaded renderer EGL allocation to be used, with given
     29    * dimensions.
     30    */
     31   public ThreadedRendererUse(Context context, int width, int height) {
     32     mTextView = new TextView(context);
     33     mTextView.setText("TRU");
     34     mTextView.setBackgroundColor(0xffff0000);
     35 
     36     // Adding a view to the WindowManager (as opposed to the app's root view
     37     // hierarchy) causes a ThreadedRenderer and EGL allocations under the cover.
     38     // We use a TextView here to trigger the use case, but we could use any
     39     // other kind of view as well.
     40     WindowManager wm = context.getSystemService(WindowManager.class);
     41     WindowManager.LayoutParams layout = new WindowManager.LayoutParams();
     42     layout.width = width;
     43     layout.height = height;
     44     wm.addView(mTextView, layout);
     45 
     46     mTextView.post(new CycleRunnable());
     47   }
     48 
     49   // To force as many graphics buffers as will ever be used to actually be
     50   // used, we cycle the text of the text view a handful of times right
     51   // when things start up.
     52   private class CycleRunnable implements Runnable {
     53     private int mCycles = 0;
     54 
     55     public void run() {
     56       if (mCycles < 10) {
     57         mCycles++;
     58         mTextView.setText("TRU " + mCycles);
     59         mTextView.post(this);
     60       }
     61     }
     62   }
     63 }
     64 
     65