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

Unified Diff: src/gpu/GrTexture.cpp

Issue 815833004: Add a simpler key type for scratch resource keys. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: final fix Created 6 years 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/gpu/GrStencilBuffer.cpp ('k') | src/gpu/GrTexturePriv.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/gpu/GrTexture.cpp
diff --git a/src/gpu/GrTexture.cpp b/src/gpu/GrTexture.cpp
index e5d0fcc0323764161acd1eb37d54cf89c8ede0eb..eb518f5635ae2095f7a816296a74da104cd73d70 100644
--- a/src/gpu/GrTexture.cpp
+++ b/src/gpu/GrTexture.cpp
@@ -9,6 +9,7 @@
#include "GrContext.h"
#include "GrDrawTargetCaps.h"
#include "GrGpu.h"
+#include "GrResourceKey.h"
#include "GrTexture.h"
#include "GrTexturePriv.h"
@@ -122,7 +123,9 @@ GrTexture::GrTexture(GrGpu* gpu, bool isWrapped, const GrSurfaceDesc& desc)
, fMipMapsStatus(kNotAllocated_MipMapsStatus) {
if (!isWrapped) {
- this->setScratchKey(GrTexturePriv::ComputeScratchKey(desc));
+ GrScratchKey key;
+ GrTexturePriv::ComputeScratchKey(desc, &key);
+ this->setScratchKey(key);
}
// only make sense if alloc size is pow2
fShiftFixedX = 31 - SkCLZ(fDesc.fWidth);
@@ -134,26 +137,26 @@ GrResourceKey GrTexturePriv::ComputeKey(const GrGpu* gpu,
const GrSurfaceDesc& desc,
const GrCacheID& cacheID) {
GrResourceKey::ResourceFlags flags = get_texture_flags(gpu, params, desc);
- return GrResourceKey(cacheID, ResourceType(), flags);
+ return GrResourceKey(cacheID, flags);
}
-GrResourceKey GrTexturePriv::ComputeScratchKey(const GrSurfaceDesc& desc) {
- GrCacheID::Key idKey;
- // Instead of a client-provided key of the texture contents we create a key from the
- // descriptor.
- GR_STATIC_ASSERT(sizeof(idKey) >= 16);
- SkASSERT(desc.fHeight < (1 << 16));
- SkASSERT(desc.fWidth < (1 << 16));
- idKey.fData32[0] = (desc.fWidth) | (desc.fHeight << 16);
- idKey.fData32[1] = desc.fConfig | desc.fSampleCnt << 16;
- idKey.fData32[2] = desc.fFlags;
- idKey.fData32[3] = resolve_origin(desc); // Only needs 2 bits actually
- static const int kPadSize = sizeof(idKey) - 16;
- GR_STATIC_ASSERT(kPadSize >= 0);
- memset(idKey.fData8 + 16, 0, kPadSize);
-
- GrCacheID cacheID(GrResourceKey::ScratchDomain(), idKey);
- return GrResourceKey(cacheID, ResourceType(), 0);
+void GrTexturePriv::ComputeScratchKey(const GrSurfaceDesc& desc, GrScratchKey* key) {
+ static const GrScratchKey::ResourceType kType = GrScratchKey::GenerateResourceType();
+
+ GrScratchKey::Builder builder(key, kType, 2);
+
+ GrSurfaceOrigin origin = resolve_origin(desc);
+ uint32_t flags = desc.fFlags & ~kCheckAllocation_GrSurfaceFlag;
+
+ SkASSERT(desc.fWidth <= SK_MaxU16);
+ SkASSERT(desc.fHeight <= SK_MaxU16);
+ SkASSERT(static_cast<int>(desc.fConfig) < (1 << 6));
+ SkASSERT(desc.fSampleCnt < (1 << 8));
+ SkASSERT(flags < (1 << 10));
+ SkASSERT(static_cast<int>(origin) < (1 << 8));
+
+ builder[0] = desc.fWidth | (desc.fHeight << 16);
+ builder[1] = desc.fConfig | (desc.fSampleCnt << 6) | (flags << 14) | (origin << 24);
}
bool GrTexturePriv::NeedsResizing(const GrResourceKey& key) {
« no previous file with comments | « src/gpu/GrStencilBuffer.cpp ('k') | src/gpu/GrTexturePriv.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698