Home | History | Annotate | Download | only in SRC
      1 /*
      2  * Copyright (C) 2012 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 %PACKAGE%;
     18 
     19 import android.renderscript.RSSurfaceView;
     20 import android.renderscript.RenderScriptGL;
     21 
     22 import android.content.Context;
     23 import android.view.MotionEvent;
     24 
     25 public class DriverView extends RSSurfaceView {
     26     // Renderscipt context
     27     private RenderScriptGL mRS;
     28     // Script that does the rendering
     29     private DriverRS mRender;
     30 
     31     public DriverView(Context context) {
     32         super(context);
     33         ensureRenderScript();
     34     }
     35 
     36     private void ensureRenderScript() {
     37         if (mRS == null) {
     38             // Initialize renderscript with desired surface characteristics.
     39             // In this case, just use the defaults
     40             RenderScriptGL.SurfaceConfig sc = new RenderScriptGL.SurfaceConfig();
     41             mRS = createRenderScriptGL(sc);
     42             // Create an instance of the script that does the rendering
     43             mRender = new DriverRS();
     44             mRender.init(mRS, getResources());
     45         }
     46     }
     47 
     48     @Override
     49     protected void onAttachedToWindow() {
     50         super.onAttachedToWindow();
     51         ensureRenderScript();
     52     }
     53 
     54     @Override
     55     protected void onDetachedFromWindow() {
     56         // Handle the system event and clean up
     57         mRender = null;
     58         if (mRS != null) {
     59             mRS = null;
     60             destroyRenderScriptGL();
     61         }
     62     }
     63 }
     64 
     65 
     66