Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(173)

Side by Side Diff: src/gpu/GrTexture.cpp

Issue 858123002: Add specialized content key class for resources. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: remove default template arg Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/gpu/GrStencilAndCoverTextContext.cpp ('k') | src/gpu/GrTexturePriv.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2011 Google Inc. 3 * Copyright 2011 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 #include "GrContext.h" 9 #include "GrContext.h"
10 #include "GrDrawTargetCaps.h" 10 #include "GrDrawTargetCaps.h"
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 SkASSERT(fDesc.fSampleCnt == this->asRenderTarget()->numSamples()); 59 SkASSERT(fDesc.fSampleCnt == this->asRenderTarget()->numSamples());
60 } else { 60 } else {
61 SkASSERT(0 == (fDesc.fFlags & kRenderTarget_GrSurfaceFlag)); 61 SkASSERT(0 == (fDesc.fFlags & kRenderTarget_GrSurfaceFlag));
62 SkASSERT(0 == (fDesc.fFlags & kNoStencil_GrSurfaceFlag)); 62 SkASSERT(0 == (fDesc.fFlags & kNoStencil_GrSurfaceFlag));
63 SkASSERT(0 == fDesc.fSampleCnt); 63 SkASSERT(0 == fDesc.fSampleCnt);
64 } 64 }
65 } 65 }
66 66
67 ////////////////////////////////////////////////////////////////////////////// 67 //////////////////////////////////////////////////////////////////////////////
68 68
69 // These flags need to fit in a GrResourceKey::ResourceFlags so they can be fold ed into the texture
70 // key
71 enum TextureFlags {
72 /**
73 * The kStretchToPOT bit is set when the texture is NPOT and is being repeat ed but the
74 * hardware doesn't support that feature.
75 */
76 kStretchToPOT_TextureFlag = 0x1,
77 /**
78 * The kBilerp bit can only be set when the kStretchToPOT flag is set and in dicates whether the
79 * stretched texture should be bilerped.
80 */
81 kBilerp_TextureFlag = 0x2,
82 };
83
84 namespace { 69 namespace {
85 GrResourceKey::ResourceFlags get_texture_flags(const GrGpu* gpu,
86 const GrTextureParams* params,
87 const GrSurfaceDesc& desc) {
88 GrResourceKey::ResourceFlags flags = 0;
89 bool tiled = params && params->isTiled();
90 if (tiled && !gpu->caps()->npotTextureTileSupport()) {
91 if (!SkIsPow2(desc.fWidth) || !SkIsPow2(desc.fHeight)) {
92 flags |= kStretchToPOT_TextureFlag;
93 switch(params->filterMode()) {
94 case GrTextureParams::kNone_FilterMode:
95 break;
96 case GrTextureParams::kBilerp_FilterMode:
97 case GrTextureParams::kMipMap_FilterMode:
98 flags |= kBilerp_TextureFlag;
99 break;
100 }
101 }
102 }
103 return flags;
104 }
105 70
106 // FIXME: This should be refactored with the code in gl/GrGLGpu.cpp. 71 // FIXME: This should be refactored with the code in gl/GrGLGpu.cpp.
107 GrSurfaceOrigin resolve_origin(const GrSurfaceDesc& desc) { 72 GrSurfaceOrigin resolve_origin(const GrSurfaceDesc& desc) {
108 // By default, GrRenderTargets are GL's normal orientation so that they 73 // By default, GrRenderTargets are GL's normal orientation so that they
109 // can be drawn to by the outside world without the client having 74 // can be drawn to by the outside world without the client having
110 // to render upside down. 75 // to render upside down.
111 bool renderTarget = 0 != (desc.fFlags & kRenderTarget_GrSurfaceFlag); 76 bool renderTarget = 0 != (desc.fFlags & kRenderTarget_GrSurfaceFlag);
112 if (kDefault_GrSurfaceOrigin == desc.fOrigin) { 77 if (kDefault_GrSurfaceOrigin == desc.fOrigin) {
113 return renderTarget ? kBottomLeft_GrSurfaceOrigin : kTopLeft_GrSurfaceOr igin; 78 return renderTarget ? kBottomLeft_GrSurfaceOrigin : kTopLeft_GrSurfaceOr igin;
114 } else { 79 } else {
(...skipping 10 matching lines...) Expand all
125 if (kCached_LifeCycle == lifeCycle) { 90 if (kCached_LifeCycle == lifeCycle) {
126 GrScratchKey key; 91 GrScratchKey key;
127 GrTexturePriv::ComputeScratchKey(desc, &key); 92 GrTexturePriv::ComputeScratchKey(desc, &key);
128 this->setScratchKey(key); 93 this->setScratchKey(key);
129 } 94 }
130 // only make sense if alloc size is pow2 95 // only make sense if alloc size is pow2
131 fShiftFixedX = 31 - SkCLZ(fDesc.fWidth); 96 fShiftFixedX = 31 - SkCLZ(fDesc.fWidth);
132 fShiftFixedY = 31 - SkCLZ(fDesc.fHeight); 97 fShiftFixedY = 31 - SkCLZ(fDesc.fHeight);
133 } 98 }
134 99
135 GrResourceKey GrTexturePriv::ComputeKey(const GrGpu* gpu,
136 const GrTextureParams* params,
137 const GrSurfaceDesc& desc,
138 const GrCacheID& cacheID) {
139 GrResourceKey::ResourceFlags flags = get_texture_flags(gpu, params, desc);
140 return GrResourceKey(cacheID, flags);
141 }
142
143 void GrTexturePriv::ComputeScratchKey(const GrSurfaceDesc& desc, GrScratchKey* k ey) { 100 void GrTexturePriv::ComputeScratchKey(const GrSurfaceDesc& desc, GrScratchKey* k ey) {
144 static const GrScratchKey::ResourceType kType = GrScratchKey::GenerateResour ceType(); 101 static const GrScratchKey::ResourceType kType = GrScratchKey::GenerateResour ceType();
145 102
146 GrScratchKey::Builder builder(key, kType, 2); 103 GrScratchKey::Builder builder(key, kType, 2);
147 104
148 GrSurfaceOrigin origin = resolve_origin(desc); 105 GrSurfaceOrigin origin = resolve_origin(desc);
149 uint32_t flags = desc.fFlags & ~kCheckAllocation_GrSurfaceFlag; 106 uint32_t flags = desc.fFlags & ~kCheckAllocation_GrSurfaceFlag;
150 107
151 SkASSERT(desc.fWidth <= SK_MaxU16); 108 SkASSERT(desc.fWidth <= SK_MaxU16);
152 SkASSERT(desc.fHeight <= SK_MaxU16); 109 SkASSERT(desc.fHeight <= SK_MaxU16);
153 SkASSERT(static_cast<int>(desc.fConfig) < (1 << 6)); 110 SkASSERT(static_cast<int>(desc.fConfig) < (1 << 6));
154 SkASSERT(desc.fSampleCnt < (1 << 8)); 111 SkASSERT(desc.fSampleCnt < (1 << 8));
155 SkASSERT(flags < (1 << 10)); 112 SkASSERT(flags < (1 << 10));
156 SkASSERT(static_cast<int>(origin) < (1 << 8)); 113 SkASSERT(static_cast<int>(origin) < (1 << 8));
157 114
158 builder[0] = desc.fWidth | (desc.fHeight << 16); 115 builder[0] = desc.fWidth | (desc.fHeight << 16);
159 builder[1] = desc.fConfig | (desc.fSampleCnt << 6) | (flags << 14) | (origin << 24); 116 builder[1] = desc.fConfig | (desc.fSampleCnt << 6) | (flags << 14) | (origin << 24);
160 } 117 }
161
162 bool GrTexturePriv::NeedsResizing(const GrResourceKey& key) {
163 return SkToBool(key.getResourceFlags() & kStretchToPOT_TextureFlag);
164 }
165
166 bool GrTexturePriv::NeedsBilerp(const GrResourceKey& key) {
167 return SkToBool(key.getResourceFlags() & kBilerp_TextureFlag);
168 }
OLDNEW
« no previous file with comments | « src/gpu/GrStencilAndCoverTextContext.cpp ('k') | src/gpu/GrTexturePriv.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698