Home | History | Annotate | Download | only in gpu
      1 /*
      2  * Copyright 2016 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 "GrTextureRenderTargetProxy.h"
      9 
     10 // Deferred version
     11 // This class is virtually derived from GrSurfaceProxy (via both GrTextureProxy and
     12 // GrRenderTargetProxy) so its constructor must be explicitly called.
     13 GrTextureRenderTargetProxy::GrTextureRenderTargetProxy(const GrCaps& caps,
     14                                                        const GrSurfaceDesc& desc,
     15                                                        SkBackingFit fit,
     16                                                        SkBudgeted budgeted,
     17                                                        uint32_t flags)
     18     : GrSurfaceProxy(desc, fit, budgeted, flags)
     19     // for now textures w/ data are always wrapped
     20     , GrTextureProxy(desc, fit, budgeted, nullptr, 0, flags)
     21     , GrRenderTargetProxy(caps, desc, fit, budgeted, flags) {
     22 }
     23 
     24 // Wrapped version
     25 // This class is virtually derived from GrSurfaceProxy (via both GrTextureProxy and
     26 // GrRenderTargetProxy) so its constructor must be explicitly called.
     27 GrTextureRenderTargetProxy::GrTextureRenderTargetProxy(sk_sp<GrSurface> surf)
     28     : GrSurfaceProxy(surf, SkBackingFit::kExact)
     29     , GrTextureProxy(surf)
     30     , GrRenderTargetProxy(surf) {
     31     SkASSERT(surf->asTexture());
     32     SkASSERT(surf->asRenderTarget());
     33 }
     34 
     35 size_t GrTextureRenderTargetProxy::onUninstantiatedGpuMemorySize() const {
     36     int colorSamplesPerPixel = this->numColorSamples() + 1;
     37 
     38     static const bool kHasMipMaps = true;
     39     // TODO: add tracking of mipmap state to improve the estimate. We track whether we are created
     40     // with mip maps but not whether a texture read from the proxy will lazily generate mip maps.
     41 
     42     // TODO: do we have enough information to improve this worst case estimate?
     43     return GrSurface::ComputeSize(fConfig, fWidth, fHeight, colorSamplesPerPixel, kHasMipMaps,
     44                                   SkBackingFit::kApprox == fFit);
     45 }
     46 
     47 bool GrTextureRenderTargetProxy::instantiate(GrResourceProvider* resourceProvider) {
     48     static constexpr GrSurfaceFlags kFlags = kRenderTarget_GrSurfaceFlag;
     49 
     50     if (!this->instantiateImpl(resourceProvider, this->numStencilSamples(), kFlags,
     51                                this->isMipMapped(), this->mipColorMode())) {
     52         return false;
     53     }
     54     SkASSERT(fTarget->asRenderTarget());
     55     SkASSERT(fTarget->asTexture());
     56 
     57     return true;
     58 }
     59 
     60 sk_sp<GrSurface> GrTextureRenderTargetProxy::createSurface(
     61                                                     GrResourceProvider* resourceProvider) const {
     62     static constexpr GrSurfaceFlags kFlags = kRenderTarget_GrSurfaceFlag;
     63 
     64     sk_sp<GrSurface> surface = this->createSurfaceImpl(resourceProvider, this->numStencilSamples(),
     65                                                        kFlags, this->isMipMapped(),
     66                                                        this->mipColorMode());
     67     if (!surface) {
     68         return nullptr;
     69     }
     70     SkASSERT(surface->asRenderTarget());
     71     SkASSERT(surface->asTexture());
     72 
     73     return surface;
     74 }
     75 
     76