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 | |
Robert Phillips | a4c41b3 | 2017-03-15 13:02:45 -0400 | [diff] [blame] | 10 | #include "GrTexturePriv.h" |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 11 | |
robertphillips | 8abb370 | 2016-08-31 14:04:06 -0700 | [diff] [blame] | 12 | GrTextureProxy::GrTextureProxy(const GrSurfaceDesc& srcDesc, SkBackingFit fit, SkBudgeted budgeted, |
Robert Phillips | c787e49 | 2017-02-28 11:26:32 -0500 | [diff] [blame] | 13 | const void* srcData, size_t /*rowBytes*/, uint32_t flags) |
Brian Salomon | bb5711a | 2017-05-17 13:49:59 -0400 | [diff] [blame] | 14 | : INHERITED(srcDesc, fit, budgeted, flags) |
Brian Salomon | 081e0e6 | 2017-05-17 14:27:58 -0400 | [diff] [blame] | 15 | , fIsMipMapped(srcDesc.fIsMipMapped) |
| 16 | , fMipColorMode(SkDestinationSurfaceColorMode::kLegacy) { |
Brian Salomon | bb5711a | 2017-05-17 13:49:59 -0400 | [diff] [blame] | 17 | SkASSERT(!srcData); // currently handled in Make() |
robertphillips | 8abb370 | 2016-08-31 14:04:06 -0700 | [diff] [blame] | 18 | } |
| 19 | |
Robert Phillips | 6af2a66 | 2017-07-25 14:11:29 +0000 | [diff] [blame^] | 20 | GrTextureProxy::GrTextureProxy(sk_sp<GrSurface> surf) |
| 21 | : INHERITED(std::move(surf), SkBackingFit::kExact) |
Brian Salomon | 081e0e6 | 2017-05-17 14:27:58 -0400 | [diff] [blame] | 22 | , fIsMipMapped(fTarget->asTexture()->texturePriv().hasMipMaps()) |
Robert Phillips | eee4d6e | 2017-06-05 09:26:07 -0400 | [diff] [blame] | 23 | , fMipColorMode(fTarget->asTexture()->texturePriv().mipColorMode()) { |
| 24 | } |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 25 | |
Robert Phillips | eee4d6e | 2017-06-05 09:26:07 -0400 | [diff] [blame] | 26 | bool GrTextureProxy::instantiate(GrResourceProvider* resourceProvider) { |
| 27 | if (!this->instantiateImpl(resourceProvider, 0, kNone_GrSurfaceFlags, fIsMipMapped, |
| 28 | fMipColorMode)) { |
| 29 | return false; |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 30 | } |
Robert Phillips | eee4d6e | 2017-06-05 09:26:07 -0400 | [diff] [blame] | 31 | |
| 32 | SkASSERT(fTarget->asTexture()); |
| 33 | return true; |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 34 | } |
| 35 | |
Robert Phillips | 5af44de | 2017-07-18 14:49:38 -0400 | [diff] [blame] | 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 | |
Robert Phillips | a4c41b3 | 2017-03-15 13:02:45 -0400 | [diff] [blame] | 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 | |
Robert Phillips | 49081d1 | 2017-05-08 13:41:35 -0400 | [diff] [blame] | 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 | |
Brian Salomon | bb5711a | 2017-05-17 13:49:59 -0400 | [diff] [blame] | 74 | size_t GrTextureProxy::onUninstantiatedGpuMemorySize() const { |
Robert Phillips | 29e52f1 | 2016-11-03 10:19:14 -0400 | [diff] [blame] | 75 | static const bool kHasMipMaps = true; |
Brian Salomon | bb5711a | 2017-05-17 13:49:59 -0400 | [diff] [blame] | 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); |
Robert Phillips | 8bc06d0 | 2016-11-01 17:28:40 -0400 | [diff] [blame] | 80 | } |