Home | History | Annotate | Download | only in ui
      1 /*
      2  * Copyright (C) 2010 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.gallery3d.ui;
     18 
     19 import javax.microedition.khronos.opengles.GL11;
     20 
     21 // RawTexture is used for texture created by glCopyTexImage2D.
     22 //
     23 // It will throw RuntimeException in onBind() if used with a different GL
     24 // context. It is only used internally by copyTexture() in GLCanvas.
     25 class RawTexture extends BasicTexture {
     26 
     27     private RawTexture(GLCanvas canvas, int id) {
     28         super(canvas, id, STATE_LOADED);
     29     }
     30 
     31     public static RawTexture newInstance(GLCanvas canvas) {
     32         int[] textureId = new int[1];
     33         GL11 gl = canvas.getGLInstance();
     34         gl.glGenTextures(1, textureId, 0);
     35         return new RawTexture(canvas, textureId[0]);
     36     }
     37 
     38     @Override
     39     protected boolean onBind(GLCanvas canvas) {
     40         if (mCanvasRef.get() != canvas) {
     41             throw new RuntimeException("cannot bind to different canvas");
     42         }
     43         return true;
     44     }
     45 
     46     public boolean isOpaque() {
     47         return true;
     48     }
     49 
     50     @Override
     51     public void yield() {
     52         // we cannot free the texture because we have no backup.
     53     }
     54 }
     55