GrTextureRenderTargetProxy.cpp revision 76d640d14ea78e1f827a2f545e7f0729cdc2896f
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. 13GrTextureRenderTargetProxy::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. 27GrTextureRenderTargetProxy::GrTextureRenderTargetProxy(sk_sp<GrSurface> surf, 28 GrSurfaceOrigin origin) 29 : GrSurfaceProxy(surf, origin, SkBackingFit::kExact) 30 , GrTextureProxy(surf, origin) 31 , GrRenderTargetProxy(surf, origin) { 32 SkASSERT(surf->asTexture()); 33 SkASSERT(surf->asRenderTarget()); 34} 35 36size_t GrTextureRenderTargetProxy::onUninstantiatedGpuMemorySize() const { 37 int colorSamplesPerPixel = this->numColorSamples() + 1; 38 39 static const bool kHasMipMaps = true; 40 // TODO: add tracking of mipmap state to improve the estimate. We track whether we are created 41 // with mip maps but not whether a texture read from the proxy will lazily generate mip maps. 42 43 // TODO: do we have enough information to improve this worst case estimate? 44 return GrSurface::ComputeSize(fConfig, fWidth, fHeight, colorSamplesPerPixel, kHasMipMaps, 45 SkBackingFit::kApprox == fFit); 46} 47 48bool GrTextureRenderTargetProxy::instantiate(GrResourceProvider* resourceProvider) { 49 static constexpr GrSurfaceFlags kFlags = kRenderTarget_GrSurfaceFlag; 50 51 if (!this->instantiateImpl(resourceProvider, this->numStencilSamples(), this->needsStencil(), 52 kFlags, this->isMipMapped(), this->mipColorMode())) { 53 return false; 54 } 55 SkASSERT(fTarget->asRenderTarget()); 56 SkASSERT(fTarget->asTexture()); 57 58 return true; 59} 60 61sk_sp<GrSurface> GrTextureRenderTargetProxy::createSurface( 62 GrResourceProvider* resourceProvider) const { 63 static constexpr GrSurfaceFlags kFlags = kRenderTarget_GrSurfaceFlag; 64 65 sk_sp<GrSurface> surface = this->createSurfaceImpl(resourceProvider, this->numStencilSamples(), 66 this->needsStencil(), kFlags, 67 this->isMipMapped(), this->mipColorMode()); 68 if (!surface) { 69 return nullptr; 70 } 71 SkASSERT(surface->asRenderTarget()); 72 SkASSERT(surface->asTexture()); 73 74 return surface; 75} 76 77