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 "GrResourceProvider.h"
11 #include "GrTexturePriv.h"
12 
GrTextureProxy(const GrSurfaceDesc & srcDesc,SkBackingFit fit,SkBudgeted budgeted,const void * srcData,size_t,uint32_t flags)13 GrTextureProxy::GrTextureProxy(const GrSurfaceDesc& srcDesc, SkBackingFit fit, SkBudgeted budgeted,
14                                const void* srcData, size_t /*rowBytes*/, uint32_t flags)
15     : INHERITED(srcDesc, fit, budgeted, flags) {
16     SkASSERT(!srcData);   // currently handled in Make()
17 }
18 
GrTextureProxy(sk_sp<GrSurface> surf)19 GrTextureProxy::GrTextureProxy(sk_sp<GrSurface> surf)
20     : INHERITED(std::move(surf), SkBackingFit::kExact) {
21 }
22 
instantiate(GrResourceProvider * resourceProvider)23 GrTexture* GrTextureProxy::instantiate(GrResourceProvider* resourceProvider) {
24     GrSurface* surf = this->INHERITED::instantiate(resourceProvider);
25     if (!surf) {
26         return nullptr;
27     }
28 
29     return fTarget->asTexture();
30 }
31 
setMipColorMode(SkDestinationSurfaceColorMode colorMode)32 void GrTextureProxy::setMipColorMode(SkDestinationSurfaceColorMode colorMode) {
33     SkASSERT(fTarget || fTarget->asTexture());
34 
35     if (fTarget) {
36         fTarget->asTexture()->texturePriv().setMipColorMode(colorMode);
37     }
38 
39     fMipColorMode = colorMode;
40 }
41 
onGpuMemorySize() const42 size_t GrTextureProxy::onGpuMemorySize() const {
43     if (fTarget) {
44         return fTarget->gpuMemorySize();
45     }
46 
47     static const bool kHasMipMaps = true;
48     // TODO: add tracking of mipmap state to improve the estimate
49     return GrSurface::ComputeSize(fDesc, 1, kHasMipMaps, SkBackingFit::kApprox == fFit);
50 }
51