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 "GrTextureProxy.h"
      9 
     10 #include "GrTexturePriv.h"
     11 
     12 GrTextureProxy::GrTextureProxy(const GrSurfaceDesc& srcDesc, SkBackingFit fit, SkBudgeted budgeted,
     13                                const void* srcData, size_t /*rowBytes*/, uint32_t flags)
     14         : INHERITED(srcDesc, fit, budgeted, flags)
     15         , fIsMipMapped(srcDesc.fIsMipMapped)
     16         , fMipColorMode(SkDestinationSurfaceColorMode::kLegacy) {
     17     SkASSERT(!srcData);  // currently handled in Make()
     18 }
     19 
     20 GrTextureProxy::GrTextureProxy(sk_sp<GrSurface> surf)
     21         : INHERITED(std::move(surf), SkBackingFit::kExact)
     22         , fIsMipMapped(fTarget->asTexture()->texturePriv().hasMipMaps())
     23         , fMipColorMode(fTarget->asTexture()->texturePriv().mipColorMode()) {
     24 }
     25 
     26 bool GrTextureProxy::instantiate(GrResourceProvider* resourceProvider) {
     27     if (!this->instantiateImpl(resourceProvider, 0, kNone_GrSurfaceFlags, fIsMipMapped,
     28                                fMipColorMode)) {
     29         return false;
     30     }
     31 
     32     SkASSERT(fTarget->asTexture());
     33     return true;
     34 }
     35 
     36 sk_sp<GrSurface> GrTextureProxy::createSurface(GrResourceProvider* resourceProvider) const {
     37     sk_sp<GrSurface> surface= this->createSurfaceImpl(resourceProvider, 0, kNone_GrSurfaceFlags,
     38                                                       fIsMipMapped, fMipColorMode);
     39     if (!surface) {
     40         return nullptr;
     41     }
     42 
     43     SkASSERT(surface->asTexture());
     44     return surface;
     45 }
     46 
     47 void GrTextureProxy::setMipColorMode(SkDestinationSurfaceColorMode colorMode) {
     48     SkASSERT(fTarget || fTarget->asTexture());
     49 
     50     if (fTarget) {
     51         fTarget->asTexture()->texturePriv().setMipColorMode(colorMode);
     52     }
     53 
     54     fMipColorMode = colorMode;
     55 }
     56 
     57 // This method parallels the highest_filter_mode functions in GrGLTexture & GrVkTexture.
     58 GrSamplerParams::FilterMode GrTextureProxy::highestFilterMode() const {
     59     if (fTarget) {
     60         return fTarget->asTexture()->texturePriv().highestFilterMode();
     61     }
     62 
     63     if (GrPixelConfigIsSint(this->config())) {
     64         // We only ever want to nearest-neighbor sample signed int textures.
     65         return GrSamplerParams::kNone_FilterMode;
     66     }
     67 
     68     // In OpenGL, GR_GL_TEXTURE_RECTANGLE and GR_GL_TEXTURE_EXTERNAL (which have a highest filter
     69     // mode of bilerp) can only be created via wrapping.
     70 
     71     return GrSamplerParams::kMipMap_FilterMode;
     72 }
     73 
     74 size_t GrTextureProxy::onUninstantiatedGpuMemorySize() const {
     75     static const bool kHasMipMaps = true;
     76     // TODO: add tracking of mipmap state to improve the estimate. We track whether we are created
     77     // with mip maps but not whether a texture read from the proxy will lazily generate mip maps.
     78     return GrSurface::ComputeSize(fConfig, fWidth, fHeight, 1, kHasMipMaps,
     79                                   SkBackingFit::kApprox == fFit);
     80 }
     81