robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 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 | |
Brian Osman | 32342f0 | 2017-03-04 08:12:46 -0500 | [diff] [blame] | 10 | #include "GrResourceProvider.h" |
Robert Phillips | a4c41b3 | 2017-03-15 13:02:45 -0400 | [diff] [blame] | 11 | #include "GrTexturePriv.h" |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 12 | |
robertphillips | 8abb370 | 2016-08-31 14:04:06 -0700 | [diff] [blame] | 13 | GrTextureProxy::GrTextureProxy(const GrSurfaceDesc& srcDesc, SkBackingFit fit, SkBudgeted budgeted, |
Robert Phillips | c787e49 | 2017-02-28 11:26:32 -0500 | [diff] [blame] | 14 | const void* srcData, size_t /*rowBytes*/, uint32_t flags) |
Brian Salomon | bb5711a | 2017-05-17 13:49:59 -0400 | [diff] [blame^] | 15 | : INHERITED(srcDesc, fit, budgeted, flags) |
| 16 | , fIsMipMapped(srcDesc.fIsMipMapped) { |
| 17 | SkASSERT(!srcData); // currently handled in Make() |
robertphillips | 8abb370 | 2016-08-31 14:04:06 -0700 | [diff] [blame] | 18 | } |
| 19 | |
Robert Phillips | 3743013 | 2016-11-09 06:50:43 -0500 | [diff] [blame] | 20 | GrTextureProxy::GrTextureProxy(sk_sp<GrSurface> surf) |
Brian Salomon | bb5711a | 2017-05-17 13:49:59 -0400 | [diff] [blame^] | 21 | : INHERITED(std::move(surf), SkBackingFit::kExact) |
| 22 | , fIsMipMapped(fTarget->asTexture()->texturePriv().hasMipMaps()) {} |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 23 | |
Brian Salomon | bb5711a | 2017-05-17 13:49:59 -0400 | [diff] [blame^] | 24 | GrSurface* GrTextureProxy::instantiate(GrResourceProvider* resourceProvider) { |
| 25 | GrSurface* surf = |
| 26 | this->instantiateImpl(resourceProvider, 0, kNone_GrSurfaceFlags, fIsMipMapped); |
Robert Phillips | eaa8625 | 2016-11-08 13:49:39 +0000 | [diff] [blame] | 27 | if (!surf) { |
| 28 | return nullptr; |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 29 | } |
Brian Salomon | bb5711a | 2017-05-17 13:49:59 -0400 | [diff] [blame^] | 30 | SkASSERT(surf->asTexture()); |
| 31 | return surf; |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 32 | } |
| 33 | |
Robert Phillips | a4c41b3 | 2017-03-15 13:02:45 -0400 | [diff] [blame] | 34 | void 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 Phillips | 49081d1 | 2017-05-08 13:41:35 -0400 | [diff] [blame] | 44 | // This method parallels the highest_filter_mode functions in GrGLTexture & GrVkTexture. |
| 45 | GrSamplerParams::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 Salomon | bb5711a | 2017-05-17 13:49:59 -0400 | [diff] [blame^] | 61 | size_t GrTextureProxy::onUninstantiatedGpuMemorySize() const { |
Robert Phillips | 29e52f1 | 2016-11-03 10:19:14 -0400 | [diff] [blame] | 62 | static const bool kHasMipMaps = true; |
Brian Salomon | bb5711a | 2017-05-17 13:49:59 -0400 | [diff] [blame^] | 63 | // 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 Phillips | 8bc06d0 | 2016-11-01 17:28:40 -0400 | [diff] [blame] | 67 | } |