[graphite] Move GrResourceKey to skgpu::ResourceKey.

We'll want to reuse this key class for Graphite resources as well. There
is nothing special about these keys that is Ganesh specific.

Bug: skia:12754
Change-Id: I39fe5a9968156985865bccbfc4978583120ac2e8
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/487384
Reviewed-by: Michael Ludwig <michaelludwig@google.com>
Commit-Queue: Greg Daniel <egdaniel@google.com>
This commit is contained in:
Greg Daniel 2021-12-21 18:01:47 -05:00 committed by SkCQ
parent c2b31fb04a
commit c1bc0205d9
65 changed files with 498 additions and 468 deletions

View File

@ -26,9 +26,9 @@ public:
this->registerWithCache(SkBudgeted::kYes); this->registerWithCache(SkBudgeted::kYes);
} }
static void ComputeKey(int i, int keyData32Count, GrUniqueKey* key) { static void ComputeKey(int i, int keyData32Count, skgpu::UniqueKey* key) {
static GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDomain(); static skgpu::UniqueKey::Domain kDomain = skgpu::UniqueKey::GenerateDomain();
GrUniqueKey::Builder builder(key, kDomain, keyData32Count); skgpu::UniqueKey::Builder builder(key, kDomain, keyData32Count);
for (int j = 0; j < keyData32Count; ++j) { for (int j = 0; j < keyData32Count; ++j) {
builder[j] = i + j; builder[j] = i + j;
} }
@ -42,7 +42,7 @@ private:
static void populate_cache(GrGpu* gpu, int resourceCount, int keyData32Count) { static void populate_cache(GrGpu* gpu, int resourceCount, int keyData32Count) {
for (int i = 0; i < resourceCount; ++i) { for (int i = 0; i < resourceCount; ++i) {
GrUniqueKey key; skgpu::UniqueKey key;
BenchResource::ComputeKey(i, keyData32Count, &key); BenchResource::ComputeKey(i, keyData32Count, &key);
GrGpuResource* resource = new BenchResource(gpu); GrGpuResource* resource = new BenchResource(gpu);
resource->resourcePriv().setUniqueKey(key); resource->resourcePriv().setUniqueKey(key);
@ -141,7 +141,7 @@ protected:
SkASSERT(CACHE_SIZE_COUNT == cache->getResourceCount()); SkASSERT(CACHE_SIZE_COUNT == cache->getResourceCount());
for (int i = 0; i < loops; ++i) { for (int i = 0; i < loops; ++i) {
for (int k = 0; k < CACHE_SIZE_COUNT; ++k) { for (int k = 0; k < CACHE_SIZE_COUNT; ++k) {
GrUniqueKey key; skgpu::UniqueKey key;
BenchResource::ComputeKey(k, fKeyData32Count, &key); BenchResource::ComputeKey(k, fKeyData32Count, &key);
sk_sp<GrGpuResource> resource(cache->findAndRefUniqueResource(key)); sk_sp<GrGpuResource> resource(cache->findAndRefUniqueResource(key));
SkASSERT(resource); SkASSERT(resource);

View File

@ -27,7 +27,6 @@ skia_gpu_sources = [
"$_include/private/GrGLTypesPriv.h", "$_include/private/GrGLTypesPriv.h",
"$_include/private/GrImageContext.h", "$_include/private/GrImageContext.h",
"$_include/private/GrMtlTypesPriv.h", "$_include/private/GrMtlTypesPriv.h",
"$_include/private/GrResourceKey.h",
"$_include/private/GrSingleOwner.h", "$_include/private/GrSingleOwner.h",
"$_include/private/GrTypesPriv.h", "$_include/private/GrTypesPriv.h",
"$_include/private/chromium/GrSlug.h", "$_include/private/chromium/GrSlug.h",
@ -821,6 +820,8 @@ skia_shared_gpu_sources = [
"$_include/gpu/ShaderErrorHandler.h", "$_include/gpu/ShaderErrorHandler.h",
"$_src/gpu/BufferWriter.h", "$_src/gpu/BufferWriter.h",
"$_src/gpu/KeyBuilder.h", "$_src/gpu/KeyBuilder.h",
"$_src/gpu/ResourceKey.cpp",
"$_src/gpu/ResourceKey.h",
"$_src/gpu/ShaderErrorHandler.cpp", "$_src/gpu/ShaderErrorHandler.cpp",
# tessellate # tessellate

View File

@ -789,9 +789,9 @@ static std::unique_ptr<GrFragmentProcessor> create_profile_effect(GrRecordingCon
// 1 / textureRadius. This is done to avoid overflow in length(). // 1 / textureRadius. This is done to avoid overflow in length().
SkMatrix texM = SkMatrix::Scale(kProfileTextureWidth, 1.f); SkMatrix texM = SkMatrix::Scale(kProfileTextureWidth, 1.f);
static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDomain(); static const skgpu::UniqueKey::Domain kDomain = skgpu::UniqueKey::GenerateDomain();
GrUniqueKey key; skgpu::UniqueKey key;
GrUniqueKey::Builder builder(&key, kDomain, 1, "1-D Circular Blur"); skgpu::UniqueKey::Builder builder(&key, kDomain, 1, "1-D Circular Blur");
builder[0] = sigmaToCircleRRatioFixed; builder[0] = sigmaToCircleRRatioFixed;
builder.finish(); builder.finish();
@ -872,9 +872,9 @@ static std::unique_ptr<GrFragmentProcessor> make_rect_integral_fp(GrRecordingCon
int width = SkGpuBlurUtils::CreateIntegralTable(sixSigma, nullptr); int width = SkGpuBlurUtils::CreateIntegralTable(sixSigma, nullptr);
static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDomain(); static const skgpu::UniqueKey::Domain kDomain = skgpu::UniqueKey::GenerateDomain();
GrUniqueKey key; skgpu::UniqueKey key;
GrUniqueKey::Builder builder(&key, kDomain, 1, "Rect Blur Mask"); skgpu::UniqueKey::Builder builder(&key, kDomain, 1, "Rect Blur Mask");
builder[0] = width; builder[0] = width;
builder.finish(); builder.finish();
@ -1040,13 +1040,13 @@ static std::unique_ptr<GrFragmentProcessor> make_rect_blur(GrRecordingContext* c
static constexpr auto kBlurredRRectMaskOrigin = kTopLeft_GrSurfaceOrigin; static constexpr auto kBlurredRRectMaskOrigin = kTopLeft_GrSurfaceOrigin;
static void make_blurred_rrect_key(GrUniqueKey* key, static void make_blurred_rrect_key(skgpu::UniqueKey* key,
const SkRRect& rrectToDraw, const SkRRect& rrectToDraw,
float xformedSigma) { float xformedSigma) {
SkASSERT(!SkGpuBlurUtils::IsEffectivelyZeroSigma(xformedSigma)); SkASSERT(!SkGpuBlurUtils::IsEffectivelyZeroSigma(xformedSigma));
static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDomain(); static const skgpu::UniqueKey::Domain kDomain = skgpu::UniqueKey::GenerateDomain();
GrUniqueKey::Builder builder(key, kDomain, 9, "RoundRect Blur Mask"); skgpu::UniqueKey::Builder builder(key, kDomain, 9, "RoundRect Blur Mask");
builder[0] = SkScalarCeilToInt(xformedSigma - 1 / 6.0f); builder[0] = SkScalarCeilToInt(xformedSigma - 1 / 6.0f);
int index = 1; int index = 1;
@ -1262,7 +1262,7 @@ static std::unique_ptr<GrFragmentProcessor> find_or_create_rrect_blur_mask_fp(
const SkISize& dimensions, const SkISize& dimensions,
float xformedSigma) { float xformedSigma) {
SkASSERT(!SkGpuBlurUtils::IsEffectivelyZeroSigma(xformedSigma)); SkASSERT(!SkGpuBlurUtils::IsEffectivelyZeroSigma(xformedSigma));
GrUniqueKey key; skgpu::UniqueKey key;
make_blurred_rrect_key(&key, rrectToDraw, xformedSigma); make_blurred_rrect_key(&key, rrectToDraw, xformedSigma);
auto threadSafeCache = rContext->priv().threadSafeCache(); auto threadSafeCache = rContext->priv().threadSafeCache();

View File

@ -21,7 +21,7 @@
#if SK_SUPPORT_GPU #if SK_SUPPORT_GPU
class GrProxyProvider; class GrProxyProvider;
#include "include/private/GrResourceKey.h" #include "src/gpu/ResourceKey.h"
#endif #endif
// Because a single save/restore state can have multiple clips, this class // Because a single save/restore state can have multiple clips, this class
@ -195,7 +195,7 @@ public:
* the element is destroyed because their key is based on this element's gen ID. * the element is destroyed because their key is based on this element's gen ID.
*/ */
void addResourceInvalidationMessage(GrProxyProvider* proxyProvider, void addResourceInvalidationMessage(GrProxyProvider* proxyProvider,
const GrUniqueKey& key) const { const skgpu::UniqueKey& key) const {
SkASSERT(proxyProvider); SkASSERT(proxyProvider);
if (!fProxyProvider) { if (!fProxyProvider) {
@ -238,8 +238,8 @@ public:
uint32_t fGenID; uint32_t fGenID;
#if SK_SUPPORT_GPU #if SK_SUPPORT_GPU
mutable GrProxyProvider* fProxyProvider = nullptr; mutable GrProxyProvider* fProxyProvider = nullptr;
mutable SkTArray<GrUniqueKey> fKeysToInvalidate; mutable SkTArray<skgpu::UniqueKey> fKeysToInvalidate;
#endif #endif
Element(int saveCount) { Element(int saveCount) {
this->initCommon(saveCount, SkClipOp::kIntersect, false); this->initCommon(saveCount, SkClipOp::kIntersect, false);

View File

@ -7,7 +7,6 @@
#include "src/gpu/GrAttachment.h" #include "src/gpu/GrAttachment.h"
#include "include/private/GrResourceKey.h"
#include "src/gpu/GrBackendUtils.h" #include "src/gpu/GrBackendUtils.h"
#include "src/gpu/GrCaps.h" #include "src/gpu/GrCaps.h"
#include "src/gpu/GrDataUtils.h" #include "src/gpu/GrDataUtils.h"
@ -34,7 +33,7 @@ size_t GrAttachment::onGpuMemorySize() const {
return 0; return 0;
} }
static void build_key(GrResourceKey::Builder* builder, static void build_key(skgpu::ResourceKey::Builder* builder,
const GrCaps& caps, const GrCaps& caps,
const GrBackendFormat& format, const GrBackendFormat& format,
SkISize dimensions, SkISize dimensions,
@ -69,10 +68,10 @@ void GrAttachment::ComputeSharedAttachmentUniqueKey(const GrCaps& caps,
GrMipmapped mipmapped, GrMipmapped mipmapped,
GrProtected isProtected, GrProtected isProtected,
GrMemoryless memoryless, GrMemoryless memoryless,
GrUniqueKey* key) { skgpu::UniqueKey* key) {
static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDomain(); static const skgpu::UniqueKey::Domain kDomain = skgpu::UniqueKey::GenerateDomain();
GrUniqueKey::Builder builder(key, kDomain, 5); skgpu::UniqueKey::Builder builder(key, kDomain, 5);
build_key(&builder, caps, format, dimensions, requiredUsage, sampleCnt, mipmapped, isProtected, build_key(&builder, caps, format, dimensions, requiredUsage, sampleCnt, mipmapped, isProtected,
memoryless); memoryless);
} }
@ -85,15 +84,15 @@ void GrAttachment::ComputeScratchKey(const GrCaps& caps,
GrMipmapped mipmapped, GrMipmapped mipmapped,
GrProtected isProtected, GrProtected isProtected,
GrMemoryless memoryless, GrMemoryless memoryless,
GrScratchKey* key) { skgpu::ScratchKey* key) {
static const GrScratchKey::ResourceType kType = GrScratchKey::GenerateResourceType(); static const skgpu::ScratchKey::ResourceType kType = skgpu::ScratchKey::GenerateResourceType();
GrScratchKey::Builder builder(key, kType, 5); skgpu::ScratchKey::Builder builder(key, kType, 5);
build_key(&builder, caps, format, dimensions, requiredUsage, sampleCnt, mipmapped, isProtected, build_key(&builder, caps, format, dimensions, requiredUsage, sampleCnt, mipmapped, isProtected,
memoryless); memoryless);
} }
void GrAttachment::computeScratchKey(GrScratchKey* key) const { void GrAttachment::computeScratchKey(skgpu::ScratchKey* key) const {
if (!SkToBool(fSupportedUsages & UsageFlags::kStencilAttachment)) { if (!SkToBool(fSupportedUsages & UsageFlags::kStencilAttachment)) {
auto isProtected = this->isProtected() ? GrProtected::kYes : GrProtected::kNo; auto isProtected = this->isProtected() ? GrProtected::kYes : GrProtected::kNo;
ComputeScratchKey(*this->getGpu()->caps(), ComputeScratchKey(*this->getGpu()->caps(),

View File

@ -12,7 +12,6 @@
#include "src/gpu/GrSurface.h" #include "src/gpu/GrSurface.h"
class GrRenderTarget; class GrRenderTarget;
class GrResourceKey;
/** /**
* This is a generic attachment class for out GrSurfaces. It always represents a single gpu * This is a generic attachment class for out GrSurfaces. It always represents a single gpu
@ -55,7 +54,7 @@ public:
GrMipmapped mipmapped, GrMipmapped mipmapped,
GrProtected isProtected, GrProtected isProtected,
GrMemoryless memoryless, GrMemoryless memoryless,
GrUniqueKey* key); skgpu::UniqueKey* key);
// TODO: Once attachments start having multiple usages, we'll need to figure out how to search // TODO: Once attachments start having multiple usages, we'll need to figure out how to search
// the cache for an attachment that simply contains the requested usage instead of equaling it. // the cache for an attachment that simply contains the requested usage instead of equaling it.
@ -67,7 +66,7 @@ public:
GrMipmapped mipmapped, GrMipmapped mipmapped,
GrProtected, GrProtected,
GrMemoryless, GrMemoryless,
GrScratchKey* key); skgpu::ScratchKey* key);
protected: protected:
GrAttachment(GrGpu* gpu, SkISize dimensions, UsageFlags supportedUsages, int sampleCnt, GrAttachment(GrGpu* gpu, SkISize dimensions, UsageFlags supportedUsages, int sampleCnt,
@ -82,7 +81,7 @@ protected:
private: private:
size_t onGpuMemorySize() const final; size_t onGpuMemorySize() const final;
void computeScratchKey(GrScratchKey*) const final; void computeScratchKey(skgpu::ScratchKey*) const final;
const char* getResourceType() const override { const char* getResourceType() const override {
if (fSupportedUsages == UsageFlags::kStencilAttachment) { if (fSupportedUsages == UsageFlags::kStencilAttachment) {

View File

@ -142,8 +142,8 @@ GrSurfaceProxyView GrBackendTextureImageGenerator::onGenerateTexture(
} }
fRefHelper->fBorrowingContextID = dContext->directContextID(); fRefHelper->fBorrowingContextID = dContext->directContextID();
if (!fRefHelper->fBorrowedTextureKey.isValid()) { if (!fRefHelper->fBorrowedTextureKey.isValid()) {
static const auto kDomain = GrUniqueKey::GenerateDomain(); static const auto kDomain = skgpu::UniqueKey::GenerateDomain();
GrUniqueKey::Builder builder(&fRefHelper->fBorrowedTextureKey, kDomain, 1); skgpu::UniqueKey::Builder builder(&fRefHelper->fBorrowedTextureKey, kDomain, 1);
builder[0] = this->uniqueID(); builder[0] = this->uniqueID();
} }
fBorrowingMutex.release(); fBorrowingMutex.release();

View File

@ -10,9 +10,9 @@
#include "include/core/SkImageGenerator.h" #include "include/core/SkImageGenerator.h"
#include "include/gpu/GrBackendSurface.h" #include "include/gpu/GrBackendSurface.h"
#include "include/gpu/GrDirectContext.h" #include "include/gpu/GrDirectContext.h"
#include "include/private/GrResourceKey.h"
#include "include/private/SkMutex.h" #include "include/private/SkMutex.h"
#include "src/gpu/GrTexture.h" #include "src/gpu/GrTexture.h"
#include "src/gpu/ResourceKey.h"
class GrSemaphore; class GrSemaphore;
@ -70,7 +70,7 @@ private:
// We use this key so that we don't rewrap the GrBackendTexture in a GrTexture for each // We use this key so that we don't rewrap the GrBackendTexture in a GrTexture for each
// proxy created from this generator for a particular borrowing context. // proxy created from this generator for a particular borrowing context.
GrUniqueKey fBorrowedTextureKey; skgpu::UniqueKey fBorrowedTextureKey;
// There is no ref associated with this pointer. We rely on our atomic bookkeeping with the // There is no ref associated with this pointer. We rely on our atomic bookkeeping with the
// context ID to know when this pointer is valid and safe to use. This is used to make sure // context ID to know when this pointer is valid and safe to use. This is used to make sure
// all uses of the wrapped texture are finished on the borrowing context before we open // all uses of the wrapped texture are finished on the borrowing context before we open

View File

@ -101,7 +101,7 @@ static GrSurfaceProxyView sw_create_filtered_mask(GrRecordingContext* rContext,
const SkIRect& unclippedDevShapeBounds, const SkIRect& unclippedDevShapeBounds,
const SkIRect& clipBounds, const SkIRect& clipBounds,
SkIRect* drawRect, SkIRect* drawRect,
GrUniqueKey* key) { skgpu::UniqueKey* key) {
SkASSERT(filter); SkASSERT(filter);
SkASSERT(!shape.style().applies()); SkASSERT(!shape.style().applies());
@ -283,7 +283,7 @@ static bool get_shape_and_clip_bounds(skgpu::v1::SurfaceDrawContext* sdc,
// The key and clip-bounds are computed together because the caching decision can impact the // The key and clip-bounds are computed together because the caching decision can impact the
// clip-bound - since we only cache un-clipped masks the clip can be removed entirely. // clip-bound - since we only cache un-clipped masks the clip can be removed entirely.
// A 'false' return value indicates that the shape is known to be clipped away. // A 'false' return value indicates that the shape is known to be clipped away.
static bool compute_key_and_clip_bounds(GrUniqueKey* maskKey, static bool compute_key_and_clip_bounds(skgpu::UniqueKey* maskKey,
SkIRect* boundsForClip, SkIRect* boundsForClip,
const GrCaps* caps, const GrCaps* caps,
const SkMatrix& viewMatrix, const SkMatrix& viewMatrix,
@ -326,8 +326,8 @@ static bool compute_key_and_clip_bounds(GrUniqueKey* maskKey,
} }
if (useCache) { if (useCache) {
static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDomain(); static const skgpu::UniqueKey::Domain kDomain = skgpu::UniqueKey::GenerateDomain();
GrUniqueKey::Builder builder(maskKey, kDomain, 5 + 2 + shape.unstyledKeySize(), skgpu::UniqueKey::Builder builder(maskKey, kDomain, 5 + 2 + shape.unstyledKeySize(),
"Mask Filtered Masks"); "Mask Filtered Masks");
// We require the upper left 2x2 of the matrix to match exactly for a cache hit. // We require the upper left 2x2 of the matrix to match exactly for a cache hit.
@ -375,7 +375,7 @@ static GrSurfaceProxyView hw_create_filtered_mask(GrDirectContext* dContext,
const SkIRect& unclippedDevShapeBounds, const SkIRect& unclippedDevShapeBounds,
const SkIRect& clipBounds, const SkIRect& clipBounds,
SkIRect* maskRect, SkIRect* maskRect,
GrUniqueKey* key) { skgpu::UniqueKey* key) {
if (!filter->canFilterMaskGPU(shape, if (!filter->canFilterMaskGPU(shape,
unclippedDevShapeBounds, unclippedDevShapeBounds,
clipBounds, clipBounds,
@ -508,7 +508,7 @@ static void draw_shape_with_mask_filter(GrRecordingContext* rContext,
} }
} }
GrUniqueKey maskKey; skgpu::UniqueKey maskKey;
SkIRect boundsForClip; SkIRect boundsForClip;
if (!compute_key_and_clip_bounds(&maskKey, &boundsForClip, if (!compute_key_and_clip_bounds(&maskKey, &boundsForClip,
sdc->caps(), sdc->caps(),

View File

@ -58,10 +58,11 @@ bool GrGpuBuffer::updateData(const void* src, size_t srcSizeInBytes) {
return result; return result;
} }
void GrGpuBuffer::ComputeScratchKeyForDynamicBuffer(size_t size, GrGpuBufferType intendedType, void GrGpuBuffer::ComputeScratchKeyForDynamicBuffer(size_t size,
GrScratchKey* key) { GrGpuBufferType intendedType,
static const GrScratchKey::ResourceType kType = GrScratchKey::GenerateResourceType(); skgpu::ScratchKey* key) {
GrScratchKey::Builder builder(key, kType, 1 + (sizeof(size_t) + 3) / 4); static const skgpu::ScratchKey::ResourceType kType = skgpu::ScratchKey::GenerateResourceType();
skgpu::ScratchKey::Builder builder(key, kType, 1 + (sizeof(size_t) + 3) / 4);
builder[0] = SkToU32(intendedType); builder[0] = SkToU32(intendedType);
builder[1] = (uint32_t)size; builder[1] = (uint32_t)size;
if (sizeof(size_t) > 4) { if (sizeof(size_t) > 4) {
@ -69,7 +70,7 @@ void GrGpuBuffer::ComputeScratchKeyForDynamicBuffer(size_t size, GrGpuBufferType
} }
} }
void GrGpuBuffer::computeScratchKey(GrScratchKey* key) const { void GrGpuBuffer::computeScratchKey(skgpu::ScratchKey* key) const {
if (SkIsPow2(fSizeInBytes) && kDynamic_GrAccessPattern == fAccessPattern) { if (SkIsPow2(fSizeInBytes) && kDynamic_GrAccessPattern == fAccessPattern) {
ComputeScratchKeyForDynamicBuffer(fSizeInBytes, fIntendedType, key); ComputeScratchKeyForDynamicBuffer(fSizeInBytes, fIntendedType, key);
} }

View File

@ -19,7 +19,7 @@ public:
* Computes a scratch key for a GPU-side buffer with a "dynamic" access pattern. (Buffers with * Computes a scratch key for a GPU-side buffer with a "dynamic" access pattern. (Buffers with
* "static" and "stream" patterns are disqualified by nature from being cached and reused.) * "static" and "stream" patterns are disqualified by nature from being cached and reused.)
*/ */
static void ComputeScratchKeyForDynamicBuffer(size_t size, GrGpuBufferType, GrScratchKey*); static void ComputeScratchKeyForDynamicBuffer(size_t size, GrGpuBufferType, skgpu::ScratchKey*);
GrAccessPattern accessPattern() const { return fAccessPattern; } GrAccessPattern accessPattern() const { return fAccessPattern; }
@ -93,7 +93,7 @@ private:
size_t onGpuMemorySize() const override { return fSizeInBytes; } size_t onGpuMemorySize() const override { return fSizeInBytes; }
const char* getResourceType() const override { return "Buffer Object"; } const char* getResourceType() const override { return "Buffer Object"; }
void computeScratchKey(GrScratchKey* key) const override; void computeScratchKey(skgpu::ScratchKey* key) const override;
size_t fSizeInBytes; size_t fSizeInBytes;
GrAccessPattern fAccessPattern; GrAccessPattern fAccessPattern;

View File

@ -141,7 +141,7 @@ void GrGpuResource::removeUniqueKey() {
get_resource_cache(fGpu)->resourceAccess().removeUniqueKey(this); get_resource_cache(fGpu)->resourceAccess().removeUniqueKey(this);
} }
void GrGpuResource::setUniqueKey(const GrUniqueKey& key) { void GrGpuResource::setUniqueKey(const skgpu::UniqueKey& key) {
SkASSERT(this->internalHasRef()); SkASSERT(this->internalHasRef());
SkASSERT(key.isValid()); SkASSERT(key.isValid());

View File

@ -8,9 +8,9 @@
#ifndef GrGpuResource_DEFINED #ifndef GrGpuResource_DEFINED
#define GrGpuResource_DEFINED #define GrGpuResource_DEFINED
#include "include/private/GrResourceKey.h"
#include "include/private/GrTypesPriv.h" #include "include/private/GrTypesPriv.h"
#include "include/private/SkNoncopyable.h" #include "include/private/SkNoncopyable.h"
#include "src/gpu/ResourceKey.h"
class GrGpu; class GrGpu;
class GrResourceCache; class GrResourceCache;
@ -172,7 +172,7 @@ public:
/** Returns the current unique key for the resource. It will be invalid if the resource has no /** Returns the current unique key for the resource. It will be invalid if the resource has no
associated unique key. */ associated unique key. */
const GrUniqueKey& getUniqueKey() const { return fUniqueKey; } const skgpu::UniqueKey& getUniqueKey() const { return fUniqueKey; }
/** /**
* Internal-only helper class used for manipulations of the resource by the cache. * Internal-only helper class used for manipulations of the resource by the cache.
@ -264,7 +264,7 @@ private:
* resources and populate the scratchKey with the key. * resources and populate the scratchKey with the key.
* By default resources are not recycled as scratch. * By default resources are not recycled as scratch.
**/ **/
virtual void computeScratchKey(GrScratchKey*) const {} virtual void computeScratchKey(skgpu::ScratchKey*) const {}
/** /**
* Removes references to objects in the underlying 3D API without freeing them. * Removes references to objects in the underlying 3D API without freeing them.
@ -280,7 +280,7 @@ private:
virtual size_t onGpuMemorySize() const = 0; virtual size_t onGpuMemorySize() const = 0;
// See comments in CacheAccess and ResourcePriv. // See comments in CacheAccess and ResourcePriv.
void setUniqueKey(const GrUniqueKey&); void setUniqueKey(const skgpu::UniqueKey&);
void removeUniqueKey(); void removeUniqueKey();
void notifyARefCntIsZero(LastRemovedRef removedRef) const; void notifyARefCntIsZero(LastRemovedRef removedRef) const;
void removeScratchKey(); void removeScratchKey();
@ -300,8 +300,8 @@ private:
GrStdSteadyClock::time_point fTimeWhenBecamePurgeable; GrStdSteadyClock::time_point fTimeWhenBecamePurgeable;
static const size_t kInvalidGpuMemorySize = ~static_cast<size_t>(0); static const size_t kInvalidGpuMemorySize = ~static_cast<size_t>(0);
GrScratchKey fScratchKey; skgpu::ScratchKey fScratchKey;
GrUniqueKey fUniqueKey; skgpu::UniqueKey fUniqueKey;
// This is not ref'ed but abandon() or release() will be called before the GrGpu object // This is not ref'ed but abandon() or release() will be called before the GrGpu object
// is destroyed. Those calls set will this to NULL. // is destroyed. Those calls set will this to NULL.

View File

@ -57,7 +57,7 @@ private:
} }
/** Called by the cache to assign a new unique key. */ /** Called by the cache to assign a new unique key. */
void setUniqueKey(const GrUniqueKey& key) { fResource->fUniqueKey = key; } void setUniqueKey(const skgpu::UniqueKey& key) { fResource->fUniqueKey = key; }
/** Is the resource ref'ed */ /** Is the resource ref'ed */
bool hasRef() const { return fResource->hasRef(); } bool hasRef() const { return fResource->hasRef(); }

View File

@ -22,7 +22,7 @@ public:
* removeUniqueKey(). If another resource is using the key then its unique key is removed and * removeUniqueKey(). If another resource is using the key then its unique key is removed and
* this resource takes over the key. * this resource takes over the key.
*/ */
void setUniqueKey(const GrUniqueKey& key) { fResource->setUniqueKey(key); } void setUniqueKey(const skgpu::UniqueKey& key) { fResource->setUniqueKey(key); }
/** Removes the unique key from a resource. If the resource has a scratch key, it may be /** Removes the unique key from a resource. If the resource has a scratch key, it may be
preserved for recycling as scratch. */ preserved for recycling as scratch. */
@ -60,7 +60,7 @@ public:
* Otherwise it returns a key for which isNullScratch is true. The resource may currently be * Otherwise it returns a key for which isNullScratch is true. The resource may currently be
* used as a uniquely keyed resource rather than scratch. Check isScratch(). * used as a uniquely keyed resource rather than scratch. Check isScratch().
*/ */
const GrScratchKey& getScratchKey() const { return fResource->fScratchKey; } const skgpu::ScratchKey& getScratchKey() const { return fResource->fScratchKey; }
/** /**
* If the resource has a scratch key, the key will be removed. Since scratch keys are installed * If the resource has a scratch key, the key will be removed. Since scratch keys are installed

View File

@ -11,7 +11,6 @@
#include "include/core/SkImage.h" #include "include/core/SkImage.h"
#include "include/gpu/GrDirectContext.h" #include "include/gpu/GrDirectContext.h"
#include "include/private/GrImageContext.h" #include "include/private/GrImageContext.h"
#include "include/private/GrResourceKey.h"
#include "include/private/GrSingleOwner.h" #include "include/private/GrSingleOwner.h"
#include "include/private/SkImageInfoPriv.h" #include "include/private/SkImageInfoPriv.h"
#include "src/core/SkAutoPixmapStorage.h" #include "src/core/SkAutoPixmapStorage.h"
@ -50,7 +49,7 @@ GrProxyProvider::~GrProxyProvider() {
} }
} }
bool GrProxyProvider::assignUniqueKeyToProxy(const GrUniqueKey& key, GrTextureProxy* proxy) { bool GrProxyProvider::assignUniqueKeyToProxy(const skgpu::UniqueKey& key, GrTextureProxy* proxy) {
ASSERT_SINGLE_OWNER ASSERT_SINGLE_OWNER
SkASSERT(key.isValid()); SkASSERT(key.isValid());
if (this->isAbandoned() || !proxy) { if (this->isAbandoned() || !proxy) {
@ -102,7 +101,7 @@ void GrProxyProvider::removeUniqueKeyFromProxy(GrTextureProxy* proxy) {
this->processInvalidUniqueKey(proxy->getUniqueKey(), proxy, InvalidateGPUResource::kYes); this->processInvalidUniqueKey(proxy->getUniqueKey(), proxy, InvalidateGPUResource::kYes);
} }
sk_sp<GrTextureProxy> GrProxyProvider::findProxyByUniqueKey(const GrUniqueKey& key) { sk_sp<GrTextureProxy> GrProxyProvider::findProxyByUniqueKey(const skgpu::UniqueKey& key) {
ASSERT_SINGLE_OWNER ASSERT_SINGLE_OWNER
if (this->isAbandoned()) { if (this->isAbandoned()) {
@ -213,7 +212,7 @@ sk_sp<GrTextureProxy> GrProxyProvider::createWrapped(sk_sp<GrTexture> tex,
} }
} }
sk_sp<GrTextureProxy> GrProxyProvider::findOrCreateProxyByUniqueKey(const GrUniqueKey& key, sk_sp<GrTextureProxy> GrProxyProvider::findOrCreateProxyByUniqueKey(const skgpu::UniqueKey& key,
UseAllocator useAllocator) { UseAllocator useAllocator) {
ASSERT_SINGLE_OWNER ASSERT_SINGLE_OWNER
@ -248,10 +247,11 @@ sk_sp<GrTextureProxy> GrProxyProvider::findOrCreateProxyByUniqueKey(const GrUniq
return result; return result;
} }
GrSurfaceProxyView GrProxyProvider::findCachedProxyWithColorTypeFallback(const GrUniqueKey& key, GrSurfaceProxyView GrProxyProvider::findCachedProxyWithColorTypeFallback(
GrSurfaceOrigin origin, const skgpu::UniqueKey& key,
GrColorType ct, GrSurfaceOrigin origin,
int sampleCnt) { GrColorType ct,
int sampleCnt) {
auto proxy = this->findOrCreateProxyByUniqueKey(key); auto proxy = this->findOrCreateProxyByUniqueKey(key);
if (!proxy) { if (!proxy) {
return {}; return {};
@ -862,12 +862,14 @@ sk_sp<GrTextureProxy> GrProxyProvider::MakeFullyLazyProxy(LazyInstantiateCallbac
} }
} }
void GrProxyProvider::processInvalidUniqueKey(const GrUniqueKey& key, GrTextureProxy* proxy, void GrProxyProvider::processInvalidUniqueKey(const skgpu::UniqueKey& key,
GrTextureProxy* proxy,
InvalidateGPUResource invalidateGPUResource) { InvalidateGPUResource invalidateGPUResource) {
this->processInvalidUniqueKeyImpl(key, proxy, invalidateGPUResource, RemoveTableEntry::kYes); this->processInvalidUniqueKeyImpl(key, proxy, invalidateGPUResource, RemoveTableEntry::kYes);
} }
void GrProxyProvider::processInvalidUniqueKeyImpl(const GrUniqueKey& key, GrTextureProxy* proxy, void GrProxyProvider::processInvalidUniqueKeyImpl(const skgpu::UniqueKey& key,
GrTextureProxy* proxy,
InvalidateGPUResource invalidateGPUResource, InvalidateGPUResource invalidateGPUResource,
RemoveTableEntry removeTableEntry) { RemoveTableEntry removeTableEntry) {
SkASSERT(key.isValid()); SkASSERT(key.isValid());

View File

@ -9,9 +9,9 @@
#define GrProxyProvider_DEFINED #define GrProxyProvider_DEFINED
#include "include/gpu/GrTypes.h" #include "include/gpu/GrTypes.h"
#include "include/private/GrResourceKey.h"
#include "src/core/SkTDynamicHash.h" #include "src/core/SkTDynamicHash.h"
#include "src/gpu/GrTextureProxy.h" #include "src/gpu/GrTextureProxy.h"
#include "src/gpu/ResourceKey.h"
class GrImageContext; class GrImageContext;
class GrBackendRenderTarget; class GrBackendRenderTarget;
@ -34,7 +34,7 @@ public:
* Assigns a unique key to a proxy. The proxy will be findable via this key using * Assigns a unique key to a proxy. The proxy will be findable via this key using
* findProxyByUniqueKey(). It is an error if an existing proxy already has a key. * findProxyByUniqueKey(). It is an error if an existing proxy already has a key.
*/ */
bool assignUniqueKeyToProxy(const GrUniqueKey&, GrTextureProxy*); bool assignUniqueKeyToProxy(const skgpu::UniqueKey&, GrTextureProxy*);
/* /*
* Sets the unique key of the provided proxy to the unique key of the surface. The surface must * Sets the unique key of the provided proxy to the unique key of the surface. The surface must
@ -51,13 +51,13 @@ public:
/* /*
* Finds a proxy by unique key. * Finds a proxy by unique key.
*/ */
sk_sp<GrTextureProxy> findProxyByUniqueKey(const GrUniqueKey&); sk_sp<GrTextureProxy> findProxyByUniqueKey(const skgpu::UniqueKey&);
/* /*
* Finds a proxy by unique key or creates a new one that wraps a resource matching the unique * Finds a proxy by unique key or creates a new one that wraps a resource matching the unique
* key. * key.
*/ */
sk_sp<GrTextureProxy> findOrCreateProxyByUniqueKey(const GrUniqueKey&, sk_sp<GrTextureProxy> findOrCreateProxyByUniqueKey(const skgpu::UniqueKey&,
UseAllocator = UseAllocator::kYes); UseAllocator = UseAllocator::kYes);
/** /**
@ -66,7 +66,7 @@ public:
* the proxy is renderable then it was created via a fallback code path so the fallback * the proxy is renderable then it was created via a fallback code path so the fallback
* color type will be used to create the view. * color type will be used to create the view.
*/ */
GrSurfaceProxyView findCachedProxyWithColorTypeFallback(const GrUniqueKey&, GrSurfaceProxyView findCachedProxyWithColorTypeFallback(const skgpu::UniqueKey&,
GrSurfaceOrigin, GrSurfaceOrigin,
GrColorType, GrColorType,
int sampleCnt); int sampleCnt);
@ -223,7 +223,7 @@ public:
* (in which case we don't want it cluttering up the hash table) or the client has indicated * (in which case we don't want it cluttering up the hash table) or the client has indicated
* that it will never refer to the unique key again. * that it will never refer to the unique key again.
*/ */
void processInvalidUniqueKey(const GrUniqueKey&, GrTextureProxy*, InvalidateGPUResource); void processInvalidUniqueKey(const skgpu::UniqueKey&, GrTextureProxy*, InvalidateGPUResource);
GrDDLProvider isDDLProvider() const; GrDDLProvider isDDLProvider() const;
@ -278,7 +278,7 @@ private:
// processInvalidUniqueKey() with control over removing hash table entries, // processInvalidUniqueKey() with control over removing hash table entries,
// which is not safe while iterating with foreach(). // which is not safe while iterating with foreach().
enum class RemoveTableEntry { kNo, kYes }; enum class RemoveTableEntry { kNo, kYes };
void processInvalidUniqueKeyImpl(const GrUniqueKey&, GrTextureProxy*, void processInvalidUniqueKeyImpl(const skgpu::UniqueKey&, GrTextureProxy*,
InvalidateGPUResource, RemoveTableEntry); InvalidateGPUResource, RemoveTableEntry);
bool isAbandoned() const; bool isAbandoned() const;
@ -296,11 +296,11 @@ private:
sk_sp<GrTextureProxy> createWrapped(sk_sp<GrTexture> tex, UseAllocator useAllocator); sk_sp<GrTextureProxy> createWrapped(sk_sp<GrTexture> tex, UseAllocator useAllocator);
struct UniquelyKeyedProxyHashTraits { struct UniquelyKeyedProxyHashTraits {
static const GrUniqueKey& GetKey(const GrTextureProxy& p) { return p.getUniqueKey(); } static const skgpu::UniqueKey& GetKey(const GrTextureProxy& p) { return p.getUniqueKey(); }
static uint32_t Hash(const GrUniqueKey& key) { return key.hash(); } static uint32_t Hash(const skgpu::UniqueKey& key) { return key.hash(); }
}; };
typedef SkTDynamicHash<GrTextureProxy, GrUniqueKey, UniquelyKeyedProxyHashTraits> UniquelyKeyedProxyHash; typedef SkTDynamicHash<GrTextureProxy, skgpu::UniqueKey, UniquelyKeyedProxyHashTraits> UniquelyKeyedProxyHash;
// This holds the texture proxies that have unique keys. The resourceCache does not get a ref // This holds the texture proxies that have unique keys. The resourceCache does not get a ref
// on these proxies but they must send a message to the resourceCache when they are deleted. // on these proxies but they must send a message to the resourceCache when they are deleted.

View File

@ -105,7 +105,7 @@ static bool can_proxy_use_scratch(const GrCaps& caps, GrSurfaceProxy* proxy) {
} }
GrResourceAllocator::Register::Register(GrSurfaceProxy* originatingProxy, GrResourceAllocator::Register::Register(GrSurfaceProxy* originatingProxy,
GrScratchKey scratchKey, skgpu::ScratchKey scratchKey,
GrResourceProvider* provider) GrResourceProvider* provider)
: fOriginatingProxy(originatingProxy) : fOriginatingProxy(originatingProxy)
, fScratchKey(std::move(scratchKey)) { , fScratchKey(std::move(scratchKey)) {
@ -276,13 +276,15 @@ GrResourceAllocator::Register* GrResourceAllocator::findOrCreateRegisterFor(GrSu
return *p; return *p;
} }
// No need for a scratch key. These don't go in the free pool. // No need for a scratch key. These don't go in the free pool.
Register* r = fInternalAllocator.make<Register>(proxy, GrScratchKey(), resourceProvider); Register* r = fInternalAllocator.make<Register>(proxy,
skgpu::ScratchKey(),
resourceProvider);
fUniqueKeyRegisters.set(uniqueKey, r); fUniqueKeyRegisters.set(uniqueKey, r);
return r; return r;
} }
// Then look in the free pool // Then look in the free pool
GrScratchKey scratchKey; skgpu::ScratchKey scratchKey;
proxy->priv().computeScratchKey(*fDContext->priv().caps(), &scratchKey); proxy->priv().computeScratchKey(*fDContext->priv().caps(), &scratchKey);
auto filter = [] (const Register* r) { auto filter = [] (const Register* r) {

View File

@ -134,21 +134,21 @@ private:
Register* findOrCreateRegisterFor(GrSurfaceProxy* proxy); Register* findOrCreateRegisterFor(GrSurfaceProxy* proxy);
struct FreePoolTraits { struct FreePoolTraits {
static const GrScratchKey& GetKey(const Register& r) { static const skgpu::ScratchKey& GetKey(const Register& r) {
return r.scratchKey(); return r.scratchKey();
} }
static uint32_t Hash(const GrScratchKey& key) { return key.hash(); } static uint32_t Hash(const skgpu::ScratchKey& key) { return key.hash(); }
static void OnFree(Register* r) { } static void OnFree(Register* r) { }
}; };
typedef SkTMultiMap<Register, GrScratchKey, FreePoolTraits> FreePoolMultiMap; typedef SkTMultiMap<Register, skgpu::ScratchKey, FreePoolTraits> FreePoolMultiMap;
typedef SkTHashMap<uint32_t, Interval*, GrCheapHash> IntvlHash; typedef SkTHashMap<uint32_t, Interval*, GrCheapHash> IntvlHash;
struct UniqueKeyHash { struct UniqueKeyHash {
uint32_t operator()(const GrUniqueKey& key) const { return key.hash(); } uint32_t operator()(const skgpu::UniqueKey& key) const { return key.hash(); }
}; };
typedef SkTHashMap<GrUniqueKey, Register*, UniqueKeyHash> UniqueKeyRegisterHash; typedef SkTHashMap<skgpu::UniqueKey, Register*, UniqueKeyHash> UniqueKeyRegisterHash;
// Each proxy with some exceptions is assigned a register. After all assignments are made, // Each proxy with some exceptions is assigned a register. After all assignments are made,
// another pass is performed to instantiate and assign actual surfaces to the proxies. Right // another pass is performed to instantiate and assign actual surfaces to the proxies. Right
@ -157,10 +157,10 @@ private:
class Register { class Register {
public: public:
// It's OK to pass an invalid scratch key iff the proxy has a unique key. // It's OK to pass an invalid scratch key iff the proxy has a unique key.
Register(GrSurfaceProxy* originatingProxy, GrScratchKey, GrResourceProvider*); Register(GrSurfaceProxy* originatingProxy, skgpu::ScratchKey, GrResourceProvider*);
const GrScratchKey& scratchKey() const { return fScratchKey; } const skgpu::ScratchKey& scratchKey() const { return fScratchKey; }
const GrUniqueKey& uniqueKey() const { return fOriginatingProxy->getUniqueKey(); } const skgpu::UniqueKey& uniqueKey() const { return fOriginatingProxy->getUniqueKey(); }
bool accountedForInBudget() const { return fAccountedForInBudget; } bool accountedForInBudget() const { return fAccountedForInBudget; }
void setAccountedForInBudget() { fAccountedForInBudget = true; } void setAccountedForInBudget() { fAccountedForInBudget = true; }
@ -178,10 +178,10 @@ private:
SkDEBUGCODE(uint32_t uniqueID() const { return fUniqueID; }) SkDEBUGCODE(uint32_t uniqueID() const { return fUniqueID; })
private: private:
GrSurfaceProxy* fOriginatingProxy; GrSurfaceProxy* fOriginatingProxy;
GrScratchKey fScratchKey; // free pool wants a reference to this. skgpu::ScratchKey fScratchKey; // free pool wants a reference to this.
sk_sp<GrSurface> fExistingSurface; // queried from resource cache. may be null. sk_sp<GrSurface> fExistingSurface; // queried from resource cache. may be null.
bool fAccountedForInBudget = false; bool fAccountedForInBudget = false;
#ifdef SK_DEBUG #ifdef SK_DEBUG
uint32_t fUniqueID; uint32_t fUniqueID;

View File

@ -26,7 +26,7 @@
#include "src/gpu/GrTracing.h" #include "src/gpu/GrTracing.h"
#include "src/gpu/SkGr.h" #include "src/gpu/SkGr.h"
DECLARE_SKMESSAGEBUS_MESSAGE(GrUniqueKeyInvalidatedMessage, uint32_t, true); DECLARE_SKMESSAGEBUS_MESSAGE(skgpu::UniqueKeyInvalidatedMessage, uint32_t, true);
DECLARE_SKMESSAGEBUS_MESSAGE(GrTextureFreedMessage, GrDirectContext::DirectContextID, true); DECLARE_SKMESSAGEBUS_MESSAGE(GrTextureFreedMessage, GrDirectContext::DirectContextID, true);
@ -34,34 +34,6 @@ DECLARE_SKMESSAGEBUS_MESSAGE(GrTextureFreedMessage, GrDirectContext::DirectConte
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
GrScratchKey::ResourceType GrScratchKey::GenerateResourceType() {
static std::atomic<int32_t> nextType{INHERITED::kInvalidDomain + 1};
int32_t type = nextType.fetch_add(1, std::memory_order_relaxed);
if (type > SkTo<int32_t>(UINT16_MAX)) {
SK_ABORT("Too many Resource Types");
}
return static_cast<ResourceType>(type);
}
GrUniqueKey::Domain GrUniqueKey::GenerateDomain() {
static std::atomic<int32_t> nextDomain{INHERITED::kInvalidDomain + 1};
int32_t domain = nextDomain.fetch_add(1, std::memory_order_relaxed);
if (domain > SkTo<int32_t>(UINT16_MAX)) {
SK_ABORT("Too many GrUniqueKey Domains");
}
return static_cast<Domain>(domain);
}
uint32_t GrResourceKeyHash(const uint32_t* data, size_t size) {
return SkOpts::hash(data, size);
}
//////////////////////////////////////////////////////////////////////////////
class GrResourceCache::AutoValidate : ::SkNoncopyable { class GrResourceCache::AutoValidate : ::SkNoncopyable {
public: public:
AutoValidate(GrResourceCache* cache) : fCache(cache) { cache->validate(); } AutoValidate(GrResourceCache* cache) : fCache(cache) { cache->validate(); }
@ -290,7 +262,7 @@ public:
} }
}; };
GrGpuResource* GrResourceCache::findAndRefScratchResource(const GrScratchKey& scratchKey) { GrGpuResource* GrResourceCache::findAndRefScratchResource(const skgpu::ScratchKey& scratchKey) {
SkASSERT(scratchKey.isValid()); SkASSERT(scratchKey.isValid());
GrGpuResource* resource = fScratchMap.find(scratchKey, AvailableForScratchUse()); GrGpuResource* resource = fScratchMap.find(scratchKey, AvailableForScratchUse());
@ -330,7 +302,7 @@ void GrResourceCache::removeUniqueKey(GrGpuResource* resource) {
this->validate(); this->validate();
} }
void GrResourceCache::changeUniqueKey(GrGpuResource* resource, const GrUniqueKey& newKey) { void GrResourceCache::changeUniqueKey(GrGpuResource* resource, const skgpu::UniqueKey& newKey) {
ASSERT_SINGLE_OWNER ASSERT_SINGLE_OWNER
SkASSERT(resource); SkASSERT(resource);
SkASSERT(this->isInCache(resource)); SkASSERT(this->isInCache(resource));
@ -522,7 +494,7 @@ void GrResourceCache::didChangeBudgetStatus(GrGpuResource* resource) {
} }
void GrResourceCache::purgeAsNeeded() { void GrResourceCache::purgeAsNeeded() {
SkTArray<GrUniqueKeyInvalidatedMessage> invalidKeyMsgs; SkTArray<skgpu::UniqueKeyInvalidatedMessage> invalidKeyMsgs;
fInvalidUniqueKeyInbox.poll(&invalidKeyMsgs); fInvalidUniqueKeyInbox.poll(&invalidKeyMsgs);
if (invalidKeyMsgs.count()) { if (invalidKeyMsgs.count()) {
SkASSERT(fProxyProvider); SkASSERT(fProxyProvider);
@ -919,8 +891,8 @@ void GrResourceCache::validate() const {
++fLocked; ++fLocked;
} }
const GrScratchKey& scratchKey = resource->resourcePriv().getScratchKey(); const skgpu::ScratchKey& scratchKey = resource->resourcePriv().getScratchKey();
const GrUniqueKey& uniqueKey = resource->getUniqueKey(); const skgpu::UniqueKey& uniqueKey = resource->getUniqueKey();
if (resource->cacheAccess().isUsableAsScratch()) { if (resource->cacheAccess().isUsableAsScratch()) {
SkASSERT(!uniqueKey.isValid()); SkASSERT(!uniqueKey.isValid());

View File

@ -10,7 +10,6 @@
#include "include/core/SkRefCnt.h" #include "include/core/SkRefCnt.h"
#include "include/gpu/GrDirectContext.h" #include "include/gpu/GrDirectContext.h"
#include "include/private/GrResourceKey.h"
#include "include/private/SkTArray.h" #include "include/private/SkTArray.h"
#include "include/private/SkTHash.h" #include "include/private/SkTHash.h"
#include "src/core/SkMessageBus.h" #include "src/core/SkMessageBus.h"
@ -20,6 +19,7 @@
#include "src/gpu/GrGpuResource.h" #include "src/gpu/GrGpuResource.h"
#include "src/gpu/GrGpuResourceCacheAccess.h" #include "src/gpu/GrGpuResourceCacheAccess.h"
#include "src/gpu/GrGpuResourcePriv.h" #include "src/gpu/GrGpuResourcePriv.h"
#include "src/gpu/ResourceKey.h"
class GrCaps; class GrCaps;
class GrProxyProvider; class GrProxyProvider;
@ -123,11 +123,11 @@ public:
/** /**
* Find a resource that matches a scratch key. * Find a resource that matches a scratch key.
*/ */
GrGpuResource* findAndRefScratchResource(const GrScratchKey& scratchKey); GrGpuResource* findAndRefScratchResource(const skgpu::ScratchKey& scratchKey);
#ifdef SK_DEBUG #ifdef SK_DEBUG
// This is not particularly fast and only used for validation, so debug only. // This is not particularly fast and only used for validation, so debug only.
int countScratchEntriesForKey(const GrScratchKey& scratchKey) const { int countScratchEntriesForKey(const skgpu::ScratchKey& scratchKey) const {
return fScratchMap.countForKey(scratchKey); return fScratchMap.countForKey(scratchKey);
} }
#endif #endif
@ -135,7 +135,7 @@ public:
/** /**
* Find a resource that matches a unique key. * Find a resource that matches a unique key.
*/ */
GrGpuResource* findAndRefUniqueResource(const GrUniqueKey& key) { GrGpuResource* findAndRefUniqueResource(const skgpu::UniqueKey& key) {
GrGpuResource* resource = fUniqueHash.find(key); GrGpuResource* resource = fUniqueHash.find(key);
if (resource) { if (resource) {
this->refAndMakeResourceMRU(resource); this->refAndMakeResourceMRU(resource);
@ -146,7 +146,7 @@ public:
/** /**
* Query whether a unique key exists in the cache. * Query whether a unique key exists in the cache.
*/ */
bool hasUniqueKey(const GrUniqueKey& key) const { bool hasUniqueKey(const skgpu::UniqueKey& key) const {
return SkToBool(fUniqueHash.find(key)); return SkToBool(fUniqueHash.find(key));
} }
@ -260,7 +260,7 @@ private:
void insertResource(GrGpuResource*); void insertResource(GrGpuResource*);
void removeResource(GrGpuResource*); void removeResource(GrGpuResource*);
void notifyARefCntReachedZero(GrGpuResource*, GrGpuResource::LastRemovedRef); void notifyARefCntReachedZero(GrGpuResource*, GrGpuResource::LastRemovedRef);
void changeUniqueKey(GrGpuResource*, const GrUniqueKey&); void changeUniqueKey(GrGpuResource*, const skgpu::UniqueKey&);
void removeUniqueKey(GrGpuResource*); void removeUniqueKey(GrGpuResource*);
void willRemoveScratchKey(const GrGpuResource*); void willRemoveScratchKey(const GrGpuResource*);
void didChangeBudgetStatus(GrGpuResource*); void didChangeBudgetStatus(GrGpuResource*);
@ -291,21 +291,21 @@ private:
class AvailableForScratchUse; class AvailableForScratchUse;
struct ScratchMapTraits { struct ScratchMapTraits {
static const GrScratchKey& GetKey(const GrGpuResource& r) { static const skgpu::ScratchKey& GetKey(const GrGpuResource& r) {
return r.resourcePriv().getScratchKey(); return r.resourcePriv().getScratchKey();
} }
static uint32_t Hash(const GrScratchKey& key) { return key.hash(); } static uint32_t Hash(const skgpu::ScratchKey& key) { return key.hash(); }
static void OnFree(GrGpuResource*) { } static void OnFree(GrGpuResource*) { }
}; };
typedef SkTMultiMap<GrGpuResource, GrScratchKey, ScratchMapTraits> ScratchMap; typedef SkTMultiMap<GrGpuResource, skgpu::ScratchKey, ScratchMapTraits> ScratchMap;
struct UniqueHashTraits { struct UniqueHashTraits {
static const GrUniqueKey& GetKey(const GrGpuResource& r) { return r.getUniqueKey(); } static const skgpu::UniqueKey& GetKey(const GrGpuResource& r) { return r.getUniqueKey(); }
static uint32_t Hash(const GrUniqueKey& key) { return key.hash(); } static uint32_t Hash(const skgpu::UniqueKey& key) { return key.hash(); }
}; };
typedef SkTDynamicHash<GrGpuResource, GrUniqueKey, UniqueHashTraits> UniqueHash; typedef SkTDynamicHash<GrGpuResource, skgpu::UniqueKey, UniqueHashTraits> UniqueHash;
class TextureAwaitingUnref { class TextureAwaitingUnref {
public: public:
@ -337,7 +337,7 @@ private:
using TextureFreedMessageBus = SkMessageBus<GrTextureFreedMessage, using TextureFreedMessageBus = SkMessageBus<GrTextureFreedMessage,
GrDirectContext::DirectContextID>; GrDirectContext::DirectContextID>;
typedef SkMessageBus<GrUniqueKeyInvalidatedMessage, uint32_t>::Inbox InvalidUniqueKeyInbox; typedef SkMessageBus<skgpu::UniqueKeyInvalidatedMessage, uint32_t>::Inbox InvalidUniqueKeyInbox;
typedef SkTDPQueue<GrGpuResource*, CompareTimestamp, AccessResourceIndex> PurgeableQueue; typedef SkTDPQueue<GrGpuResource*, CompareTimestamp, AccessResourceIndex> PurgeableQueue;
typedef SkTDArray<GrGpuResource*> ResourceArray; typedef SkTDArray<GrGpuResource*> ResourceArray;
@ -433,7 +433,7 @@ private:
/** /**
* Called by GrGpuResources to change their unique keys. * Called by GrGpuResources to change their unique keys.
*/ */
void changeUniqueKey(GrGpuResource* resource, const GrUniqueKey& newKey) { void changeUniqueKey(GrGpuResource* resource, const skgpu::UniqueKey& newKey) {
fCache->changeUniqueKey(resource, newKey); fCache->changeUniqueKey(resource, newKey);
} }

View File

@ -8,7 +8,6 @@
#include "src/gpu/GrResourceProvider.h" #include "src/gpu/GrResourceProvider.h"
#include "include/gpu/GrBackendSemaphore.h" #include "include/gpu/GrBackendSemaphore.h"
#include "include/private/GrResourceKey.h"
#include "include/private/GrSingleOwner.h" #include "include/private/GrSingleOwner.h"
#include "src/core/SkConvertPixels.h" #include "src/core/SkConvertPixels.h"
#include "src/core/SkMathPriv.h" #include "src/core/SkMathPriv.h"
@ -25,6 +24,7 @@
#include "src/gpu/GrResourceCache.h" #include "src/gpu/GrResourceCache.h"
#include "src/gpu/GrSemaphore.h" #include "src/gpu/GrSemaphore.h"
#include "src/gpu/GrTexture.h" #include "src/gpu/GrTexture.h"
#include "src/gpu/ResourceKey.h"
#include "src/gpu/SkGr.h" #include "src/gpu/SkGr.h"
const int GrResourceProvider::kMinScratchTextureSize = 16; const int GrResourceProvider::kMinScratchTextureSize = 16;
@ -304,7 +304,7 @@ sk_sp<GrTexture> GrResourceProvider::createApproxTexture(SkISize dimensions,
isProtected); isProtected);
} }
sk_sp<GrTexture> GrResourceProvider::findAndRefScratchTexture(const GrScratchKey& key) { sk_sp<GrTexture> GrResourceProvider::findAndRefScratchTexture(const skgpu::ScratchKey& key) {
ASSERT_SINGLE_OWNER ASSERT_SINGLE_OWNER
SkASSERT(!this->isAbandoned()); SkASSERT(!this->isAbandoned());
SkASSERT(key.isValid()); SkASSERT(key.isValid());
@ -333,7 +333,7 @@ sk_sp<GrTexture> GrResourceProvider::findAndRefScratchTexture(SkISize dimensions
// We could make initial clears work with scratch textures but it is a rare case so we just opt // We could make initial clears work with scratch textures but it is a rare case so we just opt
// to fall back to making a new texture. // to fall back to making a new texture.
if (fGpu->caps()->reuseScratchTextures() || renderable == GrRenderable::kYes) { if (fGpu->caps()->reuseScratchTextures() || renderable == GrRenderable::kYes) {
GrScratchKey key; skgpu::ScratchKey key;
GrTexture::ComputeScratchKey(*this->caps(), format, dimensions, renderable, GrTexture::ComputeScratchKey(*this->caps(), format, dimensions, renderable,
renderTargetSampleCnt, mipmapped, isProtected, &key); renderTargetSampleCnt, mipmapped, isProtected, &key);
return this->findAndRefScratchTexture(key); return this->findAndRefScratchTexture(key);
@ -390,7 +390,7 @@ sk_sp<GrRenderTarget> GrResourceProvider::wrapVulkanSecondaryCBAsRenderTarget(
} }
void GrResourceProvider::assignUniqueKeyToResource(const GrUniqueKey& key, void GrResourceProvider::assignUniqueKeyToResource(const skgpu::UniqueKey& key,
GrGpuResource* resource) { GrGpuResource* resource) {
ASSERT_SINGLE_OWNER ASSERT_SINGLE_OWNER
if (this->isAbandoned() || !resource) { if (this->isAbandoned() || !resource) {
@ -399,7 +399,7 @@ void GrResourceProvider::assignUniqueKeyToResource(const GrUniqueKey& key,
resource->resourcePriv().setUniqueKey(key); resource->resourcePriv().setUniqueKey(key);
} }
sk_sp<GrGpuResource> GrResourceProvider::findResourceByUniqueKey(const GrUniqueKey& key) { sk_sp<GrGpuResource> GrResourceProvider::findResourceByUniqueKey(const skgpu::UniqueKey& key) {
ASSERT_SINGLE_OWNER ASSERT_SINGLE_OWNER
return this->isAbandoned() ? nullptr return this->isAbandoned() ? nullptr
: sk_sp<GrGpuResource>(fCache->findAndRefUniqueResource(key)); : sk_sp<GrGpuResource>(fCache->findAndRefUniqueResource(key));
@ -408,7 +408,7 @@ sk_sp<GrGpuResource> GrResourceProvider::findResourceByUniqueKey(const GrUniqueK
sk_sp<const GrGpuBuffer> GrResourceProvider::findOrMakeStaticBuffer(GrGpuBufferType intendedType, sk_sp<const GrGpuBuffer> GrResourceProvider::findOrMakeStaticBuffer(GrGpuBufferType intendedType,
size_t size, size_t size,
const void* staticData, const void* staticData,
const GrUniqueKey& key) { const skgpu::UniqueKey& key) {
if (auto buffer = this->findByUniqueKey<GrGpuBuffer>(key)) { if (auto buffer = this->findByUniqueKey<GrGpuBuffer>(key)) {
return std::move(buffer); return std::move(buffer);
} }
@ -425,7 +425,7 @@ sk_sp<const GrGpuBuffer> GrResourceProvider::findOrMakeStaticBuffer(GrGpuBufferT
sk_sp<const GrGpuBuffer> GrResourceProvider::findOrMakeStaticBuffer( sk_sp<const GrGpuBuffer> GrResourceProvider::findOrMakeStaticBuffer(
GrGpuBufferType intendedType, GrGpuBufferType intendedType,
size_t size, size_t size,
const GrUniqueKey& uniqueKey, const skgpu::UniqueKey& uniqueKey,
InitializeBufferFn initializeBufferFn) { InitializeBufferFn initializeBufferFn) {
if (auto buffer = this->findByUniqueKey<GrGpuBuffer>(uniqueKey)) { if (auto buffer = this->findByUniqueKey<GrGpuBuffer>(uniqueKey)) {
return std::move(buffer); return std::move(buffer);
@ -456,11 +456,12 @@ sk_sp<const GrGpuBuffer> GrResourceProvider::findOrMakeStaticBuffer(
return nullptr; return nullptr;
} }
sk_sp<const GrGpuBuffer> GrResourceProvider::createPatternedIndexBuffer(const uint16_t* pattern, sk_sp<const GrGpuBuffer> GrResourceProvider::createPatternedIndexBuffer(
int patternSize, const uint16_t* pattern,
int reps, int patternSize,
int vertCount, int reps,
const GrUniqueKey* key) { int vertCount,
const skgpu::UniqueKey* key) {
size_t bufferSize = patternSize * reps * sizeof(uint16_t); size_t bufferSize = patternSize * reps * sizeof(uint16_t);
sk_sp<GrGpuBuffer> buffer( sk_sp<GrGpuBuffer> buffer(
@ -565,7 +566,7 @@ sk_sp<GrGpuBuffer> GrResourceProvider::createBuffer(size_t size, GrGpuBufferType
size_t mid = floorPow2 + (floorPow2 >> 1); size_t mid = floorPow2 + (floorPow2 >> 1);
allocSize = (allocSize <= mid) ? mid : ceilPow2; allocSize = (allocSize <= mid) ? mid : ceilPow2;
GrScratchKey key; skgpu::ScratchKey key;
GrGpuBuffer::ComputeScratchKeyForDynamicBuffer(allocSize, intendedType, &key); GrGpuBuffer::ComputeScratchKeyForDynamicBuffer(allocSize, intendedType, &key);
auto buffer = auto buffer =
sk_sp<GrGpuBuffer>(static_cast<GrGpuBuffer*>(this->cache()->findAndRefScratchResource( sk_sp<GrGpuBuffer>(static_cast<GrGpuBuffer*>(this->cache()->findAndRefScratchResource(
@ -602,7 +603,7 @@ bool GrResourceProvider::attachStencilAttachment(GrRenderTarget* rt, bool useMSA
} }
if (!rt->wasDestroyed() && rt->canAttemptStencilAttachment(useMSAASurface)) { if (!rt->wasDestroyed() && rt->canAttemptStencilAttachment(useMSAASurface)) {
GrUniqueKey sbKey; skgpu::UniqueKey sbKey;
#if 0 #if 0
if (this->caps()->oversizedStencilSupport()) { if (this->caps()->oversizedStencilSupport()) {
@ -660,7 +661,7 @@ sk_sp<GrAttachment> GrResourceProvider::getDiscardableMSAAAttachment(SkISize dim
return nullptr; return nullptr;
} }
GrUniqueKey key; skgpu::UniqueKey key;
GrAttachment::ComputeSharedAttachmentUniqueKey(*this->caps(), GrAttachment::ComputeSharedAttachmentUniqueKey(*this->caps(),
format, format,
dimensions, dimensions,
@ -731,7 +732,7 @@ sk_sp<GrAttachment> GrResourceProvider::refScratchMSAAAttachment(SkISize dimensi
GrMipmapped::kNo, GrMipmapped::kNo,
GrTextureType::kNone)); GrTextureType::kNone));
GrScratchKey key; skgpu::ScratchKey key;
GrAttachment::ComputeScratchKey(*this->caps(), format, dimensions, GrAttachment::ComputeScratchKey(*this->caps(), format, dimensions,
GrAttachment::UsageFlags::kColorAttachment, sampleCnt, GrAttachment::UsageFlags::kColorAttachment, sampleCnt,
GrMipmapped::kNo, isProtected, memoryless, &key); GrMipmapped::kNo, isProtected, memoryless, &key);

View File

@ -48,7 +48,7 @@ public:
*/ */
template <typename T = GrGpuResource> template <typename T = GrGpuResource>
typename std::enable_if<std::is_base_of<GrGpuResource, T>::value, sk_sp<T>>::type typename std::enable_if<std::is_base_of<GrGpuResource, T>::value, sk_sp<T>>::type
findByUniqueKey(const GrUniqueKey& key) { findByUniqueKey(const skgpu::UniqueKey& key) {
return sk_sp<T>(static_cast<T*>(this->findResourceByUniqueKey(key).release())); return sk_sp<T>(static_cast<T*>(this->findResourceByUniqueKey(key).release()));
} }
@ -114,7 +114,7 @@ public:
* Search the cache for a scratch texture matching the provided arguments. Failing that * Search the cache for a scratch texture matching the provided arguments. Failing that
* it returns null. If non-null, the resulting texture is always budgeted. * it returns null. If non-null, the resulting texture is always budgeted.
*/ */
sk_sp<GrTexture> findAndRefScratchTexture(const GrScratchKey&); sk_sp<GrTexture> findAndRefScratchTexture(const skgpu::ScratchKey&);
sk_sp<GrTexture> findAndRefScratchTexture(SkISize dimensions, sk_sp<GrTexture> findAndRefScratchTexture(SkISize dimensions,
const GrBackendFormat&, const GrBackendFormat&,
GrTextureType textureType, GrTextureType textureType,
@ -195,8 +195,10 @@ public:
* @return The buffer if successful, otherwise nullptr. * @return The buffer if successful, otherwise nullptr.
*/ */
using InitializeBufferFn = void(*)(skgpu::VertexWriter, size_t bufferSize); using InitializeBufferFn = void(*)(skgpu::VertexWriter, size_t bufferSize);
sk_sp<const GrGpuBuffer> findOrMakeStaticBuffer(GrGpuBufferType intendedType, size_t size, sk_sp<const GrGpuBuffer> findOrMakeStaticBuffer(GrGpuBufferType intendedType,
const GrUniqueKey& key, InitializeBufferFn); size_t size,
const skgpu::UniqueKey& key,
InitializeBufferFn);
/** /**
* Either finds and refs, or creates a static buffer with the given parameters and contents. * Either finds and refs, or creates a static buffer with the given parameters and contents.
@ -208,8 +210,10 @@ public:
* *
* @return The buffer if successful, otherwise nullptr. * @return The buffer if successful, otherwise nullptr.
*/ */
sk_sp<const GrGpuBuffer> findOrMakeStaticBuffer(GrGpuBufferType intendedType, size_t size, sk_sp<const GrGpuBuffer> findOrMakeStaticBuffer(GrGpuBufferType intendedType,
const void* staticData, const GrUniqueKey& key); size_t size,
const void* staticData,
const skgpu::UniqueKey& key);
/** /**
* Either finds and refs, or creates an index buffer with a repeating pattern for drawing * Either finds and refs, or creates an index buffer with a repeating pattern for drawing
@ -228,7 +232,7 @@ public:
int patternSize, int patternSize,
int reps, int reps,
int vertCount, int vertCount,
const GrUniqueKey& key) { const skgpu::UniqueKey& key) {
if (auto buffer = this->findByUniqueKey<const GrGpuBuffer>(key)) { if (auto buffer = this->findByUniqueKey<const GrGpuBuffer>(key)) {
return buffer; return buffer;
} }
@ -315,7 +319,7 @@ public:
* Assigns a unique key to a resource. If the key is associated with another resource that * Assigns a unique key to a resource. If the key is associated with another resource that
* association is removed and replaced by this resource. * association is removed and replaced by this resource.
*/ */
void assignUniqueKeyToResource(const GrUniqueKey&, GrGpuResource*); void assignUniqueKeyToResource(const skgpu::UniqueKey&, GrGpuResource*);
std::unique_ptr<GrSemaphore> SK_WARN_UNUSED_RESULT makeSemaphore(bool isOwned = true); std::unique_ptr<GrSemaphore> SK_WARN_UNUSED_RESULT makeSemaphore(bool isOwned = true);
@ -338,7 +342,7 @@ public:
inline const GrResourceProviderPriv priv() const; // NOLINT(readability-const-return-type) inline const GrResourceProviderPriv priv() const; // NOLINT(readability-const-return-type)
private: private:
sk_sp<GrGpuResource> findResourceByUniqueKey(const GrUniqueKey&); sk_sp<GrGpuResource> findResourceByUniqueKey(const skgpu::UniqueKey&);
/* /*
* Try to find an existing scratch texture that exactly matches 'desc'. If successful * Try to find an existing scratch texture that exactly matches 'desc'. If successful
@ -402,7 +406,7 @@ private:
int patternSize, int patternSize,
int reps, int reps,
int vertCount, int vertCount,
const GrUniqueKey* key); const skgpu::UniqueKey* key);
sk_sp<const GrGpuBuffer> createNonAAQuadIndexBuffer(); sk_sp<const GrGpuBuffer> createNonAAQuadIndexBuffer();
sk_sp<const GrGpuBuffer> createAAQuadIndexBuffer(); sk_sp<const GrGpuBuffer> createAAQuadIndexBuffer();

View File

@ -174,7 +174,7 @@ void GrSurfaceProxy::assign(sk_sp<GrSurface> surface) {
bool GrSurfaceProxy::instantiateImpl(GrResourceProvider* resourceProvider, int sampleCnt, bool GrSurfaceProxy::instantiateImpl(GrResourceProvider* resourceProvider, int sampleCnt,
GrRenderable renderable, GrMipmapped mipMapped, GrRenderable renderable, GrMipmapped mipMapped,
const GrUniqueKey* uniqueKey) { const skgpu::UniqueKey* uniqueKey) {
SkASSERT(!this->isLazy()); SkASSERT(!this->isLazy());
if (fTarget) { if (fTarget) {
if (uniqueKey && uniqueKey->isValid()) { if (uniqueKey && uniqueKey->isValid()) {
@ -205,7 +205,7 @@ void GrSurfaceProxy::deinstantiate() {
fTarget = nullptr; fTarget = nullptr;
} }
void GrSurfaceProxy::computeScratchKey(const GrCaps& caps, GrScratchKey* key) const { void GrSurfaceProxy::computeScratchKey(const GrCaps& caps, skgpu::ScratchKey* key) const {
SkASSERT(!this->isFullyLazy()); SkASSERT(!this->isFullyLazy());
GrRenderable renderable = GrRenderable::kNo; GrRenderable renderable = GrRenderable::kNo;
int sampleCount = 1; int sampleCount = 1;
@ -446,7 +446,7 @@ bool GrSurfaceProxyPriv::doLazyInstantiation(GrResourceProvider* resourceProvide
if (GrTextureProxy* texProxy = fProxy->asTextureProxy()) { if (GrTextureProxy* texProxy = fProxy->asTextureProxy()) {
texProxy->setTargetKeySync(syncKey); texProxy->setTargetKeySync(syncKey);
if (syncKey) { if (syncKey) {
const GrUniqueKey& key = texProxy->getUniqueKey(); const skgpu::UniqueKey& key = texProxy->getUniqueKey();
if (key.isValid()) { if (key.isValid()) {
if (!surface->asTexture()->getUniqueKey().isValid()) { if (!surface->asTexture()->getUniqueKey().isValid()) {
// If 'surface' is newly created, attach the unique key // If 'surface' is newly created, attach the unique key

View File

@ -231,9 +231,9 @@ public:
virtual const GrRenderTargetProxy* asRenderTargetProxy() const { return nullptr; } virtual const GrRenderTargetProxy* asRenderTargetProxy() const { return nullptr; }
/** @return The unique key for this proxy. May be invalid. */ /** @return The unique key for this proxy. May be invalid. */
virtual const GrUniqueKey& getUniqueKey() const { virtual const skgpu::UniqueKey& getUniqueKey() const {
// Base class never has a valid unique key. // Base class never has a valid unique key.
static const GrUniqueKey kInvalidKey; static const skgpu::UniqueKey kInvalidKey;
return kInvalidKey; return kInvalidKey;
} }
@ -391,7 +391,7 @@ protected:
bool ignoredByResourceAllocator() const { return fIgnoredByResourceAllocator; } bool ignoredByResourceAllocator() const { return fIgnoredByResourceAllocator; }
void setIgnoredByResourceAllocator() { fIgnoredByResourceAllocator = true; } void setIgnoredByResourceAllocator() { fIgnoredByResourceAllocator = true; }
void computeScratchKey(const GrCaps&, GrScratchKey*) const; void computeScratchKey(const GrCaps&, skgpu::ScratchKey*) const;
virtual sk_sp<GrSurface> createSurface(GrResourceProvider*) const = 0; virtual sk_sp<GrSurface> createSurface(GrResourceProvider*) const = 0;
void assign(sk_sp<GrSurface> surface); void assign(sk_sp<GrSurface> surface);
@ -410,7 +410,7 @@ protected:
} }
bool instantiateImpl(GrResourceProvider* resourceProvider, int sampleCnt, GrRenderable, bool instantiateImpl(GrResourceProvider* resourceProvider, int sampleCnt, GrRenderable,
GrMipmapped, const GrUniqueKey*); GrMipmapped, const skgpu::UniqueKey*);
// For deferred proxies this will be null until the proxy is instantiated. // For deferred proxies this will be null until the proxy is instantiated.
// For wrapped proxies it will point to the wrapped resource. // For wrapped proxies it will point to the wrapped resource.

View File

@ -17,7 +17,7 @@ class GrResourceProvider;
data members or virtual methods. */ data members or virtual methods. */
class GrSurfaceProxyPriv { class GrSurfaceProxyPriv {
public: public:
void computeScratchKey(const GrCaps& caps, GrScratchKey* key) const { void computeScratchKey(const GrCaps& caps, skgpu::ScratchKey* key) const {
return fProxy->computeScratchKey(caps, key); return fProxy->computeScratchKey(caps, key);
} }

View File

@ -8,7 +8,6 @@
#include "include/core/SkMath.h" #include "include/core/SkMath.h"
#include "include/core/SkTypes.h" #include "include/core/SkTypes.h"
#include "include/gpu/GrTypes.h" #include "include/gpu/GrTypes.h"
#include "include/private/GrResourceKey.h"
#include "src/core/SkMipmap.h" #include "src/core/SkMipmap.h"
#include "src/gpu/GrCaps.h" #include "src/gpu/GrCaps.h"
#include "src/gpu/GrGpu.h" #include "src/gpu/GrGpu.h"
@ -86,7 +85,7 @@ bool GrTexture::StealBackendTexture(sk_sp<GrTexture> texture,
return true; return true;
} }
void GrTexture::computeScratchKey(GrScratchKey* key) const { void GrTexture::computeScratchKey(skgpu::ScratchKey* key) const {
if (!this->getGpu()->caps()->isFormatCompressed(this->backendFormat())) { if (!this->getGpu()->caps()->isFormatCompressed(this->backendFormat())) {
int sampleCount = 1; int sampleCount = 1;
GrRenderable renderable = GrRenderable::kNo; GrRenderable renderable = GrRenderable::kNo;
@ -107,8 +106,8 @@ void GrTexture::ComputeScratchKey(const GrCaps& caps,
int sampleCnt, int sampleCnt,
GrMipmapped mipMapped, GrMipmapped mipMapped,
GrProtected isProtected, GrProtected isProtected,
GrScratchKey* key) { skgpu::ScratchKey* key) {
static const GrScratchKey::ResourceType kType = GrScratchKey::GenerateResourceType(); static const skgpu::ScratchKey::ResourceType kType = skgpu::ScratchKey::GenerateResourceType();
SkASSERT(!dimensions.isEmpty()); SkASSERT(!dimensions.isEmpty());
SkASSERT(sampleCnt > 0); SkASSERT(sampleCnt > 0);
SkASSERT(1 == sampleCnt || renderable == GrRenderable::kYes); SkASSERT(1 == sampleCnt || renderable == GrRenderable::kYes);
@ -120,7 +119,7 @@ void GrTexture::ComputeScratchKey(const GrCaps& caps,
uint64_t formatKey = caps.computeFormatKey(format); uint64_t formatKey = caps.computeFormatKey(format);
GrScratchKey::Builder builder(key, kType, 5); skgpu::ScratchKey::Builder builder(key, kType, 5);
builder[0] = dimensions.width(); builder[0] = dimensions.width();
builder[1] = dimensions.height(); builder[1] = dimensions.height();
builder[2] = formatKey & 0xFFFFFFFF; builder[2] = formatKey & 0xFFFFFFFF;

View File

@ -61,14 +61,14 @@ public:
int sampleCnt, int sampleCnt,
GrMipmapped, GrMipmapped,
GrProtected, GrProtected,
GrScratchKey* key); skgpu::ScratchKey* key);
protected: protected:
GrTexture(GrGpu*, const SkISize&, GrProtected, GrTextureType, GrMipmapStatus); GrTexture(GrGpu*, const SkISize&, GrProtected, GrTextureType, GrMipmapStatus);
virtual bool onStealBackendTexture(GrBackendTexture*, SkImage::BackendTextureReleaseProc*) = 0; virtual bool onStealBackendTexture(GrBackendTexture*, SkImage::BackendTextureReleaseProc*) = 0;
void computeScratchKey(GrScratchKey*) const override; void computeScratchKey(skgpu::ScratchKey*) const override;
private: private:
size_t onGpuMemorySize() const override; size_t onGpuMemorySize() const override;

View File

@ -166,7 +166,7 @@ bool GrTextureProxy::ProxiesAreCompatibleAsDynamicState(const GrSurfaceProxy* fi
first->backendFormat() == second->backendFormat(); first->backendFormat() == second->backendFormat();
} }
void GrTextureProxy::setUniqueKey(GrProxyProvider* proxyProvider, const GrUniqueKey& key) { void GrTextureProxy::setUniqueKey(GrProxyProvider* proxyProvider, const skgpu::UniqueKey& key) {
SkASSERT(key.isValid()); SkASSERT(key.isValid());
SkASSERT(!fUniqueKey.isValid()); // proxies can only ever get one uniqueKey SkASSERT(!fUniqueKey.isValid()); // proxies can only ever get one uniqueKey

View File

@ -69,7 +69,7 @@ public:
/** /**
* Return the texture proxy's unique key. It will be invalid if the proxy doesn't have one. * Return the texture proxy's unique key. It will be invalid if the proxy doesn't have one.
*/ */
const GrUniqueKey& getUniqueKey() const override { const skgpu::UniqueKey& getUniqueKey() const override {
#ifdef SK_DEBUG #ifdef SK_DEBUG
if (this->isInstantiated() && fUniqueKey.isValid() && fSyncTargetKey && if (this->isInstantiated() && fUniqueKey.isValid() && fSyncTargetKey &&
fCreatingProvider == GrDDLProvider::kNo) { fCreatingProvider == GrDDLProvider::kNo) {
@ -185,7 +185,7 @@ private:
// uniquely-keyed textureProxy is also always set on the backing GrTexture. // uniquely-keyed textureProxy is also always set on the backing GrTexture.
GrDDLProvider fCreatingProvider = GrDDLProvider::kNo; GrDDLProvider fCreatingProvider = GrDDLProvider::kNo;
GrUniqueKey fUniqueKey; skgpu::UniqueKey fUniqueKey;
GrProxyProvider* fProxyProvider; // only set when fUniqueKey is valid GrProxyProvider* fProxyProvider; // only set when fUniqueKey is valid
LazySurfaceDesc callbackDesc() const override; LazySurfaceDesc callbackDesc() const override;
@ -198,7 +198,7 @@ private:
size_t onUninstantiatedGpuMemorySize() const override; size_t onUninstantiatedGpuMemorySize() const override;
// Methods made available via GrTextureProxy::CacheAccess // Methods made available via GrTextureProxy::CacheAccess
void setUniqueKey(GrProxyProvider*, const GrUniqueKey&); void setUniqueKey(GrProxyProvider*, const skgpu::UniqueKey&);
void clearUniqueKey(); void clearUniqueKey();
SkDEBUGCODE(void onValidateSurface(const GrSurface*) override;) SkDEBUGCODE(void onValidateSurface(const GrSurface*) override;)

View File

@ -15,7 +15,7 @@
*/ */
class GrTextureProxy::CacheAccess { class GrTextureProxy::CacheAccess {
private: private:
void setUniqueKey(GrProxyProvider* proxyProvider, const GrUniqueKey& key) { void setUniqueKey(GrProxyProvider* proxyProvider, const skgpu::UniqueKey& key) {
fTextureProxy->setUniqueKey(proxyProvider, key); fTextureProxy->setUniqueKey(proxyProvider, key);
} }

View File

@ -120,7 +120,7 @@ bool GrTextureRenderTargetProxy::instantiate(GrResourceProvider* resourceProvide
return false; return false;
} }
const GrUniqueKey& key = this->getUniqueKey(); const skgpu::UniqueKey& key = this->getUniqueKey();
if (!this->instantiateImpl(resourceProvider, this->numSamples(), GrRenderable::kYes, if (!this->instantiateImpl(resourceProvider, this->numSamples(), GrRenderable::kYes,
this->mipmapped(), key.isValid() ? &key : nullptr)) { this->mipmapped(), key.isValid() ? &key : nullptr)) {

View File

@ -108,7 +108,7 @@ void GrThreadSafeCache::makeExistingEntryMRU(Entry* entry) {
} }
std::tuple<GrSurfaceProxyView, sk_sp<SkData>> GrThreadSafeCache::internalFind( std::tuple<GrSurfaceProxyView, sk_sp<SkData>> GrThreadSafeCache::internalFind(
const GrUniqueKey& key) { const skgpu::UniqueKey& key) {
Entry* tmp = fUniquelyKeyedEntryMap.find(key); Entry* tmp = fUniquelyKeyedEntryMap.find(key);
if (tmp) { if (tmp) {
this->makeExistingEntryMRU(tmp); this->makeExistingEntryMRU(tmp);
@ -119,7 +119,7 @@ std::tuple<GrSurfaceProxyView, sk_sp<SkData>> GrThreadSafeCache::internalFind(
} }
#ifdef SK_DEBUG #ifdef SK_DEBUG
bool GrThreadSafeCache::has(const GrUniqueKey& key) { bool GrThreadSafeCache::has(const skgpu::UniqueKey& key) {
SkAutoSpinlock lock{fSpinLock}; SkAutoSpinlock lock{fSpinLock};
Entry* tmp = fUniquelyKeyedEntryMap.find(key); Entry* tmp = fUniquelyKeyedEntryMap.find(key);
@ -127,7 +127,7 @@ bool GrThreadSafeCache::has(const GrUniqueKey& key) {
} }
#endif #endif
GrSurfaceProxyView GrThreadSafeCache::find(const GrUniqueKey& key) { GrSurfaceProxyView GrThreadSafeCache::find(const skgpu::UniqueKey& key) {
SkAutoSpinlock lock{fSpinLock}; SkAutoSpinlock lock{fSpinLock};
GrSurfaceProxyView view; GrSurfaceProxyView view;
@ -136,13 +136,13 @@ GrSurfaceProxyView GrThreadSafeCache::find(const GrUniqueKey& key) {
} }
std::tuple<GrSurfaceProxyView, sk_sp<SkData>> GrThreadSafeCache::findWithData( std::tuple<GrSurfaceProxyView, sk_sp<SkData>> GrThreadSafeCache::findWithData(
const GrUniqueKey& key) { const skgpu::UniqueKey& key) {
SkAutoSpinlock lock{fSpinLock}; SkAutoSpinlock lock{fSpinLock};
return this->internalFind(key); return this->internalFind(key);
} }
GrThreadSafeCache::Entry* GrThreadSafeCache::getEntry(const GrUniqueKey& key, GrThreadSafeCache::Entry* GrThreadSafeCache::getEntry(const skgpu::UniqueKey& key,
const GrSurfaceProxyView& view) { const GrSurfaceProxyView& view) {
Entry* entry; Entry* entry;
@ -166,7 +166,7 @@ GrThreadSafeCache::Entry* GrThreadSafeCache::makeNewEntryMRU(Entry* entry) {
return entry; return entry;
} }
GrThreadSafeCache::Entry* GrThreadSafeCache::getEntry(const GrUniqueKey& key, GrThreadSafeCache::Entry* GrThreadSafeCache::getEntry(const skgpu::UniqueKey& key,
sk_sp<VertexData> vertData) { sk_sp<VertexData> vertData) {
Entry* entry; Entry* entry;
@ -193,7 +193,7 @@ void GrThreadSafeCache::recycleEntry(Entry* dead) {
} }
std::tuple<GrSurfaceProxyView, sk_sp<SkData>> GrThreadSafeCache::internalAdd( std::tuple<GrSurfaceProxyView, sk_sp<SkData>> GrThreadSafeCache::internalAdd(
const GrUniqueKey& key, const skgpu::UniqueKey& key,
const GrSurfaceProxyView& view) { const GrSurfaceProxyView& view) {
Entry* tmp = fUniquelyKeyedEntryMap.find(key); Entry* tmp = fUniquelyKeyedEntryMap.find(key);
if (!tmp) { if (!tmp) {
@ -205,7 +205,8 @@ std::tuple<GrSurfaceProxyView, sk_sp<SkData>> GrThreadSafeCache::internalAdd(
return { tmp->view(), tmp->refCustomData() }; return { tmp->view(), tmp->refCustomData() };
} }
GrSurfaceProxyView GrThreadSafeCache::add(const GrUniqueKey& key, const GrSurfaceProxyView& view) { GrSurfaceProxyView GrThreadSafeCache::add(const skgpu::UniqueKey& key,
const GrSurfaceProxyView& view) {
SkAutoSpinlock lock{fSpinLock}; SkAutoSpinlock lock{fSpinLock};
GrSurfaceProxyView newView; GrSurfaceProxyView newView;
@ -214,14 +215,14 @@ GrSurfaceProxyView GrThreadSafeCache::add(const GrUniqueKey& key, const GrSurfac
} }
std::tuple<GrSurfaceProxyView, sk_sp<SkData>> GrThreadSafeCache::addWithData( std::tuple<GrSurfaceProxyView, sk_sp<SkData>> GrThreadSafeCache::addWithData(
const GrUniqueKey& key, const skgpu::UniqueKey& key,
const GrSurfaceProxyView& view) { const GrSurfaceProxyView& view) {
SkAutoSpinlock lock{fSpinLock}; SkAutoSpinlock lock{fSpinLock};
return this->internalAdd(key, view); return this->internalAdd(key, view);
} }
GrSurfaceProxyView GrThreadSafeCache::findOrAdd(const GrUniqueKey& key, GrSurfaceProxyView GrThreadSafeCache::findOrAdd(const skgpu::UniqueKey& key,
const GrSurfaceProxyView& v) { const GrSurfaceProxyView& v) {
SkAutoSpinlock lock{fSpinLock}; SkAutoSpinlock lock{fSpinLock};
@ -236,7 +237,7 @@ GrSurfaceProxyView GrThreadSafeCache::findOrAdd(const GrUniqueKey& key,
} }
std::tuple<GrSurfaceProxyView, sk_sp<SkData>> GrThreadSafeCache::findOrAddWithData( std::tuple<GrSurfaceProxyView, sk_sp<SkData>> GrThreadSafeCache::findOrAddWithData(
const GrUniqueKey& key, const skgpu::UniqueKey& key,
const GrSurfaceProxyView& v) { const GrSurfaceProxyView& v) {
SkAutoSpinlock lock{fSpinLock}; SkAutoSpinlock lock{fSpinLock};
@ -260,8 +261,8 @@ sk_sp<GrThreadSafeCache::VertexData> GrThreadSafeCache::MakeVertexData(sk_sp<GrG
return sk_sp<VertexData>(new VertexData(std::move(buffer), vertexCount, vertexSize)); return sk_sp<VertexData>(new VertexData(std::move(buffer), vertexCount, vertexSize));
} }
std::tuple<sk_sp<GrThreadSafeCache::VertexData>, sk_sp<SkData>> GrThreadSafeCache::internalFindVerts( std::tuple<sk_sp<GrThreadSafeCache::VertexData>, sk_sp<SkData>>
const GrUniqueKey& key) { GrThreadSafeCache::internalFindVerts(const skgpu::UniqueKey& key) {
Entry* tmp = fUniquelyKeyedEntryMap.find(key); Entry* tmp = fUniquelyKeyedEntryMap.find(key);
if (tmp) { if (tmp) {
this->makeExistingEntryMRU(tmp); this->makeExistingEntryMRU(tmp);
@ -271,15 +272,15 @@ std::tuple<sk_sp<GrThreadSafeCache::VertexData>, sk_sp<SkData>> GrThreadSafeCach
return {}; return {};
} }
std::tuple<sk_sp<GrThreadSafeCache::VertexData>, sk_sp<SkData>> GrThreadSafeCache::findVertsWithData( std::tuple<sk_sp<GrThreadSafeCache::VertexData>, sk_sp<SkData>>
const GrUniqueKey& key) { GrThreadSafeCache::findVertsWithData(const skgpu::UniqueKey& key) {
SkAutoSpinlock lock{fSpinLock}; SkAutoSpinlock lock{fSpinLock};
return this->internalFindVerts(key); return this->internalFindVerts(key);
} }
std::tuple<sk_sp<GrThreadSafeCache::VertexData>, sk_sp<SkData>> GrThreadSafeCache::internalAddVerts( std::tuple<sk_sp<GrThreadSafeCache::VertexData>, sk_sp<SkData>> GrThreadSafeCache::internalAddVerts(
const GrUniqueKey& key, const skgpu::UniqueKey& key,
sk_sp<VertexData> vertData, sk_sp<VertexData> vertData,
IsNewerBetter isNewerBetter) { IsNewerBetter isNewerBetter) {
Entry* tmp = fUniquelyKeyedEntryMap.find(key); Entry* tmp = fUniquelyKeyedEntryMap.find(key);
@ -297,7 +298,7 @@ std::tuple<sk_sp<GrThreadSafeCache::VertexData>, sk_sp<SkData>> GrThreadSafeCach
} }
std::tuple<sk_sp<GrThreadSafeCache::VertexData>, sk_sp<SkData>> GrThreadSafeCache::addVertsWithData( std::tuple<sk_sp<GrThreadSafeCache::VertexData>, sk_sp<SkData>> GrThreadSafeCache::addVertsWithData(
const GrUniqueKey& key, const skgpu::UniqueKey& key,
sk_sp<VertexData> vertData, sk_sp<VertexData> vertData,
IsNewerBetter isNewerBetter) { IsNewerBetter isNewerBetter) {
SkAutoSpinlock lock{fSpinLock}; SkAutoSpinlock lock{fSpinLock};
@ -305,7 +306,7 @@ std::tuple<sk_sp<GrThreadSafeCache::VertexData>, sk_sp<SkData>> GrThreadSafeCach
return this->internalAddVerts(key, std::move(vertData), isNewerBetter); return this->internalAddVerts(key, std::move(vertData), isNewerBetter);
} }
void GrThreadSafeCache::remove(const GrUniqueKey& key) { void GrThreadSafeCache::remove(const skgpu::UniqueKey& key) {
SkAutoSpinlock lock{fSpinLock}; SkAutoSpinlock lock{fSpinLock};
Entry* tmp = fUniquelyKeyedEntryMap.find(key); Entry* tmp = fUniquelyKeyedEntryMap.find(key);

View File

@ -82,20 +82,21 @@ public:
// Drop uniquely held refs that were last accessed before 'purgeTime' // Drop uniquely held refs that were last accessed before 'purgeTime'
void dropUniqueRefsOlderThan(GrStdSteadyClock::time_point purgeTime) SK_EXCLUDES(fSpinLock); void dropUniqueRefsOlderThan(GrStdSteadyClock::time_point purgeTime) SK_EXCLUDES(fSpinLock);
SkDEBUGCODE(bool has(const GrUniqueKey&) SK_EXCLUDES(fSpinLock);) SkDEBUGCODE(bool has(const skgpu::UniqueKey&) SK_EXCLUDES(fSpinLock);)
GrSurfaceProxyView find(const GrUniqueKey&) SK_EXCLUDES(fSpinLock); GrSurfaceProxyView find(const skgpu::UniqueKey&) SK_EXCLUDES(fSpinLock);
std::tuple<GrSurfaceProxyView, sk_sp<SkData>> findWithData( std::tuple<GrSurfaceProxyView, sk_sp<SkData>> findWithData(
const GrUniqueKey&) SK_EXCLUDES(fSpinLock); const skgpu::UniqueKey&) SK_EXCLUDES(fSpinLock);
GrSurfaceProxyView add(const GrUniqueKey&, const GrSurfaceProxyView&) SK_EXCLUDES(fSpinLock); GrSurfaceProxyView add(
const skgpu::UniqueKey&, const GrSurfaceProxyView&) SK_EXCLUDES(fSpinLock);
std::tuple<GrSurfaceProxyView, sk_sp<SkData>> addWithData( std::tuple<GrSurfaceProxyView, sk_sp<SkData>> addWithData(
const GrUniqueKey&, const GrSurfaceProxyView&) SK_EXCLUDES(fSpinLock); const skgpu::UniqueKey&, const GrSurfaceProxyView&) SK_EXCLUDES(fSpinLock);
GrSurfaceProxyView findOrAdd(const GrUniqueKey&, GrSurfaceProxyView findOrAdd(const skgpu::UniqueKey&,
const GrSurfaceProxyView&) SK_EXCLUDES(fSpinLock); const GrSurfaceProxyView&) SK_EXCLUDES(fSpinLock);
std::tuple<GrSurfaceProxyView, sk_sp<SkData>> findOrAddWithData( std::tuple<GrSurfaceProxyView, sk_sp<SkData>> findOrAddWithData(
const GrUniqueKey&, const GrSurfaceProxyView&) SK_EXCLUDES(fSpinLock); const skgpu::UniqueKey&, const GrSurfaceProxyView&) SK_EXCLUDES(fSpinLock);
// To hold vertex data in the cache and have it transparently transition from cpu-side to // To hold vertex data in the cache and have it transparently transition from cpu-side to
// gpu-side while being shared between all the threads we need a ref counted object that // gpu-side while being shared between all the threads we need a ref counted object that
@ -162,16 +163,16 @@ public:
size_t vertexSize); size_t vertexSize);
std::tuple<sk_sp<VertexData>, sk_sp<SkData>> findVertsWithData( std::tuple<sk_sp<VertexData>, sk_sp<SkData>> findVertsWithData(
const GrUniqueKey&) SK_EXCLUDES(fSpinLock); const skgpu::UniqueKey&) SK_EXCLUDES(fSpinLock);
typedef bool (*IsNewerBetter)(SkData* incumbent, SkData* challenger); typedef bool (*IsNewerBetter)(SkData* incumbent, SkData* challenger);
std::tuple<sk_sp<VertexData>, sk_sp<SkData>> addVertsWithData( std::tuple<sk_sp<VertexData>, sk_sp<SkData>> addVertsWithData(
const GrUniqueKey&, const skgpu::UniqueKey&,
sk_sp<VertexData>, sk_sp<VertexData>,
IsNewerBetter) SK_EXCLUDES(fSpinLock); IsNewerBetter) SK_EXCLUDES(fSpinLock);
void remove(const GrUniqueKey&) SK_EXCLUDES(fSpinLock); void remove(const skgpu::UniqueKey&) SK_EXCLUDES(fSpinLock);
// To allow gpu-created resources to have priority, we pre-emptively place a lazy proxy // To allow gpu-created resources to have priority, we pre-emptively place a lazy proxy
// in the thread-safe cache (with findOrAdd). The Trampoline object allows that lazy proxy to // in the thread-safe cache (with findOrAdd). The Trampoline object allows that lazy proxy to
@ -188,13 +189,13 @@ public:
SkBackingFit); SkBackingFit);
private: private:
struct Entry { struct Entry {
Entry(const GrUniqueKey& key, const GrSurfaceProxyView& view) Entry(const skgpu::UniqueKey& key, const GrSurfaceProxyView& view)
: fKey(key) : fKey(key)
, fView(view) , fView(view)
, fTag(Entry::kView) { , fTag(Entry::kView) {
} }
Entry(const GrUniqueKey& key, sk_sp<VertexData> vertData) Entry(const skgpu::UniqueKey& key, sk_sp<VertexData> vertData)
: fKey(key) : fKey(key)
, fVertData(std::move(vertData)) , fVertData(std::move(vertData))
, fTag(Entry::kVertData) { , fTag(Entry::kVertData) {
@ -216,7 +217,7 @@ private:
return false; return false;
} }
const GrUniqueKey& key() const { const skgpu::UniqueKey& key() const {
SkASSERT(fTag != kEmpty); SkASSERT(fTag != kEmpty);
return fKey; return fKey;
} }
@ -241,7 +242,7 @@ private:
return fVertData; return fVertData;
} }
void set(const GrUniqueKey& key, const GrSurfaceProxyView& view) { void set(const skgpu::UniqueKey& key, const GrSurfaceProxyView& view) {
SkASSERT(fTag == kEmpty); SkASSERT(fTag == kEmpty);
fKey = key; fKey = key;
fView = view; fView = view;
@ -258,7 +259,7 @@ private:
fTag = kEmpty; fTag = kEmpty;
} }
void set(const GrUniqueKey& key, sk_sp<VertexData> vertData) { void set(const skgpu::UniqueKey& key, sk_sp<VertexData> vertData) {
SkASSERT(fTag == kEmpty || fTag == kVertData); SkASSERT(fTag == kEmpty || fTag == kVertData);
fKey = key; fKey = key;
fVertData = vertData; fVertData = vertData;
@ -270,15 +271,15 @@ private:
SK_DECLARE_INTERNAL_LLIST_INTERFACE(Entry); SK_DECLARE_INTERNAL_LLIST_INTERFACE(Entry);
// for SkTDynamicHash // for SkTDynamicHash
static const GrUniqueKey& GetKey(const Entry& e) { static const skgpu::UniqueKey& GetKey(const Entry& e) {
SkASSERT(e.fTag != kEmpty); SkASSERT(e.fTag != kEmpty);
return e.fKey; return e.fKey;
} }
static uint32_t Hash(const GrUniqueKey& key) { return key.hash(); } static uint32_t Hash(const skgpu::UniqueKey& key) { return key.hash(); }
private: private:
// Note: the unique key is stored here bc it is never attached to a proxy or a GrTexture // Note: the unique key is stored here bc it is never attached to a proxy or a GrTexture
GrUniqueKey fKey; skgpu::UniqueKey fKey;
union { union {
GrSurfaceProxyView fView; GrSurfaceProxyView fView;
sk_sp<VertexData> fVertData; sk_sp<VertexData> fVertData;
@ -294,27 +295,24 @@ private:
void makeExistingEntryMRU(Entry*) SK_REQUIRES(fSpinLock); void makeExistingEntryMRU(Entry*) SK_REQUIRES(fSpinLock);
Entry* makeNewEntryMRU(Entry*) SK_REQUIRES(fSpinLock); Entry* makeNewEntryMRU(Entry*) SK_REQUIRES(fSpinLock);
Entry* getEntry(const GrUniqueKey&, const GrSurfaceProxyView&) SK_REQUIRES(fSpinLock); Entry* getEntry(const skgpu::UniqueKey&, const GrSurfaceProxyView&) SK_REQUIRES(fSpinLock);
Entry* getEntry(const GrUniqueKey&, sk_sp<VertexData>) SK_REQUIRES(fSpinLock); Entry* getEntry(const skgpu::UniqueKey&, sk_sp<VertexData>) SK_REQUIRES(fSpinLock);
void recycleEntry(Entry*) SK_REQUIRES(fSpinLock); void recycleEntry(Entry*) SK_REQUIRES(fSpinLock);
std::tuple<GrSurfaceProxyView, sk_sp<SkData>> internalFind( std::tuple<GrSurfaceProxyView, sk_sp<SkData>> internalFind(
const GrUniqueKey&) SK_REQUIRES(fSpinLock); const skgpu::UniqueKey&) SK_REQUIRES(fSpinLock);
std::tuple<GrSurfaceProxyView, sk_sp<SkData>> internalAdd( std::tuple<GrSurfaceProxyView, sk_sp<SkData>> internalAdd(
const GrUniqueKey&, const skgpu::UniqueKey&, const GrSurfaceProxyView&) SK_REQUIRES(fSpinLock);
const GrSurfaceProxyView&) SK_REQUIRES(fSpinLock);
std::tuple<sk_sp<VertexData>, sk_sp<SkData>> internalFindVerts( std::tuple<sk_sp<VertexData>, sk_sp<SkData>> internalFindVerts(
const GrUniqueKey&) SK_REQUIRES(fSpinLock); const skgpu::UniqueKey&) SK_REQUIRES(fSpinLock);
std::tuple<sk_sp<VertexData>, sk_sp<SkData>> internalAddVerts( std::tuple<sk_sp<VertexData>, sk_sp<SkData>> internalAddVerts(
const GrUniqueKey&, const skgpu::UniqueKey&, sk_sp<VertexData>, IsNewerBetter) SK_REQUIRES(fSpinLock);
sk_sp<VertexData>,
IsNewerBetter) SK_REQUIRES(fSpinLock);
mutable SkSpinlock fSpinLock; mutable SkSpinlock fSpinLock;
SkTDynamicHash<Entry, GrUniqueKey> fUniquelyKeyedEntryMap SK_GUARDED_BY(fSpinLock); SkTDynamicHash<Entry, skgpu::UniqueKey> fUniquelyKeyedEntryMap SK_GUARDED_BY(fSpinLock);
// The head of this list is the MRU // The head of this list is the MRU
SkTInternalLList<Entry> fUniquelyKeyedEntryList SK_GUARDED_BY(fSpinLock); SkTInternalLList<Entry> fUniquelyKeyedEntryList SK_GUARDED_BY(fSpinLock);

40
src/gpu/ResourceKey.cpp Normal file
View File

@ -0,0 +1,40 @@
/*
* Copyright 2021 Google LLC
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "src/core/SkOpts.h"
#include "src/gpu/ResourceKey.h"
namespace skgpu {
ScratchKey::ResourceType ScratchKey::GenerateResourceType() {
static std::atomic<int32_t> nextType{ResourceKey::kInvalidDomain + 1};
int32_t type = nextType.fetch_add(1, std::memory_order_relaxed);
if (type > SkTo<int32_t>(UINT16_MAX)) {
SK_ABORT("Too many Resource Types");
}
return static_cast<ResourceType>(type);
}
UniqueKey::Domain UniqueKey::GenerateDomain() {
static std::atomic<int32_t> nextDomain{ResourceKey::kInvalidDomain + 1};
int32_t domain = nextDomain.fetch_add(1, std::memory_order_relaxed);
if (domain > SkTo<int32_t>(UINT16_MAX)) {
SK_ABORT("Too many skgpu::UniqueKey Domains");
}
return static_cast<Domain>(domain);
}
uint32_t ResourceKeyHash(const uint32_t* data, size_t size) {
return SkOpts::hash(data, size);
}
} // namespace skgpu

View File

@ -5,25 +5,28 @@
* found in the LICENSE file. * found in the LICENSE file.
*/ */
#ifndef GrResourceKey_DEFINED #ifndef skgpu_ResourceKey_DEFINED
#define GrResourceKey_DEFINED #define skgpu_ResourceKey_DEFINED
#include "include/core/SkData.h" #include "include/core/SkData.h"
#include "include/core/SkString.h" #include "include/core/SkString.h"
#include "include/gpu/GrTypes.h"
#include "include/private/SkOnce.h" #include "include/private/SkOnce.h"
#include "include/private/SkTemplates.h" #include "include/private/SkTemplates.h"
#include "include/private/SkTo.h" #include "include/private/SkTo.h"
#include <new> #include <new>
uint32_t GrResourceKeyHash(const uint32_t* data, size_t size); class TestResource;
namespace skgpu {
uint32_t ResourceKeyHash(const uint32_t* data, size_t size);
/** /**
* Base class for all GrGpuResource cache keys. There are two types of cache keys. Refer to the * Base class for all gpu Resource cache keys. There are two types of cache keys. Refer to the
* comments for each key type below. * comments for each key type below.
*/ */
class GrResourceKey { class ResourceKey {
public: public:
uint32_t hash() const { uint32_t hash() const {
this->validate(); this->validate();
@ -46,7 +49,7 @@ public:
return; return;
} }
uint32_t* hash = &fKey->fKey[kHash_MetaDataIdx]; uint32_t* hash = &fKey->fKey[kHash_MetaDataIdx];
*hash = GrResourceKeyHash(hash + 1, fKey->internalSize() - sizeof(uint32_t)); *hash = ResourceKeyHash(hash + 1, fKey->internalSize() - sizeof(uint32_t));
fKey->validate(); fKey->validate();
fKey = nullptr; fKey = nullptr;
} }
@ -59,7 +62,7 @@ public:
} }
protected: protected:
Builder(GrResourceKey* key, uint32_t domain, int data32Count) : fKey(key) { Builder(ResourceKey* key, uint32_t domain, int data32Count) : fKey(key) {
size_t count = SkToSizeT(data32Count); size_t count = SkToSizeT(data32Count);
SkASSERT(domain != kInvalidDomain); SkASSERT(domain != kInvalidDomain);
key->fKey.reset(kMetaDataCnt + count); key->fKey.reset(kMetaDataCnt + count);
@ -70,13 +73,13 @@ public:
} }
private: private:
GrResourceKey* fKey; ResourceKey* fKey;
}; };
protected: protected:
static const uint32_t kInvalidDomain = 0; static const uint32_t kInvalidDomain = 0;
GrResourceKey() { this->reset(); } ResourceKey() { this->reset(); }
/** Reset to an invalid key. */ /** Reset to an invalid key. */
void reset() { void reset() {
@ -85,14 +88,14 @@ protected:
fKey[kDomainAndSize_MetaDataIdx] = kInvalidDomain; fKey[kDomainAndSize_MetaDataIdx] = kInvalidDomain;
} }
bool operator==(const GrResourceKey& that) const { bool operator==(const ResourceKey& that) const {
// Both keys should be sized to at least contain the meta data. The metadata contains each // Both keys should be sized to at least contain the meta data. The metadata contains each
// key's length. So the second memcmp should only run if the keys have the same length. // key's length. So the second memcmp should only run if the keys have the same length.
return 0 == memcmp(fKey.get(), that.fKey.get(), kMetaDataCnt*sizeof(uint32_t)) && return 0 == memcmp(fKey.get(), that.fKey.get(), kMetaDataCnt*sizeof(uint32_t)) &&
0 == memcmp(&fKey[kMetaDataCnt], &that.fKey[kMetaDataCnt], this->dataSize()); 0 == memcmp(&fKey[kMetaDataCnt], &that.fKey[kMetaDataCnt], this->dataSize());
} }
GrResourceKey& operator=(const GrResourceKey& that) { ResourceKey& operator=(const ResourceKey& that) {
if (this != &that) { if (this != &that) {
if (!that.isValid()) { if (!that.isValid()) {
this->reset(); this->reset();
@ -152,12 +155,12 @@ private:
void validate() const { void validate() const {
SkASSERT(this->isValid()); SkASSERT(this->isValid());
SkASSERT(fKey[kHash_MetaDataIdx] == SkASSERT(fKey[kHash_MetaDataIdx] ==
GrResourceKeyHash(&fKey[kHash_MetaDataIdx] + 1, ResourceKeyHash(&fKey[kHash_MetaDataIdx] + 1,
this->internalSize() - sizeof(uint32_t))); this->internalSize() - sizeof(uint32_t)));
SkASSERT(SkIsAlign4(this->internalSize())); SkASSERT(SkIsAlign4(this->internalSize()));
} }
friend class TestResource; // For unit test to access kMetaDataCnt. friend class ::TestResource; // For unit test to access kMetaDataCnt.
// bmp textures require 5 uint32_t values. // bmp textures require 5 uint32_t values.
SkAutoSTMalloc<kMetaDataCnt + 5, uint32_t> fKey; SkAutoSTMalloc<kMetaDataCnt + 5, uint32_t> fKey;
@ -184,10 +187,7 @@ private:
* consume_blur(texture[0]); * consume_blur(texture[0]);
* texture[0]->unref(); // texture 0 can now be recycled for the next request with scratchKey * texture[0]->unref(); // texture 0 can now be recycled for the next request with scratchKey
*/ */
class GrScratchKey : public GrResourceKey { class ScratchKey : public ResourceKey {
private:
using INHERITED = GrResourceKey;
public: public:
/** Uniquely identifies the type of resource that is cached as scratch. */ /** Uniquely identifies the type of resource that is cached as scratch. */
typedef uint32_t ResourceType; typedef uint32_t ResourceType;
@ -196,29 +196,29 @@ public:
static ResourceType GenerateResourceType(); static ResourceType GenerateResourceType();
/** Creates an invalid scratch key. It must be initialized using a Builder object before use. */ /** Creates an invalid scratch key. It must be initialized using a Builder object before use. */
GrScratchKey() {} ScratchKey() {}
GrScratchKey(const GrScratchKey& that) { *this = that; } ScratchKey(const ScratchKey& that) { *this = that; }
/** reset() returns the key to the invalid state. */ /** reset() returns the key to the invalid state. */
using INHERITED::reset; using ResourceKey::reset;
using INHERITED::isValid; using ResourceKey::isValid;
ResourceType resourceType() const { return this->domain(); } ResourceType resourceType() const { return this->domain(); }
GrScratchKey& operator=(const GrScratchKey& that) { ScratchKey& operator=(const ScratchKey& that) {
this->INHERITED::operator=(that); this->ResourceKey::operator=(that);
return *this; return *this;
} }
bool operator==(const GrScratchKey& that) const { return this->INHERITED::operator==(that); } bool operator==(const ScratchKey& that) const { return this->ResourceKey::operator==(that); }
bool operator!=(const GrScratchKey& that) const { return !(*this == that); } bool operator!=(const ScratchKey& that) const { return !(*this == that); }
class Builder : public INHERITED::Builder { class Builder : public ResourceKey::Builder {
public: public:
Builder(GrScratchKey* key, ResourceType type, int data32Count) Builder(ScratchKey* key, ResourceType type, int data32Count)
: INHERITED::Builder(key, type, data32Count) {} : ResourceKey::Builder(key, type, data32Count) {}
}; };
}; };
@ -236,34 +236,31 @@ public:
* Unique keys preempt scratch keys. While a resource has a unique key it is inaccessible via its * Unique keys preempt scratch keys. While a resource has a unique key it is inaccessible via its
* scratch key. It can become scratch again if the unique key is removed. * scratch key. It can become scratch again if the unique key is removed.
*/ */
class GrUniqueKey : public GrResourceKey { class UniqueKey : public ResourceKey {
private:
using INHERITED = GrResourceKey;
public: public:
typedef uint32_t Domain; typedef uint32_t Domain;
/** Generate a Domain for unique keys. */ /** Generate a Domain for unique keys. */
static Domain GenerateDomain(); static Domain GenerateDomain();
/** Creates an invalid unique key. It must be initialized using a Builder object before use. */ /** Creates an invalid unique key. It must be initialized using a Builder object before use. */
GrUniqueKey() : fTag(nullptr) {} UniqueKey() : fTag(nullptr) {}
GrUniqueKey(const GrUniqueKey& that) { *this = that; } UniqueKey(const UniqueKey& that) { *this = that; }
/** reset() returns the key to the invalid state. */ /** reset() returns the key to the invalid state. */
using INHERITED::reset; using ResourceKey::reset;
using INHERITED::isValid; using ResourceKey::isValid;
GrUniqueKey& operator=(const GrUniqueKey& that) { UniqueKey& operator=(const UniqueKey& that) {
this->INHERITED::operator=(that); this->ResourceKey::operator=(that);
this->setCustomData(sk_ref_sp(that.getCustomData())); this->setCustomData(sk_ref_sp(that.getCustomData()));
fTag = that.fTag; fTag = that.fTag;
return *this; return *this;
} }
bool operator==(const GrUniqueKey& that) const { return this->INHERITED::operator==(that); } bool operator==(const UniqueKey& that) const { return this->ResourceKey::operator==(that); }
bool operator!=(const GrUniqueKey& that) const { return !(*this == that); } bool operator!=(const UniqueKey& that) const { return !(*this == that); }
void setCustomData(sk_sp<SkData> data) { fData = std::move(data); } void setCustomData(sk_sp<SkData> data) { fData = std::move(data); }
SkData* getCustomData() const { return fData.get(); } SkData* getCustomData() const { return fData.get(); }
@ -274,21 +271,23 @@ public:
#ifdef SK_DEBUG #ifdef SK_DEBUG
void dump(const char* label) const { void dump(const char* label) const {
SkDebugf("%s tag: %s\n", label, fTag ? fTag : "None"); SkDebugf("%s tag: %s\n", label, fTag ? fTag : "None");
this->INHERITED::dump(); this->ResourceKey::dump();
} }
#endif #endif
class Builder : public INHERITED::Builder { class Builder : public ResourceKey::Builder {
public: public:
Builder(GrUniqueKey* key, Domain type, int data32Count, const char* tag = nullptr) Builder(UniqueKey* key, Domain type, int data32Count, const char* tag = nullptr)
: INHERITED::Builder(key, type, data32Count) { : ResourceKey::Builder(key, type, data32Count) {
key->fTag = tag; key->fTag = tag;
} }
/** Used to build a key that wraps another key and adds additional data. */ /** Used to build a key that wraps another key and adds additional data. */
Builder(GrUniqueKey* key, const GrUniqueKey& innerKey, Domain domain, int extraData32Cnt, Builder(UniqueKey* key, const UniqueKey& innerKey, Domain domain, int extraData32Cnt,
const char* tag = nullptr) const char* tag = nullptr)
: INHERITED::Builder(key, domain, Data32CntForInnerKey(innerKey) + extraData32Cnt) { : ResourceKey::Builder(key,
domain,
Data32CntForInnerKey(innerKey) + extraData32Cnt) {
SkASSERT(&innerKey != key); SkASSERT(&innerKey != key);
// add the inner key to the end of the key so that op[] can be indexed normally. // add the inner key to the end of the key so that op[] can be indexed normally.
uint32_t* innerKeyData = &this->operator[](extraData32Cnt); uint32_t* innerKeyData = &this->operator[](extraData32Cnt);
@ -299,7 +298,7 @@ public:
} }
private: private:
static int Data32CntForInnerKey(const GrUniqueKey& innerKey) { static int Data32CntForInnerKey(const UniqueKey& innerKey) {
// key data + domain // key data + domain
return SkToInt((innerKey.dataSize() >> 2) + 1); return SkToInt((innerKey.dataSize() >> 2) + 1);
} }
@ -311,52 +310,56 @@ private:
}; };
/** /**
* It is common to need a frequently reused GrUniqueKey where the only requirement is that the key * It is common to need a frequently reused UniqueKey where the only requirement is that the key
* is unique. These macros create such a key in a thread safe manner so the key can be truly global * is unique. These macros create such a key in a thread safe manner so the key can be truly global
* and only constructed once. * and only constructed once.
*/ */
/** Place outside of function/class definitions. */ /** Place outside of function/class definitions. */
#define GR_DECLARE_STATIC_UNIQUE_KEY(name) static SkOnce name##_once #define SKGPU_DECLARE_STATIC_UNIQUE_KEY(name) static SkOnce name##_once
/** Place inside function where the key is used. */ /** Place inside function where the key is used. */
#define GR_DEFINE_STATIC_UNIQUE_KEY(name) \ #define SKGPU_DEFINE_STATIC_UNIQUE_KEY(name) \
static SkAlignedSTStorage<1, GrUniqueKey> name##_storage; \ static SkAlignedSTStorage<1, skgpu::UniqueKey> name##_storage; \
name##_once(gr_init_static_unique_key_once, &name##_storage); \ name##_once(skgpu::skgpu_init_static_unique_key_once, &name##_storage); \
static const GrUniqueKey& name = *reinterpret_cast<GrUniqueKey*>(name##_storage.get()) static const skgpu::UniqueKey& name = \
*reinterpret_cast<skgpu::UniqueKey*>(name##_storage.get())
static inline void gr_init_static_unique_key_once(SkAlignedSTStorage<1, GrUniqueKey>* keyStorage) { static inline void skgpu_init_static_unique_key_once(SkAlignedSTStorage<1, UniqueKey>* keyStorage) {
GrUniqueKey* key = new (keyStorage->get()) GrUniqueKey; UniqueKey* key = new (keyStorage->get()) UniqueKey;
GrUniqueKey::Builder builder(key, GrUniqueKey::GenerateDomain(), 0); UniqueKey::Builder builder(key, UniqueKey::GenerateDomain(), 0);
} }
// The cache listens for these messages to purge junk resources proactively. // The cache listens for these messages to purge junk resources proactively.
class GrUniqueKeyInvalidatedMessage { class UniqueKeyInvalidatedMessage {
public: public:
GrUniqueKeyInvalidatedMessage() = default; UniqueKeyInvalidatedMessage() = default;
GrUniqueKeyInvalidatedMessage(const GrUniqueKey& key, uint32_t contextUniqueID, UniqueKeyInvalidatedMessage(const UniqueKey& key,
bool inThreadSafeCache = false) uint32_t contextUniqueID,
bool inThreadSafeCache = false)
: fKey(key), fContextID(contextUniqueID), fInThreadSafeCache(inThreadSafeCache) { : fKey(key), fContextID(contextUniqueID), fInThreadSafeCache(inThreadSafeCache) {
SkASSERT(SK_InvalidUniqueID != contextUniqueID); SkASSERT(SK_InvalidUniqueID != contextUniqueID);
} }
GrUniqueKeyInvalidatedMessage(const GrUniqueKeyInvalidatedMessage&) = default; UniqueKeyInvalidatedMessage(const UniqueKeyInvalidatedMessage&) = default;
GrUniqueKeyInvalidatedMessage& operator=(const GrUniqueKeyInvalidatedMessage&) = default; UniqueKeyInvalidatedMessage& operator=(const UniqueKeyInvalidatedMessage&) = default;
const GrUniqueKey& key() const { return fKey; } const UniqueKey& key() const { return fKey; }
uint32_t contextID() const { return fContextID; } uint32_t contextID() const { return fContextID; }
bool inThreadSafeCache() const { return fInThreadSafeCache; } bool inThreadSafeCache() const { return fInThreadSafeCache; }
private: private:
GrUniqueKey fKey; UniqueKey fKey;
uint32_t fContextID = SK_InvalidUniqueID; uint32_t fContextID = SK_InvalidUniqueID;
bool fInThreadSafeCache = false; bool fInThreadSafeCache = false;
}; };
static inline bool SkShouldPostMessageToBus(const GrUniqueKeyInvalidatedMessage& msg, static inline bool SkShouldPostMessageToBus(const UniqueKeyInvalidatedMessage& msg,
uint32_t msgBusUniqueID) { uint32_t msgBusUniqueID) {
return msg.contextID() == msgBusUniqueID; return msg.contextID() == msgBusUniqueID;
} }
#endif } // namespace skgpu
#endif // skgpu_ResourceKey_DEFINED

View File

@ -48,12 +48,12 @@
#include "src/image/SkImage_Base.h" #include "src/image/SkImage_Base.h"
#include "src/shaders/SkShaderBase.h" #include "src/shaders/SkShaderBase.h"
void GrMakeKeyFromImageID(GrUniqueKey* key, uint32_t imageID, const SkIRect& imageBounds) { void GrMakeKeyFromImageID(skgpu::UniqueKey* key, uint32_t imageID, const SkIRect& imageBounds) {
SkASSERT(key); SkASSERT(key);
SkASSERT(imageID); SkASSERT(imageID);
SkASSERT(!imageBounds.isEmpty()); SkASSERT(!imageBounds.isEmpty());
static const GrUniqueKey::Domain kImageIDDomain = GrUniqueKey::GenerateDomain(); static const skgpu::UniqueKey::Domain kImageIDDomain = skgpu::UniqueKey::GenerateDomain();
GrUniqueKey::Builder builder(key, kImageIDDomain, 5, "Image"); skgpu::UniqueKey::Builder builder(key, kImageIDDomain, 5, "Image");
builder[0] = imageID; builder[0] = imageID;
builder[1] = imageBounds.fLeft; builder[1] = imageBounds.fLeft;
builder[2] = imageBounds.fTop; builder[2] = imageBounds.fTop;
@ -63,18 +63,19 @@ void GrMakeKeyFromImageID(GrUniqueKey* key, uint32_t imageID, const SkIRect& ima
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
sk_sp<SkIDChangeListener> GrMakeUniqueKeyInvalidationListener(GrUniqueKey* key, sk_sp<SkIDChangeListener> GrMakeUniqueKeyInvalidationListener(skgpu::UniqueKey* key,
uint32_t contextID) { uint32_t contextID) {
class Listener : public SkIDChangeListener { class Listener : public SkIDChangeListener {
public: public:
Listener(const GrUniqueKey& key, uint32_t contextUniqueID) : fMsg(key, contextUniqueID) {} Listener(const skgpu::UniqueKey& key, uint32_t contextUniqueID)
: fMsg(key, contextUniqueID) {}
void changed() override { void changed() override {
SkMessageBus<GrUniqueKeyInvalidatedMessage, uint32_t>::Post(fMsg); SkMessageBus<skgpu::UniqueKeyInvalidatedMessage, uint32_t>::Post(fMsg);
} }
private: private:
GrUniqueKeyInvalidatedMessage fMsg; skgpu::UniqueKeyInvalidatedMessage fMsg;
}; };
auto listener = sk_make_sp<Listener>(*key, contextID); auto listener = sk_make_sp<Listener>(*key, contextID);
@ -176,7 +177,7 @@ GrMakeCachedBitmapProxyView(GrRecordingContext* rContext,
GrProxyProvider* proxyProvider = rContext->priv().proxyProvider(); GrProxyProvider* proxyProvider = rContext->priv().proxyProvider();
const GrCaps* caps = rContext->priv().caps(); const GrCaps* caps = rContext->priv().caps();
GrUniqueKey key; skgpu::UniqueKey key;
SkIPoint origin = bitmap.pixelRefOrigin(); SkIPoint origin = bitmap.pixelRefOrigin();
SkIRect subset = SkIRect::MakePtSize(origin, bitmap.dimensions()); SkIRect subset = SkIRect::MakePtSize(origin, bitmap.dimensions());
GrMakeKeyFromImageID(&key, bitmap.pixelRef()->getGenerationID(), subset); GrMakeKeyFromImageID(&key, bitmap.pixelRef()->getGenerationID(), subset);

View File

@ -30,7 +30,6 @@ class GrPaint;
class GrRecordingContext; class GrRecordingContext;
class GrResourceProvider; class GrResourceProvider;
class GrTextureProxy; class GrTextureProxy;
class GrUniqueKey;
class SkBitmap; class SkBitmap;
class SkData; class SkData;
class SkMatrix; class SkMatrix;
@ -40,6 +39,10 @@ class SkPixelRef;
class SkPixmap; class SkPixmap;
struct SkIRect; struct SkIRect;
namespace skgpu {
class UniqueKey;
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// Color type conversions // Color type conversions
@ -187,15 +190,16 @@ GrMakeUncachedBitmapProxyView(GrRecordingContext*,
* - SkImage * - SkImage
* - SkImageGenerator * - SkImageGenerator
*/ */
void GrMakeKeyFromImageID(GrUniqueKey* key, uint32_t imageID, const SkIRect& imageBounds); void GrMakeKeyFromImageID(skgpu::UniqueKey* key, uint32_t imageID, const SkIRect& imageBounds);
/** /**
* Makes a SkIDChangeListener from a GrUniqueKey. The key will be invalidated in the resource * Makes a SkIDChangeListener from a skgpu::UniqueKey. The key will be invalidated in the resource
* cache if the ID becomes invalid. This also modifies the key so that it will cause the listener * cache if the ID becomes invalid. This also modifies the key so that it will cause the listener
* to be deregistered if the key is destroyed (to prevent unbounded listener growth when resources * to be deregistered if the key is destroyed (to prevent unbounded listener growth when resources
* are purged before listeners trigger). * are purged before listeners trigger).
*/ */
sk_sp<SkIDChangeListener> GrMakeUniqueKeyInvalidationListener(GrUniqueKey*, uint32_t contextID); sk_sp<SkIDChangeListener> GrMakeUniqueKeyInvalidationListener(skgpu::UniqueKey*,
uint32_t contextID);
static inline bool GrValidCubicResampler(SkCubicResampler cubic) { static inline bool GrValidCubicResampler(SkCubicResampler cubic) {
return cubic.B >= 0 && cubic.C >= 0; return cubic.B >= 0 && cubic.C >= 0;

View File

@ -86,10 +86,10 @@ GrMatrixConvolutionEffect::KernelWrapper::Make(GrRecordingContext* rContext,
// TODO: Pick cache or dont-cache based on observed perf. // TODO: Pick cache or dont-cache based on observed perf.
static constexpr bool kCacheKernelTexture = true; static constexpr bool kCacheKernelTexture = true;
GrUniqueKey key; skgpu::UniqueKey key;
if (kCacheKernelTexture) { if (kCacheKernelTexture) {
static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDomain(); static const skgpu::UniqueKey::Domain kDomain = skgpu::UniqueKey::GenerateDomain();
GrUniqueKey::Builder builder(&key, kDomain, length, "Matrix Convolution Kernel"); skgpu::UniqueKey::Builder builder(&key, kDomain, length, "Matrix Convolution Kernel");
// Texture cache key is the exact content of the kernel. // Texture cache key is the exact content of the kernel.
static_assert(sizeof(float) == 4); static_assert(sizeof(float) == 4);
for (int i = 0; i < length; i++) { for (int i = 0; i < length; i++) {

View File

@ -212,7 +212,9 @@ private:
} }
// This avoids an inherits via dominance warning on MSVC. // This avoids an inherits via dominance warning on MSVC.
void computeScratchKey(GrScratchKey* key) const override { GrTexture::computeScratchKey(key); } void computeScratchKey(skgpu::ScratchKey* key) const override {
GrTexture::computeScratchKey(key);
}
}; };
#endif #endif

View File

@ -75,10 +75,10 @@ static const uint16_t kQuadIdxBufPattern[] = {
static const int kIdxsPerQuad = SK_ARRAY_COUNT(kQuadIdxBufPattern); static const int kIdxsPerQuad = SK_ARRAY_COUNT(kQuadIdxBufPattern);
static const int kQuadNumVertices = 5; static const int kQuadNumVertices = 5;
static const int kQuadsNumInIdxBuffer = 256; static const int kQuadsNumInIdxBuffer = 256;
GR_DECLARE_STATIC_UNIQUE_KEY(gQuadsIndexBufferKey); SKGPU_DECLARE_STATIC_UNIQUE_KEY(gQuadsIndexBufferKey);
sk_sp<const GrBuffer> get_quads_index_buffer(GrResourceProvider* resourceProvider) { sk_sp<const GrBuffer> get_quads_index_buffer(GrResourceProvider* resourceProvider) {
GR_DEFINE_STATIC_UNIQUE_KEY(gQuadsIndexBufferKey); SKGPU_DEFINE_STATIC_UNIQUE_KEY(gQuadsIndexBufferKey);
return resourceProvider->findOrCreatePatternedIndexBuffer( return resourceProvider->findOrCreatePatternedIndexBuffer(
kQuadIdxBufPattern, kIdxsPerQuad, kQuadsNumInIdxBuffer, kQuadNumVertices, kQuadIdxBufPattern, kIdxsPerQuad, kQuadsNumInIdxBuffer, kQuadNumVertices,
gQuadsIndexBufferKey); gQuadsIndexBufferKey);
@ -109,10 +109,10 @@ static const int kIdxsPerLineSeg = SK_ARRAY_COUNT(kLineSegIdxBufPattern);
static const int kLineSegNumVertices = 6; static const int kLineSegNumVertices = 6;
static const int kLineSegsNumInIdxBuffer = 256; static const int kLineSegsNumInIdxBuffer = 256;
GR_DECLARE_STATIC_UNIQUE_KEY(gLinesIndexBufferKey); SKGPU_DECLARE_STATIC_UNIQUE_KEY(gLinesIndexBufferKey);
sk_sp<const GrBuffer> get_lines_index_buffer(GrResourceProvider* resourceProvider) { sk_sp<const GrBuffer> get_lines_index_buffer(GrResourceProvider* resourceProvider) {
GR_DEFINE_STATIC_UNIQUE_KEY(gLinesIndexBufferKey); SKGPU_DEFINE_STATIC_UNIQUE_KEY(gLinesIndexBufferKey);
return resourceProvider->findOrCreatePatternedIndexBuffer( return resourceProvider->findOrCreatePatternedIndexBuffer(
kLineSegIdxBufPattern, kIdxsPerLineSeg, kLineSegsNumInIdxBuffer, kLineSegNumVertices, kLineSegIdxBufPattern, kIdxsPerLineSeg, kLineSegsNumInIdxBuffer, kLineSegNumVertices,
gLinesIndexBufferKey); gLinesIndexBufferKey);

View File

@ -181,7 +181,7 @@ void DrawAtlasPathOp::onPrePrepare(GrRecordingContext* rContext,
rContext->priv().recordProgramInfo(fProgram); rContext->priv().recordProgramInfo(fProgram);
} }
GR_DECLARE_STATIC_UNIQUE_KEY(gUnitQuadBufferKey); SKGPU_DECLARE_STATIC_UNIQUE_KEY(gUnitQuadBufferKey);
void DrawAtlasPathOp::onPrepare(GrOpFlushState* flushState) { void DrawAtlasPathOp::onPrepare(GrOpFlushState* flushState) {
if (!fProgram) { if (!fProgram) {
@ -207,7 +207,7 @@ void DrawAtlasPathOp::onPrepare(GrOpFlushState* flushState) {
if (!flushState->caps().shaderCaps()->vertexIDSupport()) { if (!flushState->caps().shaderCaps()->vertexIDSupport()) {
constexpr static SkPoint kUnitQuad[4] = {{0,0}, {0,1}, {1,0}, {1,1}}; constexpr static SkPoint kUnitQuad[4] = {{0,0}, {0,1}, {1,0}, {1,1}};
GR_DEFINE_STATIC_UNIQUE_KEY(gUnitQuadBufferKey); SKGPU_DEFINE_STATIC_UNIQUE_KEY(gUnitQuadBufferKey);
fVertexBufferIfNoIDSupport = flushState->resourceProvider()->findOrMakeStaticBuffer( fVertexBufferIfNoIDSupport = flushState->resourceProvider()->findOrMakeStaticBuffer(
GrGpuBufferType::kVertex, sizeof(kUnitQuad), kUnitQuad, gUnitQuadBufferKey); GrGpuBufferType::kVertex, sizeof(kUnitQuad), kUnitQuad, gUnitQuadBufferKey);

View File

@ -470,7 +470,7 @@ static constexpr CoverageVertex kVertexData[] = {
{{{0,0,0,1}}, {{-1,+1}}, {{0,-kOctoOffset}}, {{-1,+1}}, 0, 0}, {{{0,0,0,1}}, {{-1,+1}}, {{0,-kOctoOffset}}, {{-1,+1}}, 0, 0},
{{{0,0,0,1}}, {{-1,+1}}, {{+kOctoOffset,0}}, {{-1,+1}}, 0, 0}}; {{{0,0,0,1}}, {{-1,+1}}, {{+kOctoOffset,0}}, {{-1,+1}}, 0, 0}};
GR_DECLARE_STATIC_UNIQUE_KEY(gVertexBufferKey); SKGPU_DECLARE_STATIC_UNIQUE_KEY(gVertexBufferKey);
static constexpr uint16_t kIndexData[] = { static constexpr uint16_t kIndexData[] = {
// Inset octagon (solid coverage). // Inset octagon (solid coverage).
@ -511,7 +511,7 @@ static constexpr uint16_t kIndexData[] = {
39, 36, 38, 39, 36, 38,
36, 38, 37}; 36, 38, 37};
GR_DECLARE_STATIC_UNIQUE_KEY(gIndexBufferKey); SKGPU_DECLARE_STATIC_UNIQUE_KEY(gIndexBufferKey);
void FillRRectOpImpl::onPrepareDraws(GrMeshDrawTarget* target) { void FillRRectOpImpl::onPrepareDraws(GrMeshDrawTarget* target) {
if (!fProgramInfo) { if (!fProgramInfo) {
@ -549,13 +549,13 @@ void FillRRectOpImpl::onPrepareDraws(GrMeshDrawTarget* target) {
SkASSERT(instanceWrter == end); SkASSERT(instanceWrter == end);
} }
GR_DEFINE_STATIC_UNIQUE_KEY(gIndexBufferKey); SKGPU_DEFINE_STATIC_UNIQUE_KEY(gIndexBufferKey);
fIndexBuffer = target->resourceProvider()->findOrMakeStaticBuffer(GrGpuBufferType::kIndex, fIndexBuffer = target->resourceProvider()->findOrMakeStaticBuffer(GrGpuBufferType::kIndex,
sizeof(kIndexData), sizeof(kIndexData),
kIndexData, gIndexBufferKey); kIndexData, gIndexBufferKey);
GR_DEFINE_STATIC_UNIQUE_KEY(gVertexBufferKey); SKGPU_DEFINE_STATIC_UNIQUE_KEY(gVertexBufferKey);
fVertexBuffer = target->resourceProvider()->findOrMakeStaticBuffer(GrGpuBufferType::kVertex, fVertexBuffer = target->resourceProvider()->findOrMakeStaticBuffer(GrGpuBufferType::kVertex,
sizeof(kVertexData), sizeof(kVertexData),

View File

@ -2846,12 +2846,12 @@ private:
static const int kNumRRectsInIndexBuffer = 256; static const int kNumRRectsInIndexBuffer = 256;
GR_DECLARE_STATIC_UNIQUE_KEY(gStrokeRRectOnlyIndexBufferKey); SKGPU_DECLARE_STATIC_UNIQUE_KEY(gStrokeRRectOnlyIndexBufferKey);
GR_DECLARE_STATIC_UNIQUE_KEY(gRRectOnlyIndexBufferKey); SKGPU_DECLARE_STATIC_UNIQUE_KEY(gRRectOnlyIndexBufferKey);
static sk_sp<const GrBuffer> get_rrect_index_buffer(RRectType type, static sk_sp<const GrBuffer> get_rrect_index_buffer(RRectType type,
GrResourceProvider* resourceProvider) { GrResourceProvider* resourceProvider) {
GR_DEFINE_STATIC_UNIQUE_KEY(gStrokeRRectOnlyIndexBufferKey); SKGPU_DEFINE_STATIC_UNIQUE_KEY(gStrokeRRectOnlyIndexBufferKey);
GR_DEFINE_STATIC_UNIQUE_KEY(gRRectOnlyIndexBufferKey); SKGPU_DEFINE_STATIC_UNIQUE_KEY(gRRectOnlyIndexBufferKey);
switch (type) { switch (type) {
case kFill_RRectType: case kFill_RRectType:
return resourceProvider->findOrCreatePatternedIndexBuffer( return resourceProvider->findOrCreatePatternedIndexBuffer(

View File

@ -398,7 +398,7 @@ void PathInnerTriangulateOp::onPrePrepare(GrRecordingContext* context,
} }
} }
GR_DECLARE_STATIC_UNIQUE_KEY(gHullVertexBufferKey); SKGPU_DECLARE_STATIC_UNIQUE_KEY(gHullVertexBufferKey);
void PathInnerTriangulateOp::onPrepare(GrOpFlushState* flushState) { void PathInnerTriangulateOp::onPrepare(GrOpFlushState* flushState) {
const GrCaps& caps = flushState->caps(); const GrCaps& caps = flushState->caps();
@ -460,7 +460,7 @@ void PathInnerTriangulateOp::onPrepare(GrOpFlushState* flushState) {
if (!caps.shaderCaps()->vertexIDSupport()) { if (!caps.shaderCaps()->vertexIDSupport()) {
constexpr static float kStripOrderIDs[4] = {0, 1, 3, 2}; constexpr static float kStripOrderIDs[4] = {0, 1, 3, 2};
GR_DEFINE_STATIC_UNIQUE_KEY(gHullVertexBufferKey); SKGPU_DEFINE_STATIC_UNIQUE_KEY(gHullVertexBufferKey);
fHullVertexBufferIfNoIDSupport = flushState->resourceProvider()->findOrMakeStaticBuffer( fHullVertexBufferIfNoIDSupport = flushState->resourceProvider()->findOrMakeStaticBuffer(
GrGpuBufferType::kVertex, sizeof(kStripOrderIDs), kStripOrderIDs, GrGpuBufferType::kVertex, sizeof(kStripOrderIDs), kStripOrderIDs,

View File

@ -221,7 +221,7 @@ void PathStencilCoverOp::onPrePrepare(GrRecordingContext* context,
} }
} }
GR_DECLARE_STATIC_UNIQUE_KEY(gUnitQuadBufferKey); SKGPU_DECLARE_STATIC_UNIQUE_KEY(gUnitQuadBufferKey);
void PathStencilCoverOp::onPrepare(GrOpFlushState* flushState) { void PathStencilCoverOp::onPrepare(GrOpFlushState* flushState) {
if (!fTessellator) { if (!fTessellator) {
@ -307,7 +307,7 @@ void PathStencilCoverOp::onPrepare(GrOpFlushState* flushState) {
if (!flushState->caps().shaderCaps()->vertexIDSupport()) { if (!flushState->caps().shaderCaps()->vertexIDSupport()) {
constexpr static SkPoint kUnitQuad[4] = {{0,0}, {0,1}, {1,0}, {1,1}}; constexpr static SkPoint kUnitQuad[4] = {{0,0}, {0,1}, {1,0}, {1,1}};
GR_DEFINE_STATIC_UNIQUE_KEY(gUnitQuadBufferKey); SKGPU_DEFINE_STATIC_UNIQUE_KEY(gUnitQuadBufferKey);
fBBoxVertexBufferIfNoIDSupport = flushState->resourceProvider()->findOrMakeStaticBuffer( fBBoxVertexBufferIfNoIDSupport = flushState->resourceProvider()->findOrMakeStaticBuffer(
GrGpuBufferType::kVertex, sizeof(kUnitQuad), kUnitQuad, gUnitQuadBufferKey); GrGpuBufferType::kVertex, sizeof(kUnitQuad), kUnitQuad, gUnitQuadBufferKey);

View File

@ -666,9 +666,9 @@ private:
namespace skgpu::v1::ShadowRRectOp { namespace skgpu::v1::ShadowRRectOp {
static GrSurfaceProxyView create_falloff_texture(GrRecordingContext* rContext) { static GrSurfaceProxyView create_falloff_texture(GrRecordingContext* rContext) {
static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDomain(); static const skgpu::UniqueKey::Domain kDomain = skgpu::UniqueKey::GenerateDomain();
GrUniqueKey key; skgpu::UniqueKey key;
GrUniqueKey::Builder builder(&key, kDomain, 0, "Shadow Gaussian Falloff"); skgpu::UniqueKey::Builder builder(&key, kDomain, 0, "Shadow Gaussian Falloff");
builder.finish(); builder.finish();
auto threadSafeCache = rContext->priv().threadSafeCache(); auto threadSafeCache = rContext->priv().threadSafeCache();

View File

@ -278,15 +278,15 @@ bool SoftwarePathRenderer::onDrawPath(const DrawPathArgs& args) {
} }
} }
GrUniqueKey maskKey; skgpu::UniqueKey maskKey;
if (useCache) { if (useCache) {
// We require the upper left 2x2 of the matrix to match exactly for a cache hit. // We require the upper left 2x2 of the matrix to match exactly for a cache hit.
SkScalar sx = args.fViewMatrix->get(SkMatrix::kMScaleX); SkScalar sx = args.fViewMatrix->get(SkMatrix::kMScaleX);
SkScalar sy = args.fViewMatrix->get(SkMatrix::kMScaleY); SkScalar sy = args.fViewMatrix->get(SkMatrix::kMScaleY);
SkScalar kx = args.fViewMatrix->get(SkMatrix::kMSkewX); SkScalar kx = args.fViewMatrix->get(SkMatrix::kMSkewX);
SkScalar ky = args.fViewMatrix->get(SkMatrix::kMSkewY); SkScalar ky = args.fViewMatrix->get(SkMatrix::kMSkewY);
static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDomain(); static const skgpu::UniqueKey::Domain kDomain = skgpu::UniqueKey::GenerateDomain();
GrUniqueKey::Builder builder(&maskKey, kDomain, 7 + args.fShape->unstyledKeySize(), skgpu::UniqueKey::Builder builder(&maskKey, kDomain, 7 + args.fShape->unstyledKeySize(),
"SW Path Mask"); "SW Path Mask");
builder[0] = boundsForMask->width(); builder[0] = boundsForMask->width();
builder[1] = boundsForMask->height(); builder[1] = boundsForMask->height();

View File

@ -8,7 +8,6 @@
#include "src/gpu/ops/StrokeRectOp.h" #include "src/gpu/ops/StrokeRectOp.h"
#include "include/core/SkStrokeRec.h" #include "include/core/SkStrokeRec.h"
#include "include/private/GrResourceKey.h"
#include "include/utils/SkRandom.h" #include "include/utils/SkRandom.h"
#include "src/core/SkMatrixPriv.h" #include "src/core/SkMatrixPriv.h"
#include "src/gpu/BufferWriter.h" #include "src/gpu/BufferWriter.h"
@ -19,6 +18,7 @@
#include "src/gpu/GrOpFlushState.h" #include "src/gpu/GrOpFlushState.h"
#include "src/gpu/GrProgramInfo.h" #include "src/gpu/GrProgramInfo.h"
#include "src/gpu/GrResourceProvider.h" #include "src/gpu/GrResourceProvider.h"
#include "src/gpu/ResourceKey.h"
#include "src/gpu/geometry/GrQuad.h" #include "src/gpu/geometry/GrQuad.h"
#include "src/gpu/ops/FillRectOp.h" #include "src/gpu/ops/FillRectOp.h"
#include "src/gpu/ops/GrMeshDrawOp.h" #include "src/gpu/ops/GrMeshDrawOp.h"
@ -277,8 +277,8 @@ private:
// AA Stroking // AA Stroking
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////
GR_DECLARE_STATIC_UNIQUE_KEY(gMiterIndexBufferKey); SKGPU_DECLARE_STATIC_UNIQUE_KEY(gMiterIndexBufferKey);
GR_DECLARE_STATIC_UNIQUE_KEY(gBevelIndexBufferKey); SKGPU_DECLARE_STATIC_UNIQUE_KEY(gBevelIndexBufferKey);
bool stroke_dev_half_size_supported(SkVector devHalfStrokeSize) { bool stroke_dev_half_size_supported(SkVector devHalfStrokeSize) {
// Since the horizontal and vertical strokes share internal corners, the coverage value at that // Since the horizontal and vertical strokes share internal corners, the coverage value at that
@ -695,7 +695,7 @@ sk_sp<const GrGpuBuffer> AAStrokeRectOp::GetIndexBuffer(GrResourceProvider* reso
}; };
// clang-format on // clang-format on
static_assert(SK_ARRAY_COUNT(gMiterIndices) == kMiterIndexCnt); static_assert(SK_ARRAY_COUNT(gMiterIndices) == kMiterIndexCnt);
GR_DEFINE_STATIC_UNIQUE_KEY(gMiterIndexBufferKey); SKGPU_DEFINE_STATIC_UNIQUE_KEY(gMiterIndexBufferKey);
return resourceProvider->findOrCreatePatternedIndexBuffer( return resourceProvider->findOrCreatePatternedIndexBuffer(
gMiterIndices, kMiterIndexCnt, kNumMiterRectsInIndexBuffer, kMiterVertexCnt, gMiterIndices, kMiterIndexCnt, kNumMiterRectsInIndexBuffer, kMiterVertexCnt,
gMiterIndexBufferKey); gMiterIndexBufferKey);
@ -760,7 +760,7 @@ sk_sp<const GrGpuBuffer> AAStrokeRectOp::GetIndexBuffer(GrResourceProvider* reso
// clang-format on // clang-format on
static_assert(SK_ARRAY_COUNT(gBevelIndices) == kBevelIndexCnt); static_assert(SK_ARRAY_COUNT(gBevelIndices) == kBevelIndexCnt);
GR_DEFINE_STATIC_UNIQUE_KEY(gBevelIndexBufferKey); SKGPU_DEFINE_STATIC_UNIQUE_KEY(gBevelIndexBufferKey);
return resourceProvider->findOrCreatePatternedIndexBuffer( return resourceProvider->findOrCreatePatternedIndexBuffer(
gBevelIndices, kBevelIndexCnt, kNumBevelRectsInIndexBuffer, kBevelVertexCnt, gBevelIndices, kBevelIndexCnt, kNumBevelRectsInIndexBuffer, kBevelVertexCnt,
gBevelIndexBufferKey); gBevelIndexBufferKey);

View File

@ -83,13 +83,15 @@ bool is_newer_better(SkData* incumbent, SkData* challenger) {
// When the SkPathRef genID changes, invalidate a corresponding GrResource described by key. // When the SkPathRef genID changes, invalidate a corresponding GrResource described by key.
class UniqueKeyInvalidator : public SkIDChangeListener { class UniqueKeyInvalidator : public SkIDChangeListener {
public: public:
UniqueKeyInvalidator(const GrUniqueKey& key, uint32_t contextUniqueID) UniqueKeyInvalidator(const skgpu::UniqueKey& key, uint32_t contextUniqueID)
: fMsg(key, contextUniqueID, /* inThreadSafeCache */ true) {} : fMsg(key, contextUniqueID, /* inThreadSafeCache */ true) {}
private: private:
GrUniqueKeyInvalidatedMessage fMsg; skgpu::UniqueKeyInvalidatedMessage fMsg;
void changed() override { SkMessageBus<GrUniqueKeyInvalidatedMessage, uint32_t>::Post(fMsg); } void changed() override {
SkMessageBus<skgpu::UniqueKeyInvalidatedMessage, uint32_t>::Post(fMsg);
}
}; };
class StaticVertexAllocator : public GrEagerVertexAllocator { class StaticVertexAllocator : public GrEagerVertexAllocator {
@ -230,17 +232,17 @@ private:
return path; return path;
} }
static void CreateKey(GrUniqueKey* key, static void CreateKey(skgpu::UniqueKey* key,
const GrStyledShape& shape, const GrStyledShape& shape,
const SkIRect& devClipBounds) { const SkIRect& devClipBounds) {
static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDomain(); static const skgpu::UniqueKey::Domain kDomain = skgpu::UniqueKey::GenerateDomain();
bool inverseFill = shape.inverseFilled(); bool inverseFill = shape.inverseFilled();
static constexpr int kClipBoundsCnt = sizeof(devClipBounds) / sizeof(uint32_t); static constexpr int kClipBoundsCnt = sizeof(devClipBounds) / sizeof(uint32_t);
int shapeKeyDataCnt = shape.unstyledKeySize(); int shapeKeyDataCnt = shape.unstyledKeySize();
SkASSERT(shapeKeyDataCnt >= 0); SkASSERT(shapeKeyDataCnt >= 0);
GrUniqueKey::Builder builder(key, kDomain, shapeKeyDataCnt + kClipBoundsCnt, "Path"); skgpu::UniqueKey::Builder builder(key, kDomain, shapeKeyDataCnt + kClipBoundsCnt, "Path");
shape.writeUnstyledKey(&builder[0]); shape.writeUnstyledKey(&builder[0]);
// For inverse fills, the tessellation is dependent on clip bounds. // For inverse fills, the tessellation is dependent on clip bounds.
if (inverseFill) { if (inverseFill) {
@ -280,7 +282,7 @@ private:
GrResourceProvider* rp = target->resourceProvider(); GrResourceProvider* rp = target->resourceProvider();
auto threadSafeCache = target->threadSafeCache(); auto threadSafeCache = target->threadSafeCache();
GrUniqueKey key; skgpu::UniqueKey key;
CreateKey(&key, fShape, fDevClipBounds); CreateKey(&key, fShape, fDevClipBounds);
SkScalar tol = GrPathUtils::scaleToleranceToSrc(GrPathUtils::kDefaultTolerance, SkScalar tol = GrPathUtils::scaleToleranceToSrc(GrPathUtils::kDefaultTolerance,
@ -439,7 +441,7 @@ private:
auto threadSafeViewCache = rContext->priv().threadSafeCache(); auto threadSafeViewCache = rContext->priv().threadSafeCache();
GrUniqueKey key; skgpu::UniqueKey key;
CreateKey(&key, fShape, fDevClipBounds); CreateKey(&key, fShape, fDevClipBounds);
SkScalar tol = GrPathUtils::scaleToleranceToSrc(GrPathUtils::kDefaultTolerance, SkScalar tol = GrPathUtils::scaleToleranceToSrc(GrPathUtils::kDefaultTolerance,

View File

@ -219,20 +219,20 @@ void PathCurveTessellator::WriteFixedIndexBufferBaseIndex(VertexWriter vertexWri
#if SK_GPU_V1 #if SK_GPU_V1
GR_DECLARE_STATIC_UNIQUE_KEY(gFixedVertexBufferKey); SKGPU_DECLARE_STATIC_UNIQUE_KEY(gFixedVertexBufferKey);
GR_DECLARE_STATIC_UNIQUE_KEY(gFixedIndexBufferKey); SKGPU_DECLARE_STATIC_UNIQUE_KEY(gFixedIndexBufferKey);
void PathCurveTessellator::prepareFixedCountBuffers(GrMeshDrawTarget* target) { void PathCurveTessellator::prepareFixedCountBuffers(GrMeshDrawTarget* target) {
GrResourceProvider* rp = target->resourceProvider(); GrResourceProvider* rp = target->resourceProvider();
GR_DEFINE_STATIC_UNIQUE_KEY(gFixedVertexBufferKey); SKGPU_DEFINE_STATIC_UNIQUE_KEY(gFixedVertexBufferKey);
fFixedVertexBuffer = rp->findOrMakeStaticBuffer(GrGpuBufferType::kVertex, fFixedVertexBuffer = rp->findOrMakeStaticBuffer(GrGpuBufferType::kVertex,
FixedVertexBufferSize(kMaxFixedResolveLevel), FixedVertexBufferSize(kMaxFixedResolveLevel),
gFixedVertexBufferKey, gFixedVertexBufferKey,
WriteFixedVertexBuffer); WriteFixedVertexBuffer);
GR_DEFINE_STATIC_UNIQUE_KEY(gFixedIndexBufferKey); SKGPU_DEFINE_STATIC_UNIQUE_KEY(gFixedIndexBufferKey);
fFixedIndexBuffer = rp->findOrMakeStaticBuffer(GrGpuBufferType::kIndex, fFixedIndexBuffer = rp->findOrMakeStaticBuffer(GrGpuBufferType::kIndex,
FixedIndexBufferSize(kMaxFixedResolveLevel), FixedIndexBufferSize(kMaxFixedResolveLevel),

View File

@ -281,20 +281,20 @@ void PathWedgeTessellator::WriteFixedIndexBuffer(VertexWriter vertexWriter, size
#if SK_GPU_V1 #if SK_GPU_V1
GR_DECLARE_STATIC_UNIQUE_KEY(gFixedVertexBufferKey); SKGPU_DECLARE_STATIC_UNIQUE_KEY(gFixedVertexBufferKey);
GR_DECLARE_STATIC_UNIQUE_KEY(gFixedIndexBufferKey); SKGPU_DECLARE_STATIC_UNIQUE_KEY(gFixedIndexBufferKey);
void PathWedgeTessellator::prepareFixedCountBuffers(GrMeshDrawTarget* target) { void PathWedgeTessellator::prepareFixedCountBuffers(GrMeshDrawTarget* target) {
GrResourceProvider* rp = target->resourceProvider(); GrResourceProvider* rp = target->resourceProvider();
GR_DEFINE_STATIC_UNIQUE_KEY(gFixedVertexBufferKey); SKGPU_DEFINE_STATIC_UNIQUE_KEY(gFixedVertexBufferKey);
fFixedVertexBuffer = rp->findOrMakeStaticBuffer(GrGpuBufferType::kVertex, fFixedVertexBuffer = rp->findOrMakeStaticBuffer(GrGpuBufferType::kVertex,
FixedVertexBufferSize(kMaxFixedResolveLevel), FixedVertexBufferSize(kMaxFixedResolveLevel),
gFixedVertexBufferKey, gFixedVertexBufferKey,
WriteFixedVertexBuffer); WriteFixedVertexBuffer);
GR_DEFINE_STATIC_UNIQUE_KEY(gFixedIndexBufferKey); SKGPU_DEFINE_STATIC_UNIQUE_KEY(gFixedIndexBufferKey);
fFixedIndexBuffer = rp->findOrMakeStaticBuffer(GrGpuBufferType::kIndex, fFixedIndexBuffer = rp->findOrMakeStaticBuffer(GrGpuBufferType::kIndex,
FixedIndexBufferSize(kMaxFixedResolveLevel), FixedIndexBufferSize(kMaxFixedResolveLevel),

View File

@ -362,7 +362,7 @@ void StrokeFixedCountTessellator::InitializeVertexIDFallbackBuffer(VertexWriter
#if SK_GPU_V1 #if SK_GPU_V1
GR_DECLARE_STATIC_UNIQUE_KEY(gVertexIDFallbackBufferKey); SKGPU_DECLARE_STATIC_UNIQUE_KEY(gVertexIDFallbackBufferKey);
int StrokeFixedCountTessellator::prepare(GrMeshDrawTarget* target, int StrokeFixedCountTessellator::prepare(GrMeshDrawTarget* target,
const SkMatrix& shaderMatrix, const SkMatrix& shaderMatrix,
@ -387,7 +387,7 @@ int StrokeFixedCountTessellator::prepare(GrMeshDrawTarget* target,
constexpr static int kMaxVerticesInFallbackBuffer = 2048; constexpr static int kMaxVerticesInFallbackBuffer = 2048;
fFixedEdgeCount = std::min(fFixedEdgeCount, kMaxVerticesInFallbackBuffer/2); fFixedEdgeCount = std::min(fFixedEdgeCount, kMaxVerticesInFallbackBuffer/2);
GR_DEFINE_STATIC_UNIQUE_KEY(gVertexIDFallbackBufferKey); SKGPU_DEFINE_STATIC_UNIQUE_KEY(gVertexIDFallbackBufferKey);
fVertexBufferIfNoIDSupport = target->resourceProvider()->findOrMakeStaticBuffer( fVertexBufferIfNoIDSupport = target->resourceProvider()->findOrMakeStaticBuffer(
GrGpuBufferType::kVertex, GrGpuBufferType::kVertex,

View File

@ -742,12 +742,12 @@ ClipStack::ClipState ClipStack::RawElement::clipType() const {
ClipStack::Mask::Mask(const SaveRecord& current, const SkIRect& drawBounds) ClipStack::Mask::Mask(const SaveRecord& current, const SkIRect& drawBounds)
: fBounds(drawBounds) : fBounds(drawBounds)
, fGenID(current.genID()) { , fGenID(current.genID()) {
static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDomain(); static const UniqueKey::Domain kDomain = UniqueKey::GenerateDomain();
// The gen ID should not be invalid, empty, or wide open, since those do not require masks // The gen ID should not be invalid, empty, or wide open, since those do not require masks
SkASSERT(fGenID != kInvalidGenID && fGenID != kEmptyGenID && fGenID != kWideOpenGenID); SkASSERT(fGenID != kInvalidGenID && fGenID != kEmptyGenID && fGenID != kWideOpenGenID);
GrUniqueKey::Builder builder(&fKey, kDomain, 5, "clip_mask"); UniqueKey::Builder builder(&fKey, kDomain, 5, "clip_mask");
builder[0] = fGenID; builder[0] = fGenID;
builder[1] = drawBounds.fLeft; builder[1] = drawBounds.fLeft;
builder[2] = drawBounds.fRight; builder[2] = drawBounds.fRight;

View File

@ -11,10 +11,10 @@
#include "include/core/SkClipOp.h" #include "include/core/SkClipOp.h"
#include "include/core/SkMatrix.h" #include "include/core/SkMatrix.h"
#include "include/core/SkShader.h" #include "include/core/SkShader.h"
#include "include/private/GrResourceKey.h"
#include "src/core/SkTBlockList.h" #include "src/core/SkTBlockList.h"
#include "src/gpu/GrClip.h" #include "src/gpu/GrClip.h"
#include "src/gpu/GrSurfaceProxyView.h" #include "src/gpu/GrSurfaceProxyView.h"
#include "src/gpu/ResourceKey.h"
#include "src/gpu/geometry/GrShape.h" #include "src/gpu/geometry/GrShape.h"
class GrAppliedClip; class GrAppliedClip;
@ -80,8 +80,8 @@ public:
SkIRect getConservativeBounds() const override; SkIRect getConservativeBounds() const override;
#if GR_TEST_UTILS #if GR_TEST_UTILS
GrUniqueKey testingOnly_getLastSWMaskKey() const { UniqueKey testingOnly_getLastSWMaskKey() const {
return fMasks.empty() ? GrUniqueKey() : fMasks.back().key(); return fMasks.empty() ? UniqueKey() : fMasks.back().key();
} }
#endif #endif
@ -176,16 +176,16 @@ private:
SkASSERT(!fKey.isValid()); SkASSERT(!fKey.isValid());
} }
const GrUniqueKey& key() const { return fKey; } const UniqueKey& key() const { return fKey; }
const SkIRect& bounds() const { return fBounds; } const SkIRect& bounds() const { return fBounds; }
uint32_t genID() const { return fGenID; } uint32_t genID() const { return fGenID; }
bool appliesToDraw(const SaveRecord& current, const SkIRect& drawBounds) const; bool appliesToDraw(const SaveRecord& current, const SkIRect& drawBounds) const;
void invalidate(GrProxyProvider* proxyProvider); void invalidate(GrProxyProvider* proxyProvider);
SkDEBUGCODE(const SaveRecord* owner() const { return fOwner; }) SkDEBUGCODE(const SaveRecord* owner() const { return fOwner; })
private: private:
GrUniqueKey fKey; UniqueKey fKey;
// The gen ID of the save record and the query bounds uniquely define the set of elements // The gen ID of the save record and the query bounds uniquely define the set of elements
// that would go into a mask. If the save record adds new elements, its gen ID would change. // that would go into a mask. If the save record adds new elements, its gen ID would change.
// If the draw had different bounds it would select a different set of masked elements. // If the draw had different bounds it would select a different set of masked elements.

View File

@ -422,14 +422,14 @@ GrSurfaceProxyView SkImage_Base::FindOrMakeCachedMipmappedView(GrRecordingContex
} }
GrProxyProvider* proxyProvider = rContext->priv().proxyProvider(); GrProxyProvider* proxyProvider = rContext->priv().proxyProvider();
GrUniqueKey baseKey; skgpu::UniqueKey baseKey;
GrMakeKeyFromImageID(&baseKey, imageUniqueID, SkIRect::MakeSize(view.dimensions())); GrMakeKeyFromImageID(&baseKey, imageUniqueID, SkIRect::MakeSize(view.dimensions()));
SkASSERT(baseKey.isValid()); SkASSERT(baseKey.isValid());
GrUniqueKey mipmappedKey; skgpu::UniqueKey mipmappedKey;
static const GrUniqueKey::Domain kMipmappedDomain = GrUniqueKey::GenerateDomain(); static const skgpu::UniqueKey::Domain kMipmappedDomain = skgpu::UniqueKey::GenerateDomain();
{ // No extra values beyond the domain are required. Must name the var to please { // No extra values beyond the domain are required. Must name the var to please
// clang-tidy. // clang-tidy.
GrUniqueKey::Builder b(&mipmappedKey, baseKey, kMipmappedDomain, 0); skgpu::UniqueKey::Builder b(&mipmappedKey, baseKey, kMipmappedDomain, 0);
} }
SkASSERT(mipmappedKey.isValid()); SkASSERT(mipmappedKey.isValid());
if (sk_sp<GrTextureProxy> cachedMippedView = if (sk_sp<GrTextureProxy> cachedMippedView =

View File

@ -18,7 +18,6 @@
#if SK_SUPPORT_GPU #if SK_SUPPORT_GPU
#include "include/gpu/GrDirectContext.h" #include "include/gpu/GrDirectContext.h"
#include "include/gpu/GrRecordingContext.h" #include "include/gpu/GrRecordingContext.h"
#include "include/private/GrResourceKey.h"
#include "src/core/SkResourceCache.h" #include "src/core/SkResourceCache.h"
#include "src/core/SkYUVPlanesCache.h" #include "src/core/SkYUVPlanesCache.h"
#include "src/gpu/GrCaps.h" #include "src/gpu/GrCaps.h"
@ -29,6 +28,7 @@
#include "src/gpu/GrRecordingContextPriv.h" #include "src/gpu/GrRecordingContextPriv.h"
#include "src/gpu/GrSamplerState.h" #include "src/gpu/GrSamplerState.h"
#include "src/gpu/GrYUVATextureProxies.h" #include "src/gpu/GrYUVATextureProxies.h"
#include "src/gpu/ResourceKey.h"
#include "src/gpu/SkGr.h" #include "src/gpu/SkGr.h"
#include "src/gpu/SurfaceFillContext.h" #include "src/gpu/SurfaceFillContext.h"
#include "src/gpu/effects/GrYUVtoRGBEffect.h" #include "src/gpu/effects/GrYUVtoRGBEffect.h"
@ -426,7 +426,7 @@ GrSurfaceProxyView SkImage_Lazy::lockTextureProxyView(GrRecordingContext* rConte
enum { kLockTexturePathCount = kRGBA_LockTexturePath + 1 }; enum { kLockTexturePathCount = kRGBA_LockTexturePath + 1 };
GrUniqueKey key; skgpu::UniqueKey key;
if (texGenPolicy == GrImageTexGenPolicy::kDraw) { if (texGenPolicy == GrImageTexGenPolicy::kDraw) {
GrMakeKeyFromImageID(&key, this->uniqueID(), SkIRect::MakeSize(this->dimensions())); GrMakeKeyFromImageID(&key, this->uniqueID(), SkIRect::MakeSize(this->dimensions()));
} }

View File

@ -387,9 +387,9 @@ std::unique_ptr<GrFragmentProcessor> SkPictureShader::asFragmentProcessor(
info.imageInfo = info.imageInfo.makeColorType(kRGBA_8888_SkColorType); info.imageInfo = info.imageInfo.makeColorType(kRGBA_8888_SkColorType);
} }
static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDomain(); static const skgpu::UniqueKey::Domain kDomain = skgpu::UniqueKey::GenerateDomain();
GrUniqueKey key; skgpu::UniqueKey key;
GrUniqueKey::Builder builder(&key, kDomain, 10, "Picture Shader Image"); skgpu::UniqueKey::Builder builder(&key, kDomain, 10, "Picture Shader Image");
builder[0] = dstCS->toXYZD50Hash(); builder[0] = dstCS->toXYZD50Hash();
builder[1] = dstCS->transferFnHash(); builder[1] = dstCS->transferFnHash();
builder[2] = static_cast<uint32_t>(dstColorType); builder[2] = static_cast<uint32_t>(dstColorType);

View File

@ -21,7 +21,6 @@
#include "include/core/SkSurface.h" #include "include/core/SkSurface.h"
#include "include/core/SkTypes.h" #include "include/core/SkTypes.h"
#include "include/effects/SkGradientShader.h" #include "include/effects/SkGradientShader.h"
#include "include/private/GrResourceKey.h"
#include "include/private/SkTemplates.h" #include "include/private/SkTemplates.h"
#include "include/utils/SkRandom.h" #include "include/utils/SkRandom.h"
#include "src/core/SkClipStack.h" #include "src/core/SkClipStack.h"

View File

@ -2085,15 +2085,15 @@ DEF_GPUTEST_FOR_CONTEXTS(ClipStack_SWMask,
}; };
auto generateMask = [&](SkRect drawBounds) { auto generateMask = [&](SkRect drawBounds) {
GrUniqueKey priorKey = cs->testingOnly_getLastSWMaskKey(); skgpu::UniqueKey priorKey = cs->testingOnly_getLastSWMaskKey();
drawRect(drawBounds); drawRect(drawBounds);
GrUniqueKey newKey = cs->testingOnly_getLastSWMaskKey(); skgpu::UniqueKey newKey = cs->testingOnly_getLastSWMaskKey();
REPORTER_ASSERT(r, priorKey != newKey, "Did not generate a new SW mask key as expected"); REPORTER_ASSERT(r, priorKey != newKey, "Did not generate a new SW mask key as expected");
return newKey; return newKey;
}; };
auto verifyKeys = [&](const std::vector<GrUniqueKey>& expectedKeys, auto verifyKeys = [&](const std::vector<skgpu::UniqueKey>& expectedKeys,
const std::vector<GrUniqueKey>& releasedKeys) { const std::vector<skgpu::UniqueKey>& releasedKeys) {
context->flush(); context->flush();
GrProxyProvider* proxyProvider = context->priv().proxyProvider(); GrProxyProvider* proxyProvider = context->priv().proxyProvider();
@ -2122,20 +2122,20 @@ DEF_GPUTEST_FOR_CONTEXTS(ClipStack_SWMask,
// Creates a mask for a complex clip // Creates a mask for a complex clip
cs->save(); cs->save();
addMaskRequiringClip(5.f, 5.f, 20.f); addMaskRequiringClip(5.f, 5.f, 20.f);
GrUniqueKey keyADepth1 = generateMask({0.f, 0.f, 20.f, 20.f}); skgpu::UniqueKey keyADepth1 = generateMask({0.f, 0.f, 20.f, 20.f});
GrUniqueKey keyBDepth1 = generateMask({10.f, 10.f, 30.f, 30.f}); skgpu::UniqueKey keyBDepth1 = generateMask({10.f, 10.f, 30.f, 30.f});
verifyKeys({keyADepth1, keyBDepth1}, {}); verifyKeys({keyADepth1, keyBDepth1}, {});
// Creates a new mask for a new save record, but doesn't delete the old records // Creates a new mask for a new save record, but doesn't delete the old records
cs->save(); cs->save();
addMaskRequiringClip(6.f, 6.f, 15.f); addMaskRequiringClip(6.f, 6.f, 15.f);
GrUniqueKey keyADepth2 = generateMask({0.f, 0.f, 20.f, 20.f}); skgpu::UniqueKey keyADepth2 = generateMask({0.f, 0.f, 20.f, 20.f});
GrUniqueKey keyBDepth2 = generateMask({10.f, 10.f, 30.f, 30.f}); skgpu::UniqueKey keyBDepth2 = generateMask({10.f, 10.f, 30.f, 30.f});
verifyKeys({keyADepth1, keyBDepth1, keyADepth2, keyBDepth2}, {}); verifyKeys({keyADepth1, keyBDepth1, keyADepth2, keyBDepth2}, {});
// Release after modifying the current record (even if we don't draw anything) // Release after modifying the current record (even if we don't draw anything)
addMaskRequiringClip(4.f, 4.f, 15.f); addMaskRequiringClip(4.f, 4.f, 15.f);
GrUniqueKey keyCDepth2 = generateMask({4.f, 4.f, 16.f, 20.f}); skgpu::UniqueKey keyCDepth2 = generateMask({4.f, 4.f, 16.f, 20.f});
verifyKeys({keyADepth1, keyBDepth1, keyCDepth2}, {keyADepth2, keyBDepth2}); verifyKeys({keyADepth1, keyBDepth1, keyCDepth2}, {keyADepth2, keyBDepth2});
// Release after restoring an older record // Release after restoring an older record

View File

@ -12,7 +12,6 @@
#include <vector> #include <vector>
#include "include/core/SkBitmap.h" #include "include/core/SkBitmap.h"
#include "include/gpu/GrDirectContext.h" #include "include/gpu/GrDirectContext.h"
#include "include/private/GrResourceKey.h"
#include "src/gpu/GrCaps.h" #include "src/gpu/GrCaps.h"
#include "src/gpu/GrDirectContextPriv.h" #include "src/gpu/GrDirectContextPriv.h"
#include "src/gpu/GrGeometryProcessor.h" #include "src/gpu/GrGeometryProcessor.h"
@ -23,6 +22,7 @@
#include "src/gpu/GrProgramInfo.h" #include "src/gpu/GrProgramInfo.h"
#include "src/gpu/GrResourceProvider.h" #include "src/gpu/GrResourceProvider.h"
#include "src/gpu/KeyBuilder.h" #include "src/gpu/KeyBuilder.h"
#include "src/gpu/ResourceKey.h"
#include "src/gpu/glsl/GrGLSLFragmentShaderBuilder.h" #include "src/gpu/glsl/GrGLSLFragmentShaderBuilder.h"
#include "src/gpu/glsl/GrGLSLVarying.h" #include "src/gpu/glsl/GrGLSLVarying.h"
#include "src/gpu/glsl/GrGLSLVertexGeoBuilder.h" #include "src/gpu/glsl/GrGLSLVertexGeoBuilder.h"
@ -34,7 +34,7 @@
#define WRITE_PNG_CONTEXT_TYPE kANGLE_D3D11_ES3_ContextType #define WRITE_PNG_CONTEXT_TYPE kANGLE_D3D11_ES3_ContextType
#endif #endif
GR_DECLARE_STATIC_UNIQUE_KEY(gIndexBufferKey); SKGPU_DECLARE_STATIC_UNIQUE_KEY(gIndexBufferKey);
static constexpr int kBoxSize = 2; static constexpr int kBoxSize = 2;
static constexpr int kBoxCountY = 8; static constexpr int kBoxCountY = 8;
@ -545,7 +545,7 @@ sk_sp<const GrBuffer> DrawMeshHelper::makeVertexBuffer(const T* data, int count)
} }
sk_sp<const GrBuffer> DrawMeshHelper::getIndexBuffer() { sk_sp<const GrBuffer> DrawMeshHelper::getIndexBuffer() {
GR_DEFINE_STATIC_UNIQUE_KEY(gIndexBufferKey); SKGPU_DEFINE_STATIC_UNIQUE_KEY(gIndexBufferKey);
return fState->resourceProvider()->findOrCreatePatternedIndexBuffer( return fState->resourceProvider()->findOrCreatePatternedIndexBuffer(
kIndexPattern, 6, kIndexPatternRepeatCount, 4, gIndexBufferKey); kIndexPattern, 6, kIndexPatternRepeatCount, 4, gIndexBufferKey);
} }

View File

@ -53,9 +53,9 @@ static std::unique_ptr<skgpu::v1::SurfaceDrawContext> new_SDC(GrRecordingContext
SkBudgeted::kYes); SkBudgeted::kYes);
} }
static void create_view_key(GrUniqueKey* key, int wh, int id) { static void create_view_key(skgpu::UniqueKey* key, int wh, int id) {
static const GrUniqueKey::Domain kViewDomain = GrUniqueKey::GenerateDomain(); static const skgpu::UniqueKey::Domain kViewDomain = skgpu::UniqueKey::GenerateDomain();
GrUniqueKey::Builder builder(key, kViewDomain, 1); skgpu::UniqueKey::Builder builder(key, kViewDomain, 1);
builder[0] = wh; builder[0] = wh;
builder.finish(); builder.finish();
@ -64,9 +64,9 @@ static void create_view_key(GrUniqueKey* key, int wh, int id) {
} }
} }
static void create_vert_key(GrUniqueKey* key, int wh, int id) { static void create_vert_key(skgpu::UniqueKey* key, int wh, int id) {
static const GrUniqueKey::Domain kVertDomain = GrUniqueKey::GenerateDomain(); static const skgpu::UniqueKey::Domain kVertDomain = skgpu::UniqueKey::GenerateDomain();
GrUniqueKey::Builder builder(key, kVertDomain, 1); skgpu::UniqueKey::Builder builder(key, kVertDomain, 1);
builder[0] = wh; builder[0] = wh;
builder.finish(); builder.finish();
@ -215,7 +215,7 @@ public:
return false; return false;
} }
GrUniqueKey key; skgpu::UniqueKey key;
create_view_key(&key, wh, kNoID); create_view_key(&key, wh, kNoID);
auto threadSafeCache = this->threadSafeCache(); auto threadSafeCache = this->threadSafeCache();
@ -301,7 +301,7 @@ public:
return false; return false;
} }
GrUniqueKey key; skgpu::UniqueKey key;
create_vert_key(&key, wh, kNoID); create_vert_key(&key, wh, kNoID);
auto threadSafeCache = this->threadSafeCache(); auto threadSafeCache = this->threadSafeCache();
@ -500,7 +500,7 @@ private:
++fStats->fNumLazyCreations; ++fStats->fNumLazyCreations;
} }
GrUniqueKey key; skgpu::UniqueKey key;
create_vert_key(&key, fWH, fID); create_vert_key(&key, fWH, fID);
// We can "fail the lookup" to simulate a threaded race condition // We can "fail the lookup" to simulate a threaded race condition
@ -673,7 +673,7 @@ GrSurfaceProxyView TestHelper::AccessCachedView(GrRecordingContext* rContext,
int wh, int wh,
bool failLookup, bool failFillingIn, int id, bool failLookup, bool failFillingIn, int id,
Stats* stats) { Stats* stats) {
GrUniqueKey key; skgpu::UniqueKey key;
create_view_key(&key, wh, id); create_view_key(&key, wh, id);
if (GrDirectContext* dContext = rContext->asDirectContext()) { if (GrDirectContext* dContext = rContext->asDirectContext()) {
@ -1422,7 +1422,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrThreadSafeCache14, reporter, ctxInfo) {
static void test_15(GrDirectContext* dContext, skiatest::Reporter* reporter, static void test_15(GrDirectContext* dContext, skiatest::Reporter* reporter,
TestHelper::addAccessFP addAccess, TestHelper::addAccessFP addAccess,
TestHelper::checkFP check, TestHelper::checkFP check,
void (*create_key)(GrUniqueKey*, int wh, int id)) { void (*create_key)(skgpu::UniqueKey*, int wh, int id)) {
TestHelper helper(dContext); TestHelper helper(dContext);
@ -1433,13 +1433,13 @@ static void test_15(GrDirectContext* dContext, skiatest::Reporter* reporter,
REPORTER_ASSERT(reporter, helper.numCacheEntries() == 1); REPORTER_ASSERT(reporter, helper.numCacheEntries() == 1);
GrUniqueKey key; skgpu::UniqueKey key;
(*create_key)(&key, kImageWH, kNoID); (*create_key)(&key, kImageWH, kNoID);
GrUniqueKeyInvalidatedMessage msg(key, dContext->priv().contextID(), skgpu::UniqueKeyInvalidatedMessage msg(key, dContext->priv().contextID(),
/* inThreadSafeCache */ true); /* inThreadSafeCache */ true);
SkMessageBus<GrUniqueKeyInvalidatedMessage, uint32_t>::Post(msg); SkMessageBus<skgpu::UniqueKeyInvalidatedMessage, uint32_t>::Post(msg);
// This purge call is needed to process the invalidation messages // This purge call is needed to process the invalidation messages
dContext->purgeUnlockedResources(/* scratchResourcesOnly */ true); dContext->purgeUnlockedResources(/* scratchResourcesOnly */ true);
@ -1478,7 +1478,7 @@ static bool newer_is_always_better(SkData* /* incumbent */, SkData* /* challenge
}; };
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrThreadSafeCache16Verts, reporter, ctxInfo) { DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrThreadSafeCache16Verts, reporter, ctxInfo) {
GrUniqueKey key; skgpu::UniqueKey key;
create_vert_key(&key, kImageWH, kNoID); create_vert_key(&key, kImageWH, kNoID);
TestHelper helper(ctxInfo.directContext(), newer_is_always_better); TestHelper helper(ctxInfo.directContext(), newer_is_always_better);

View File

@ -36,7 +36,7 @@ struct ProxyParams {
kInstantiated kInstantiated
}; };
Kind fKind; Kind fKind;
GrUniqueKey fUniqueKey = GrUniqueKey(); skgpu::UniqueKey fUniqueKey = skgpu::UniqueKey();
// TODO: do we care about mipmapping // TODO: do we care about mipmapping
}; };

View File

@ -270,16 +270,16 @@ public:
fToDelete = std::move(resource); fToDelete = std::move(resource);
} }
static void ComputeScratchKey(SimulatedProperty property, GrScratchKey* key) { static void ComputeScratchKey(SimulatedProperty property, skgpu::ScratchKey* key) {
static GrScratchKey::ResourceType t = GrScratchKey::GenerateResourceType(); static skgpu::ScratchKey::ResourceType t = skgpu::ScratchKey::GenerateResourceType();
GrScratchKey::Builder builder(key, t, kScratchKeyFieldCnt); skgpu::ScratchKey::Builder builder(key, t, kScratchKeyFieldCnt);
for (int i = 0; i < kScratchKeyFieldCnt; ++i) { for (int i = 0; i < kScratchKeyFieldCnt; ++i) {
builder[i] = static_cast<uint32_t>(i + property); builder[i] = static_cast<uint32_t>(i + property);
} }
} }
static size_t ExpectedScratchKeySize() { static size_t ExpectedScratchKeySize() {
return sizeof(uint32_t) * (kScratchKeyFieldCnt + GrScratchKey::kMetaDataCnt); return sizeof(uint32_t) * (kScratchKeyFieldCnt + skgpu::ScratchKey::kMetaDataCnt);
} }
private: private:
static const int kScratchKeyFieldCnt = 6; static const int kScratchKeyFieldCnt = 6;
@ -306,7 +306,7 @@ private:
this->registerWithCacheWrapped(cacheable); this->registerWithCacheWrapped(cacheable);
} }
void computeScratchKey(GrScratchKey* key) const override { void computeScratchKey(skgpu::ScratchKey* key) const override {
if (fIsScratch) { if (fIsScratch) {
ComputeScratchKey(fProperty, key); ComputeScratchKey(fProperty, key);
} }
@ -394,9 +394,9 @@ static void test_no_key(skiatest::Reporter* reporter) {
// Each integer passed as a template param creates a new domain. // Each integer passed as a template param creates a new domain.
template <int> template <int>
static void make_unique_key(GrUniqueKey* key, int data, const char* tag = nullptr) { static void make_unique_key(skgpu::UniqueKey* key, int data, const char* tag = nullptr) {
static GrUniqueKey::Domain d = GrUniqueKey::GenerateDomain(); static skgpu::UniqueKey::Domain d = skgpu::UniqueKey::GenerateDomain();
GrUniqueKey::Builder builder(key, d, 1, tag); skgpu::UniqueKey::Builder builder(key, d, 1, tag);
builder[0] = data; builder[0] = data;
} }
@ -409,7 +409,7 @@ static void test_purge_unlocked(skiatest::Reporter* reporter) {
TestResource* a = TestResource::CreateScratch(gpu, SkBudgeted::kYes, TestResource* a = TestResource::CreateScratch(gpu, SkBudgeted::kYes,
TestResource::kA_SimulatedProperty, 11); TestResource::kA_SimulatedProperty, 11);
GrUniqueKey uniqueKey; skgpu::UniqueKey uniqueKey;
make_unique_key<0>(&uniqueKey, 0); make_unique_key<0>(&uniqueKey, 0);
TestResource* b = TestResource::CreateScratch(gpu, SkBudgeted::kYes, TestResource* b = TestResource::CreateScratch(gpu, SkBudgeted::kYes,
@ -419,7 +419,7 @@ static void test_purge_unlocked(skiatest::Reporter* reporter) {
TestResource* c = TestResource::CreateScratch(gpu, SkBudgeted::kYes, TestResource* c = TestResource::CreateScratch(gpu, SkBudgeted::kYes,
TestResource::kA_SimulatedProperty, 13); TestResource::kA_SimulatedProperty, 13);
GrUniqueKey uniqueKey2; skgpu::UniqueKey uniqueKey2;
make_unique_key<0>(&uniqueKey2, 1); make_unique_key<0>(&uniqueKey2, 1);
TestResource* d = TestResource::CreateScratch(gpu, SkBudgeted::kYes, TestResource* d = TestResource::CreateScratch(gpu, SkBudgeted::kYes,
@ -536,7 +536,7 @@ static void test_budgeting(skiatest::Reporter* reporter) {
GrResourceCache* cache = mock.cache(); GrResourceCache* cache = mock.cache();
GrGpu* gpu = mock.gpu(); GrGpu* gpu = mock.gpu();
GrUniqueKey uniqueKey; skgpu::UniqueKey uniqueKey;
make_unique_key<0>(&uniqueKey, 0); make_unique_key<0>(&uniqueKey, 0);
// Create a scratch, a unique, and a wrapped resource // Create a scratch, a unique, and a wrapped resource
@ -550,9 +550,9 @@ static void test_budgeting(skiatest::Reporter* reporter) {
TestResource* unbudgeted = new TestResource(gpu, SkBudgeted::kNo, 14); TestResource* unbudgeted = new TestResource(gpu, SkBudgeted::kNo, 14);
// Make sure we can add a unique key to the wrapped resources // Make sure we can add a unique key to the wrapped resources
GrUniqueKey uniqueKey2; skgpu::UniqueKey uniqueKey2;
make_unique_key<0>(&uniqueKey2, 1); make_unique_key<0>(&uniqueKey2, 1);
GrUniqueKey uniqueKey3; skgpu::UniqueKey uniqueKey3;
make_unique_key<0>(&uniqueKey3, 2); make_unique_key<0>(&uniqueKey3, 2);
wrappedCacheable->resourcePriv().setUniqueKey(uniqueKey2); wrappedCacheable->resourcePriv().setUniqueKey(uniqueKey2);
wrappedUncacheable->resourcePriv().setUniqueKey(uniqueKey3); wrappedUncacheable->resourcePriv().setUniqueKey(uniqueKey3);
@ -662,7 +662,7 @@ static void test_unbudgeted(skiatest::Reporter* reporter) {
GrResourceCache* cache = mock.cache(); GrResourceCache* cache = mock.cache();
GrGpu* gpu = mock.gpu(); GrGpu* gpu = mock.gpu();
GrUniqueKey uniqueKey; skgpu::UniqueKey uniqueKey;
make_unique_key<0>(&uniqueKey, 0); make_unique_key<0>(&uniqueKey, 0);
TestResource* scratch; TestResource* scratch;
@ -736,7 +736,7 @@ void test_unbudgeted_to_scratch(skiatest::Reporter* reporter);
TestResource* resource = TestResource* resource =
TestResource::CreateScratch(gpu, SkBudgeted::kNo, TestResource::kA_SimulatedProperty); TestResource::CreateScratch(gpu, SkBudgeted::kNo, TestResource::kA_SimulatedProperty);
GrScratchKey key; skgpu::ScratchKey key;
TestResource::ComputeScratchKey(TestResource::kA_SimulatedProperty, &key); TestResource::ComputeScratchKey(TestResource::kA_SimulatedProperty, &key);
size_t size = resource->gpuMemorySize(); size_t size = resource->gpuMemorySize();
@ -807,12 +807,12 @@ static void test_duplicate_scratch_key(skiatest::Reporter* reporter) {
TestResource* b = TestResource::CreateScratch(gpu, TestResource* b = TestResource::CreateScratch(gpu,
SkBudgeted::kYes, SkBudgeted::kYes,
TestResource::kB_SimulatedProperty, 12); TestResource::kB_SimulatedProperty, 12);
GrScratchKey scratchKey1; skgpu::ScratchKey scratchKey1;
TestResource::ComputeScratchKey(TestResource::kA_SimulatedProperty, &scratchKey1); TestResource::ComputeScratchKey(TestResource::kA_SimulatedProperty, &scratchKey1);
// Check for negative case consistency. (leaks upon test failure.) // Check for negative case consistency. (leaks upon test failure.)
REPORTER_ASSERT(reporter, !cache->findAndRefScratchResource(scratchKey1)); REPORTER_ASSERT(reporter, !cache->findAndRefScratchResource(scratchKey1));
GrScratchKey scratchKey; skgpu::ScratchKey scratchKey;
TestResource::ComputeScratchKey(TestResource::kB_SimulatedProperty, &scratchKey); TestResource::ComputeScratchKey(TestResource::kB_SimulatedProperty, &scratchKey);
// Scratch resources are registered with GrResourceCache just by existing. There are 2. // Scratch resources are registered with GrResourceCache just by existing. There are 2.
@ -855,7 +855,7 @@ static void test_remove_scratch_key(skiatest::Reporter* reporter) {
a->unref(); a->unref();
b->unref(); b->unref();
GrScratchKey scratchKey; skgpu::ScratchKey scratchKey;
// Ensure that scratch key lookup is correct for negative case. // Ensure that scratch key lookup is correct for negative case.
TestResource::ComputeScratchKey(TestResource::kA_SimulatedProperty, &scratchKey); TestResource::ComputeScratchKey(TestResource::kA_SimulatedProperty, &scratchKey);
// (following leaks upon test failure). // (following leaks upon test failure).
@ -913,11 +913,11 @@ static void test_scratch_key_consistency(skiatest::Reporter* reporter) {
a->unref(); a->unref();
b->unref(); b->unref();
GrScratchKey scratchKey; skgpu::ScratchKey scratchKey;
// Ensure that scratch key comparison and assignment is consistent. // Ensure that scratch key comparison and assignment is consistent.
GrScratchKey scratchKey1; skgpu::ScratchKey scratchKey1;
TestResource::ComputeScratchKey(TestResource::kA_SimulatedProperty, &scratchKey1); TestResource::ComputeScratchKey(TestResource::kA_SimulatedProperty, &scratchKey1);
GrScratchKey scratchKey2; skgpu::ScratchKey scratchKey2;
TestResource::ComputeScratchKey(TestResource::kB_SimulatedProperty, &scratchKey2); TestResource::ComputeScratchKey(TestResource::kB_SimulatedProperty, &scratchKey2);
REPORTER_ASSERT(reporter, scratchKey1.size() == TestResource::ExpectedScratchKeySize()); REPORTER_ASSERT(reporter, scratchKey1.size() == TestResource::ExpectedScratchKeySize());
REPORTER_ASSERT(reporter, scratchKey1 != scratchKey2); REPORTER_ASSERT(reporter, scratchKey1 != scratchKey2);
@ -964,7 +964,7 @@ static void test_duplicate_unique_key(skiatest::Reporter* reporter) {
GrResourceCache* cache = mock.cache(); GrResourceCache* cache = mock.cache();
GrGpu* gpu = mock.gpu(); GrGpu* gpu = mock.gpu();
GrUniqueKey key; skgpu::UniqueKey key;
make_unique_key<0>(&key, 0); make_unique_key<0>(&key, 0);
// Create two resources that we will attempt to register with the same unique key. // Create two resources that we will attempt to register with the same unique key.
@ -1004,7 +1004,7 @@ static void test_duplicate_unique_key(skiatest::Reporter* reporter) {
// Also make b be unreffed when replacement occurs. // Also make b be unreffed when replacement occurs.
b->unref(); b->unref();
TestResource* c = new TestResource(gpu, SkBudgeted::kYes, 13); TestResource* c = new TestResource(gpu, SkBudgeted::kYes, 13);
GrUniqueKey differentKey; skgpu::UniqueKey differentKey;
make_unique_key<0>(&differentKey, 1); make_unique_key<0>(&differentKey, 1);
c->resourcePriv().setUniqueKey(differentKey); c->resourcePriv().setUniqueKey(differentKey);
REPORTER_ASSERT(reporter, 2 == cache->getResourceCount()); REPORTER_ASSERT(reporter, 2 == cache->getResourceCount());
@ -1037,7 +1037,7 @@ static void test_duplicate_unique_key(skiatest::Reporter* reporter) {
REPORTER_ASSERT(reporter, 0 == TestResource::NumAlive()); REPORTER_ASSERT(reporter, 0 == TestResource::NumAlive());
{ {
GrUniqueKey key2; skgpu::UniqueKey key2;
make_unique_key<0>(&key2, 0); make_unique_key<0>(&key2, 0);
sk_sp<TestResource> d(new TestResource(gpu)); sk_sp<TestResource> d(new TestResource(gpu));
int foo = 4132; int foo = 4132;
@ -1045,7 +1045,7 @@ static void test_duplicate_unique_key(skiatest::Reporter* reporter) {
d->resourcePriv().setUniqueKey(key2); d->resourcePriv().setUniqueKey(key2);
} }
GrUniqueKey key3; skgpu::UniqueKey key3;
make_unique_key<0>(&key3, 0); make_unique_key<0>(&key3, 0);
sk_sp<GrGpuResource> d2(cache->findAndRefUniqueResource(key3)); sk_sp<GrGpuResource> d2(cache->findAndRefUniqueResource(key3));
REPORTER_ASSERT(reporter, *(int*) d2->getUniqueKey().getCustomData()->data() == 4132); REPORTER_ASSERT(reporter, *(int*) d2->getUniqueKey().getCustomData()->data() == 4132);
@ -1057,7 +1057,7 @@ static void test_purge_invalidated(skiatest::Reporter* reporter) {
GrResourceCache* cache = mock.cache(); GrResourceCache* cache = mock.cache();
GrGpu* gpu = mock.gpu(); GrGpu* gpu = mock.gpu();
GrUniqueKey key1, key2, key3; skgpu::UniqueKey key1, key2, key3;
make_unique_key<0>(&key1, 1); make_unique_key<0>(&key1, 1);
make_unique_key<0>(&key2, 2); make_unique_key<0>(&key2, 2);
make_unique_key<0>(&key3, 3); make_unique_key<0>(&key3, 3);
@ -1079,8 +1079,8 @@ static void test_purge_invalidated(skiatest::Reporter* reporter) {
REPORTER_ASSERT(reporter, cache->hasUniqueKey(key3)); REPORTER_ASSERT(reporter, cache->hasUniqueKey(key3));
REPORTER_ASSERT(reporter, 3 == TestResource::NumAlive()); REPORTER_ASSERT(reporter, 3 == TestResource::NumAlive());
typedef GrUniqueKeyInvalidatedMessage Msg; typedef skgpu::UniqueKeyInvalidatedMessage Msg;
typedef SkMessageBus<GrUniqueKeyInvalidatedMessage, uint32_t> Bus; typedef SkMessageBus<Msg, uint32_t> Bus;
// Invalidate two of the three, they should be purged and no longer accessible via their keys. // Invalidate two of the three, they should be purged and no longer accessible via their keys.
Bus::Post(Msg(key1, dContext->priv().contextID())); Bus::Post(Msg(key1, dContext->priv().contextID()));
@ -1104,7 +1104,7 @@ static void test_purge_invalidated(skiatest::Reporter* reporter) {
REPORTER_ASSERT(reporter, 1 == TestResource::NumAlive()); REPORTER_ASSERT(reporter, 1 == TestResource::NumAlive());
// Make sure we actually get to c via it's scratch key, before we say goodbye. // Make sure we actually get to c via it's scratch key, before we say goodbye.
GrScratchKey scratchKey; skgpu::ScratchKey scratchKey;
TestResource::ComputeScratchKey(TestResource::kA_SimulatedProperty, &scratchKey); TestResource::ComputeScratchKey(TestResource::kA_SimulatedProperty, &scratchKey);
GrGpuResource* scratch = cache->findAndRefScratchResource(scratchKey); GrGpuResource* scratch = cache->findAndRefScratchResource(scratchKey);
REPORTER_ASSERT(reporter, scratch == c); REPORTER_ASSERT(reporter, scratch == c);
@ -1125,7 +1125,7 @@ static void test_cache_chained_purge(skiatest::Reporter* reporter) {
GrResourceCache* cache = mock.cache(); GrResourceCache* cache = mock.cache();
GrGpu* gpu = mock.gpu(); GrGpu* gpu = mock.gpu();
GrUniqueKey key1, key2; skgpu::UniqueKey key1, key2;
make_unique_key<0>(&key1, 1); make_unique_key<0>(&key1, 1);
make_unique_key<0>(&key2, 2); make_unique_key<0>(&key2, 2);
@ -1182,7 +1182,7 @@ static void test_timestamp_wrap(skiatest::Reporter* reporter) {
// Add kCount resources, holding onto resources at random so we have a mix of purgeable and // Add kCount resources, holding onto resources at random so we have a mix of purgeable and
// unpurgeable resources. // unpurgeable resources.
for (int j = 0; j < kCount; ++j) { for (int j = 0; j < kCount; ++j) {
GrUniqueKey key; skgpu::UniqueKey key;
make_unique_key<0>(&key, j); make_unique_key<0>(&key, j);
TestResource* r = new TestResource(gpu); TestResource* r = new TestResource(gpu);
@ -1202,7 +1202,7 @@ static void test_timestamp_wrap(skiatest::Reporter* reporter) {
// Verify that the correct resources were purged. // Verify that the correct resources were purged.
int currShouldPurgeIdx = 0; int currShouldPurgeIdx = 0;
for (int j = 0; j < kCount; ++j) { for (int j = 0; j < kCount; ++j) {
GrUniqueKey key; skgpu::UniqueKey key;
make_unique_key<0>(&key, j); make_unique_key<0>(&key, j);
GrGpuResource* res = cache->findAndRefUniqueResource(key); GrGpuResource* res = cache->findAndRefUniqueResource(key);
if (currShouldPurgeIdx < shouldPurgeIdxs.count() && if (currShouldPurgeIdx < shouldPurgeIdxs.count() &&
@ -1245,7 +1245,7 @@ static void test_time_purge(skiatest::Reporter* reporter) {
// Insert resources and get time points between each addition. // Insert resources and get time points between each addition.
for (int i = 0; i < cnt; ++i) { for (int i = 0; i < cnt; ++i) {
TestResource* r = new TestResource(gpu); TestResource* r = new TestResource(gpu);
GrUniqueKey k; skgpu::UniqueKey k;
make_unique_key<1>(&k, i); make_unique_key<1>(&k, i);
r->resourcePriv().setUniqueKey(k); r->resourcePriv().setUniqueKey(k);
r->unref(); r->unref();
@ -1258,7 +1258,7 @@ static void test_time_purge(skiatest::Reporter* reporter) {
cache->purgeResourcesNotUsedSince(timeStamps[i]); cache->purgeResourcesNotUsedSince(timeStamps[i]);
REPORTER_ASSERT(reporter, cnt - i - 1 == cache->getResourceCount()); REPORTER_ASSERT(reporter, cnt - i - 1 == cache->getResourceCount());
for (int j = 0; j < i; ++j) { for (int j = 0; j < i; ++j) {
GrUniqueKey k; skgpu::UniqueKey k;
make_unique_key<1>(&k, j); make_unique_key<1>(&k, j);
GrGpuResource* r = cache->findAndRefUniqueResource(k); GrGpuResource* r = cache->findAndRefUniqueResource(k);
REPORTER_ASSERT(reporter, !SkToBool(r)); REPORTER_ASSERT(reporter, !SkToBool(r));
@ -1276,7 +1276,7 @@ static void test_time_purge(skiatest::Reporter* reporter) {
std::unique_ptr<GrGpuResource* []> refedResources(new GrGpuResource*[cnt / 2]); std::unique_ptr<GrGpuResource* []> refedResources(new GrGpuResource*[cnt / 2]);
for (int i = 0; i < cnt; ++i) { for (int i = 0; i < cnt; ++i) {
TestResource* r = new TestResource(gpu); TestResource* r = new TestResource(gpu);
GrUniqueKey k; skgpu::UniqueKey k;
make_unique_key<1>(&k, i); make_unique_key<1>(&k, i);
r->resourcePriv().setUniqueKey(k); r->resourcePriv().setUniqueKey(k);
// Leave a ref on every other resource, beginning with the first. // Leave a ref on every other resource, beginning with the first.
@ -1316,7 +1316,7 @@ static void test_time_purge(skiatest::Reporter* reporter) {
TestResource* r = isScratch ? TestResource::CreateScratch(gpu, budgeted, property) TestResource* r = isScratch ? TestResource::CreateScratch(gpu, budgeted, property)
: new TestResource(gpu, budgeted, property); : new TestResource(gpu, budgeted, property);
if (!isScratch) { if (!isScratch) {
GrUniqueKey k; skgpu::UniqueKey k;
make_unique_key<1>(&k, i); make_unique_key<1>(&k, i);
r->resourcePriv().setUniqueKey(k); r->resourcePriv().setUniqueKey(k);
} }
@ -1341,7 +1341,7 @@ static void test_time_purge(skiatest::Reporter* reporter) {
dContext->flushAndSubmit(); dContext->flushAndSubmit();
for (int i = 0; i < 10; ++i) { for (int i = 0; i < 10; ++i) {
TestResource* r = new TestResource(gpu); TestResource* r = new TestResource(gpu);
GrUniqueKey k; skgpu::UniqueKey k;
make_unique_key<1>(&k, i); make_unique_key<1>(&k, i);
r->resourcePriv().setUniqueKey(k); r->resourcePriv().setUniqueKey(k);
r->unref(); r->unref();
@ -1372,7 +1372,7 @@ static void test_partial_purge(skiatest::Reporter* reporter) {
for (int testCase = 0; testCase < kEndTests_TestCase; testCase++) { for (int testCase = 0; testCase < kEndTests_TestCase; testCase++) {
GrUniqueKey key1, key2, key3; skgpu::UniqueKey key1, key2, key3;
make_unique_key<0>(&key1, 1); make_unique_key<0>(&key1, 1);
make_unique_key<0>(&key2, 2); make_unique_key<0>(&key2, 2);
make_unique_key<0>(&key3, 3); make_unique_key<0>(&key3, 3);
@ -1459,7 +1459,7 @@ static void test_partial_purge(skiatest::Reporter* reporter) {
} }
static void test_custom_data(skiatest::Reporter* reporter) { static void test_custom_data(skiatest::Reporter* reporter) {
GrUniqueKey key1, key2; skgpu::UniqueKey key1, key2;
make_unique_key<0>(&key1, 1); make_unique_key<0>(&key1, 1);
make_unique_key<0>(&key2, 2); make_unique_key<0>(&key2, 2);
int foo = 4132; int foo = 4132;
@ -1468,7 +1468,7 @@ static void test_custom_data(skiatest::Reporter* reporter) {
REPORTER_ASSERT(reporter, key2.getCustomData() == nullptr); REPORTER_ASSERT(reporter, key2.getCustomData() == nullptr);
// Test that copying a key also takes a ref on its custom data. // Test that copying a key also takes a ref on its custom data.
GrUniqueKey key3 = key1; skgpu::UniqueKey key3 = key1;
REPORTER_ASSERT(reporter, *(int*) key3.getCustomData()->data() == 4132); REPORTER_ASSERT(reporter, *(int*) key3.getCustomData()->data() == 4132);
} }
@ -1495,7 +1495,7 @@ static void test_abandoned(skiatest::Reporter* reporter) {
resource->resourcePriv().makeBudgeted(); resource->resourcePriv().makeBudgeted();
resource->resourcePriv().makeUnbudgeted(); resource->resourcePriv().makeUnbudgeted();
resource->resourcePriv().removeScratchKey(); resource->resourcePriv().removeScratchKey();
GrUniqueKey key; skgpu::UniqueKey key;
make_unique_key<0>(&key, 1); make_unique_key<0>(&key, 1);
resource->resourcePriv().setUniqueKey(key); resource->resourcePriv().setUniqueKey(key);
resource->resourcePriv().removeUniqueKey(); resource->resourcePriv().removeUniqueKey();
@ -1521,7 +1521,7 @@ static void test_tags(skiatest::Reporter* reporter) {
for (int i = 0; i < kNumResources; ++i, ++currTagCnt) { for (int i = 0; i < kNumResources; ++i, ++currTagCnt) {
sk_sp<GrGpuResource> resource(new TestResource(gpu)); sk_sp<GrGpuResource> resource(new TestResource(gpu));
GrUniqueKey key; skgpu::UniqueKey key;
if (currTagCnt == tagIdx) { if (currTagCnt == tagIdx) {
tagIdx += 1; tagIdx += 1;
currTagCnt = 0; currTagCnt = 0;

View File

@ -80,12 +80,12 @@ static sk_sp<GrTextureProxy> wrapped(skiatest::Reporter* reporter, GrRecordingCo
static sk_sp<GrTextureProxy> wrapped_with_key(skiatest::Reporter* reporter, GrRecordingContext*, static sk_sp<GrTextureProxy> wrapped_with_key(skiatest::Reporter* reporter, GrRecordingContext*,
GrProxyProvider* proxyProvider, SkBackingFit fit) { GrProxyProvider* proxyProvider, SkBackingFit fit) {
static GrUniqueKey::Domain d = GrUniqueKey::GenerateDomain(); static skgpu::UniqueKey::Domain d = skgpu::UniqueKey::GenerateDomain();
static int kUniqueKeyData = 0; static int kUniqueKeyData = 0;
GrUniqueKey key; skgpu::UniqueKey key;
GrUniqueKey::Builder builder(&key, d, 1, nullptr); skgpu::UniqueKey::Builder builder(&key, d, 1, nullptr);
builder[0] = kUniqueKeyData++; builder[0] = kUniqueKeyData++;
builder.finish(); builder.finish();
@ -131,7 +131,7 @@ static void basic_test(GrDirectContext* dContext,
int startCacheCount = cache->getResourceCount(); int startCacheCount = cache->getResourceCount();
GrUniqueKey key; skgpu::UniqueKey key;
if (proxy->getUniqueKey().isValid()) { if (proxy->getUniqueKey().isValid()) {
key = proxy->getUniqueKey(); key = proxy->getUniqueKey();
} else { } else {
@ -157,7 +157,7 @@ static void basic_test(GrDirectContext* dContext,
// Once instantiated, the backing resource should have the same key // Once instantiated, the backing resource should have the same key
SkAssertResult(proxy->instantiate(resourceProvider)); SkAssertResult(proxy->instantiate(resourceProvider));
const GrUniqueKey texKey = proxy->peekSurface()->getUniqueKey(); const skgpu::UniqueKey texKey = proxy->peekSurface()->getUniqueKey();
REPORTER_ASSERT(reporter, texKey.isValid()); REPORTER_ASSERT(reporter, texKey.isValid());
REPORTER_ASSERT(reporter, key == texKey); REPORTER_ASSERT(reporter, key == texKey);
@ -202,8 +202,8 @@ static void basic_test(GrDirectContext* dContext,
if (expectResourceToOutliveProxy) { if (expectResourceToOutliveProxy) {
proxy.reset(); proxy.reset();
GrUniqueKeyInvalidatedMessage msg(texKey, dContext->priv().contextID()); skgpu::UniqueKeyInvalidatedMessage msg(texKey, dContext->priv().contextID());
SkMessageBus<GrUniqueKeyInvalidatedMessage, uint32_t>::Post(msg); SkMessageBus<skgpu::UniqueKeyInvalidatedMessage, uint32_t>::Post(msg);
cache->purgeAsNeeded(); cache->purgeAsNeeded();
expectedCacheCount -= cacheEntriesPerProxy; expectedCacheCount -= cacheEntriesPerProxy;
proxy = proxyProvider->findOrCreateProxyByUniqueKey(key); proxy = proxyProvider->findOrCreateProxyByUniqueKey(key);
@ -291,9 +291,9 @@ static void invalidation_and_instantiation_test(GrDirectContext* dContext,
GrResourceCache* cache = dContext->priv().getResourceCache(); GrResourceCache* cache = dContext->priv().getResourceCache();
REPORTER_ASSERT(reporter, 0 == cache->getResourceCount()); REPORTER_ASSERT(reporter, 0 == cache->getResourceCount());
static GrUniqueKey::Domain d = GrUniqueKey::GenerateDomain(); static skgpu::UniqueKey::Domain d = skgpu::UniqueKey::GenerateDomain();
GrUniqueKey key; skgpu::UniqueKey key;
GrUniqueKey::Builder builder(&key, d, 1, nullptr); skgpu::UniqueKey::Builder builder(&key, d, 1, nullptr);
builder[0] = 0; builder[0] = 0;
builder.finish(); builder.finish();
@ -303,8 +303,8 @@ static void invalidation_and_instantiation_test(GrDirectContext* dContext,
SkAssertResult(proxyProvider->assignUniqueKeyToProxy(key, proxy.get())); SkAssertResult(proxyProvider->assignUniqueKeyToProxy(key, proxy.get()));
// Send an invalidation message, which will be sitting in the cache's inbox // Send an invalidation message, which will be sitting in the cache's inbox
SkMessageBus<GrUniqueKeyInvalidatedMessage, uint32_t>::Post( SkMessageBus<skgpu::UniqueKeyInvalidatedMessage, uint32_t>::Post(
GrUniqueKeyInvalidatedMessage(key, dContext->priv().contextID())); skgpu::UniqueKeyInvalidatedMessage(key, dContext->priv().contextID()));
REPORTER_ASSERT(reporter, 1 == proxyProvider->numUniqueKeyProxies_TestOnly()); REPORTER_ASSERT(reporter, 1 == proxyProvider->numUniqueKeyProxies_TestOnly());
REPORTER_ASSERT(reporter, 0 == cache->getResourceCount()); REPORTER_ASSERT(reporter, 0 == cache->getResourceCount());