Home | History | Annotate | Download | only in gpu
      1 
      2 /*
      3  * Copyright 2011 Google Inc.
      4  *
      5  * Use of this source code is governed by a BSD-style license that can be
      6  * found in the LICENSE file.
      7  */
      8 
      9 
     10 #include "GrResource.h"
     11 #include "GrGpu.h"
     12 
     13 SK_DEFINE_INST_COUNT(GrResource)
     14 
     15 GrResource::GrResource(GrGpu* gpu, bool isWrapped) {
     16     fGpu              = gpu;
     17     fCacheEntry       = NULL;
     18     fDeferredRefCount = 0;
     19     if (isWrapped) {
     20         fFlags = kWrapped_Flag;
     21     } else {
     22         fFlags = 0;
     23     }
     24     fGpu->insertResource(this);
     25 }
     26 
     27 GrResource::~GrResource() {
     28     // subclass should have released this.
     29     GrAssert(0 == fDeferredRefCount);
     30     GrAssert(!this->isValid());
     31 }
     32 
     33 void GrResource::release() {
     34     if (NULL != fGpu) {
     35         this->onRelease();
     36         fGpu->removeResource(this);
     37         fGpu = NULL;
     38     }
     39 }
     40 
     41 void GrResource::abandon() {
     42     if (NULL != fGpu) {
     43         this->onAbandon();
     44         fGpu->removeResource(this);
     45         fGpu = NULL;
     46     }
     47 }
     48 
     49 const GrContext* GrResource::getContext() const {
     50     if (NULL != fGpu) {
     51         return fGpu->getContext();
     52     } else {
     53         return NULL;
     54     }
     55 }
     56 
     57 GrContext* GrResource::getContext() {
     58     if (NULL != fGpu) {
     59         return fGpu->getContext();
     60     } else {
     61         return NULL;
     62     }
     63 }
     64