Home | History | Annotate | Download | only in gl
      1 /*
      2  * Copyright 2015 Google Inc.
      3  *
      4  * Use of this source code is governed by a BSD-style license that can be
      5  * found in the LICENSE file.
      6  */
      7 
      8 #include "GrGLTextureRenderTarget.h"
      9 
     10 #include "GrContext.h"
     11 #include "GrGLGpu.h"
     12 #include "GrTexturePriv.h"
     13 #include "SkTraceMemoryDump.h"
     14 
     15 GrGLTextureRenderTarget::GrGLTextureRenderTarget(GrGLGpu* gpu,
     16                                                  SkBudgeted budgeted,
     17                                                  const GrSurfaceDesc& desc,
     18                                                  const GrGLTexture::IDDesc& texIDDesc,
     19                                                  const GrGLRenderTarget::IDDesc& rtIDDesc,
     20                                                  GrMipMapsStatus mipMapsStatus)
     21         : GrSurface(gpu, desc)
     22         , GrGLTexture(gpu, desc, texIDDesc, mipMapsStatus)
     23         , GrGLRenderTarget(gpu, desc, rtIDDesc) {
     24     this->registerWithCache(budgeted);
     25 }
     26 
     27 GrGLTextureRenderTarget::GrGLTextureRenderTarget(GrGLGpu* gpu,
     28                                                  const GrSurfaceDesc& desc,
     29                                                  const GrGLTexture::IDDesc& texIDDesc,
     30                                                  const GrGLRenderTarget::IDDesc& rtIDDesc,
     31                                                  GrMipMapsStatus mipMapsStatus)
     32         : GrSurface(gpu, desc)
     33         , GrGLTexture(gpu, desc, texIDDesc, mipMapsStatus)
     34         , GrGLRenderTarget(gpu, desc, rtIDDesc) {
     35     this->registerWithCacheWrapped();
     36 }
     37 
     38 // GrGLTextureRenderTarget must dump both of its superclasses.
     39 void GrGLTextureRenderTarget::dumpMemoryStatistics(
     40     SkTraceMemoryDump* traceMemoryDump) const {
     41   GrGLRenderTarget::dumpMemoryStatistics(traceMemoryDump);
     42 
     43   // Also dump the GrGLTexture's memory. Due to this resource having both a
     44   // texture and a
     45   // renderbuffer component, dump as skia/gpu_resources/resource_#/texture
     46   SkString dumpName("skia/gpu_resources/resource_");
     47   dumpName.appendU32(this->uniqueID().asUInt());
     48   dumpName.append("/texture");
     49 
     50   // Use the texture's gpuMemorySize, not our own, which includes the
     51   // renderbuffer as well.
     52   size_t size = GrGLTexture::gpuMemorySize();
     53 
     54   traceMemoryDump->dumpNumericValue(dumpName.c_str(), "size", "bytes", size);
     55 
     56   if (this->isPurgeable()) {
     57     traceMemoryDump->dumpNumericValue(dumpName.c_str(), "purgeable_size",
     58                                       "bytes", size);
     59   }
     60 
     61   SkString texture_id;
     62   texture_id.appendU32(this->textureID());
     63   traceMemoryDump->setMemoryBacking(dumpName.c_str(), "gl_texture",
     64                                     texture_id.c_str());
     65 }
     66 
     67 bool GrGLTextureRenderTarget::canAttemptStencilAttachment() const {
     68     // The RT FBO of GrGLTextureRenderTarget is never created from a
     69     // wrapped FBO, so we only care about the flag.
     70     return !this->getGpu()->getContext()->caps()->avoidStencilBuffers();
     71 }
     72 
     73 sk_sp<GrGLTextureRenderTarget> GrGLTextureRenderTarget::MakeWrapped(
     74     GrGLGpu* gpu, const GrSurfaceDesc& desc, const GrGLTexture::IDDesc& texIDDesc,
     75     const GrGLRenderTarget::IDDesc& rtIDDesc, GrMipMapsStatus mipMapsStatus)
     76 {
     77     return sk_sp<GrGLTextureRenderTarget>(
     78         new GrGLTextureRenderTarget(gpu, desc, texIDDesc, rtIDDesc, mipMapsStatus));
     79 }
     80 
     81 size_t GrGLTextureRenderTarget::onGpuMemorySize() const {
     82     return GrSurface::ComputeSize(this->config(), this->width(), this->height(),
     83                                     this->numSamplesOwnedPerPixel(),
     84                                     this->texturePriv().mipMapped());
     85 }
     86