Home | History | Annotate | Download | only in driver
      1 /*
      2  * Copyright (C) 2011 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 
     18 #include "rsdCore.h"
     19 #include "rsdFrameBuffer.h"
     20 #include "rsdFrameBufferObj.h"
     21 #include "rsdAllocation.h"
     22 
     23 #include "rsContext.h"
     24 #include "rsFBOCache.h"
     25 
     26 #include <GLES2/gl2.h>
     27 #include <GLES2/gl2ext.h>
     28 
     29 using namespace android;
     30 using namespace android::renderscript;
     31 
     32 void setDepthAttachment(const Context *rsc, const FBOCache *fb) {
     33     RsdFrameBufferObj *fbo = (RsdFrameBufferObj*)fb->mHal.drv;
     34 
     35     DrvAllocation *depth = NULL;
     36     if (fb->mHal.state.depthTarget != NULL) {
     37         depth = (DrvAllocation *)fb->mHal.state.depthTarget->mHal.drv;
     38 
     39         if (depth->uploadDeferred) {
     40             rsdAllocationSyncAll(rsc, fb->mHal.state.depthTarget,
     41                                  RS_ALLOCATION_USAGE_SCRIPT);
     42         }
     43     }
     44     fbo->setDepthTarget(depth);
     45 }
     46 
     47 void setColorAttachment(const Context *rsc, const FBOCache *fb) {
     48     RsdFrameBufferObj *fbo = (RsdFrameBufferObj*)fb->mHal.drv;
     49     // Now attach color targets
     50     for (uint32_t i = 0; i < fb->mHal.state.colorTargetsCount; i ++) {
     51         DrvAllocation *color = NULL;
     52         if (fb->mHal.state.colorTargets[i] != NULL) {
     53             color = (DrvAllocation *)fb->mHal.state.colorTargets[i]->mHal.drv;
     54 
     55             if (color->uploadDeferred) {
     56                 rsdAllocationSyncAll(rsc, fb->mHal.state.colorTargets[i],
     57                                      RS_ALLOCATION_USAGE_SCRIPT);
     58             }
     59         }
     60         fbo->setColorTarget(color, i);
     61     }
     62 }
     63 
     64 bool rsdFrameBufferInit(const Context *rsc, const FBOCache *fb) {
     65     RsdFrameBufferObj *fbo = new RsdFrameBufferObj();
     66     if (fbo == NULL) {
     67         return false;
     68     }
     69     fb->mHal.drv = fbo;
     70 
     71     RsdHal *dc = (RsdHal *)rsc->mHal.drv;
     72     dc->gl.currentFrameBuffer = fbo;
     73 
     74     return true;
     75 }
     76 
     77 void rsdFrameBufferSetActive(const Context *rsc, const FBOCache *fb) {
     78     setDepthAttachment(rsc, fb);
     79     setColorAttachment(rsc, fb);
     80 
     81     RsdFrameBufferObj *fbo = (RsdFrameBufferObj *)fb->mHal.drv;
     82     if (fb->mHal.state.colorTargets[0]) {
     83         fbo->setDimensions(fb->mHal.state.colorTargets[0]->getType()->getDimX(),
     84                            fb->mHal.state.colorTargets[0]->getType()->getDimY());
     85     } else if (fb->mHal.state.depthTarget) {
     86         fbo->setDimensions(fb->mHal.state.depthTarget->getType()->getDimX(),
     87                            fb->mHal.state.depthTarget->getType()->getDimY());
     88     }
     89 
     90     fbo->setActive(rsc);
     91 }
     92 
     93 void rsdFrameBufferDestroy(const Context *rsc, const FBOCache *fb) {
     94     RsdFrameBufferObj *fbo = (RsdFrameBufferObj *)fb->mHal.drv;
     95     delete fbo;
     96     fb->mHal.drv = NULL;
     97 }
     98 
     99 
    100