blob: 21533df0ee0f833c7f020a7f33d3ed9777483bdc [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
Robert Phillipsa4c41b32017-03-15 13:02:45 -040010#include "GrTexturePriv.h"
robertphillips76948d42016-05-04 12:47:41 -070011
robertphillips8abb3702016-08-31 14:04:06 -070012GrTextureProxy::GrTextureProxy(const GrSurfaceDesc& srcDesc, SkBackingFit fit, SkBudgeted budgeted,
Robert Phillipsc787e492017-02-28 11:26:32 -050013 const void* srcData, size_t /*rowBytes*/, uint32_t flags)
Brian Salomonbb5711a2017-05-17 13:49:59 -040014 : INHERITED(srcDesc, fit, budgeted, flags)
Brian Salomon081e0e62017-05-17 14:27:58 -040015 , fIsMipMapped(srcDesc.fIsMipMapped)
16 , fMipColorMode(SkDestinationSurfaceColorMode::kLegacy) {
Brian Salomonbb5711a2017-05-17 13:49:59 -040017 SkASSERT(!srcData); // currently handled in Make()
robertphillips8abb3702016-08-31 14:04:06 -070018}
19
Robert Phillips066f0202017-07-25 10:16:35 -040020GrTextureProxy::GrTextureProxy(sk_sp<GrSurface> surf, GrSurfaceOrigin origin)
21 : INHERITED(std::move(surf), origin, SkBackingFit::kExact)
Brian Salomon081e0e62017-05-17 14:27:58 -040022 , fIsMipMapped(fTarget->asTexture()->texturePriv().hasMipMaps())
Robert Phillipseee4d6e2017-06-05 09:26:07 -040023 , fMipColorMode(fTarget->asTexture()->texturePriv().mipColorMode()) {
24}
robertphillips76948d42016-05-04 12:47:41 -070025
Robert Phillipseee4d6e2017-06-05 09:26:07 -040026bool GrTextureProxy::instantiate(GrResourceProvider* resourceProvider) {
27 if (!this->instantiateImpl(resourceProvider, 0, kNone_GrSurfaceFlags, fIsMipMapped,
28 fMipColorMode)) {
29 return false;
robertphillips76948d42016-05-04 12:47:41 -070030 }
Robert Phillipseee4d6e2017-06-05 09:26:07 -040031
32 SkASSERT(fTarget->asTexture());
33 return true;
robertphillips76948d42016-05-04 12:47:41 -070034}
35
Robert Phillips5af44de2017-07-18 14:49:38 -040036sk_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 Phillipsa4c41b32017-03-15 13:02:45 -040047void 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 Phillips49081d12017-05-08 13:41:35 -040057// This method parallels the highest_filter_mode functions in GrGLTexture & GrVkTexture.
58GrSamplerParams::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 Salomonbb5711a2017-05-17 13:49:59 -040074size_t GrTextureProxy::onUninstantiatedGpuMemorySize() const {
Robert Phillips29e52f12016-11-03 10:19:14 -040075 static const bool kHasMipMaps = true;
Brian Salomonbb5711a2017-05-17 13:49:59 -040076 // 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 Phillips8bc06d02016-11-01 17:28:40 -040080}