Home | History | Annotate | Download | only in glrenderer
      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 com.android.gallery3d.glrenderer;
     18 
     19 // ExtTexture is a texture whose content comes from a external texture.
     20 // Before drawing, setSize() should be called.
     21 public class ExtTexture extends BasicTexture {
     22 
     23     private int mTarget;
     24 
     25     public ExtTexture(GLCanvas canvas, int target) {
     26         GLId glId = canvas.getGLId();
     27         mId = glId.generateTexture();
     28         mTarget = target;
     29     }
     30 
     31     private void uploadToCanvas(GLCanvas canvas) {
     32         canvas.setTextureParameters(this);
     33         setAssociatedCanvas(canvas);
     34         mState = STATE_LOADED;
     35     }
     36 
     37     @Override
     38     protected boolean onBind(GLCanvas canvas) {
     39         if (!isLoaded()) {
     40             uploadToCanvas(canvas);
     41         }
     42 
     43         return true;
     44     }
     45 
     46     @Override
     47     public int getTarget() {
     48         return mTarget;
     49     }
     50 
     51     @Override
     52     public boolean isOpaque() {
     53         return true;
     54     }
     55 
     56     @Override
     57     public void yield() {
     58         // we cannot free the texture because we have no backup.
     59     }
     60 }
     61