blob: 7ecd50bee85b1568c4f9911c7c87ec7edf68af86 [file] [log] [blame]
robertphillips76948d42016-05-04 12:47:41 -07001/*
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
Brian Osman32342f02017-03-04 08:12:46 -050010#include "GrResourceProvider.h"
Robert Phillipsa4c41b32017-03-15 13:02:45 -040011#include "GrTexturePriv.h"
robertphillips76948d42016-05-04 12:47:41 -070012
robertphillips8abb3702016-08-31 14:04:06 -070013GrTextureProxy::GrTextureProxy(const GrSurfaceDesc& srcDesc, SkBackingFit fit, SkBudgeted budgeted,
Robert Phillipsc787e492017-02-28 11:26:32 -050014 const void* srcData, size_t /*rowBytes*/, uint32_t flags)
Brian Salomonbb5711a2017-05-17 13:49:59 -040015 : INHERITED(srcDesc, fit, budgeted, flags)
16 , fIsMipMapped(srcDesc.fIsMipMapped) {
17 SkASSERT(!srcData); // currently handled in Make()
robertphillips8abb3702016-08-31 14:04:06 -070018}
19
Robert Phillips37430132016-11-09 06:50:43 -050020GrTextureProxy::GrTextureProxy(sk_sp<GrSurface> surf)
Brian Salomonbb5711a2017-05-17 13:49:59 -040021 : INHERITED(std::move(surf), SkBackingFit::kExact)
22 , fIsMipMapped(fTarget->asTexture()->texturePriv().hasMipMaps()) {}
robertphillips76948d42016-05-04 12:47:41 -070023
Brian Salomonbb5711a2017-05-17 13:49:59 -040024GrSurface* GrTextureProxy::instantiate(GrResourceProvider* resourceProvider) {
25 GrSurface* surf =
26 this->instantiateImpl(resourceProvider, 0, kNone_GrSurfaceFlags, fIsMipMapped);
Robert Phillipseaa86252016-11-08 13:49:39 +000027 if (!surf) {
28 return nullptr;
robertphillips76948d42016-05-04 12:47:41 -070029 }
Brian Salomonbb5711a2017-05-17 13:49:59 -040030 SkASSERT(surf->asTexture());
31 return surf;
robertphillips76948d42016-05-04 12:47:41 -070032}
33
Robert Phillipsa4c41b32017-03-15 13:02:45 -040034void GrTextureProxy::setMipColorMode(SkDestinationSurfaceColorMode colorMode) {
35 SkASSERT(fTarget || fTarget->asTexture());
36
37 if (fTarget) {
38 fTarget->asTexture()->texturePriv().setMipColorMode(colorMode);
39 }
40
41 fMipColorMode = colorMode;
42}
43
Robert Phillips49081d12017-05-08 13:41:35 -040044// This method parallels the highest_filter_mode functions in GrGLTexture & GrVkTexture.
45GrSamplerParams::FilterMode GrTextureProxy::highestFilterMode() const {
46 if (fTarget) {
47 return fTarget->asTexture()->texturePriv().highestFilterMode();
48 }
49
50 if (GrPixelConfigIsSint(this->config())) {
51 // We only ever want to nearest-neighbor sample signed int textures.
52 return GrSamplerParams::kNone_FilterMode;
53 }
54
55 // In OpenGL, GR_GL_TEXTURE_RECTANGLE and GR_GL_TEXTURE_EXTERNAL (which have a highest filter
56 // mode of bilerp) can only be created via wrapping.
57
58 return GrSamplerParams::kMipMap_FilterMode;
59}
60
Brian Salomonbb5711a2017-05-17 13:49:59 -040061size_t GrTextureProxy::onUninstantiatedGpuMemorySize() const {
Robert Phillips29e52f12016-11-03 10:19:14 -040062 static const bool kHasMipMaps = true;
Brian Salomonbb5711a2017-05-17 13:49:59 -040063 // TODO: add tracking of mipmap state to improve the estimate. We track whether we are created
64 // with mip maps but not whether a texture read from the proxy will lazily generate mip maps.
65 return GrSurface::ComputeSize(fConfig, fWidth, fHeight, 1, kHasMipMaps,
66 SkBackingFit::kApprox == fFit);
Robert Phillips8bc06d02016-11-01 17:28:40 -040067}