This replaces the texture creation/caching functions on GrContext with a GrTextureProvider interface. The goal is to pass this narrowly focused object in places that currently take a GrContext but don't need and shouldn't use its other methods. It also has an extended private interface for interacting with non-texture resource types.

Review URL: https://codereview.chromium.org/1107973004
This commit is contained in:
bsalomon 2015-04-30 14:18:54 -07:00 committed by Commit bot
parent 3ffa126066
commit d309e7aa0e
44 changed files with 509 additions and 369 deletions

View File

@ -84,7 +84,8 @@ protected:
desc.fConfig = kSkia8888_GrPixelConfig; desc.fConfig = kSkia8888_GrPixelConfig;
desc.fWidth = 2 * S; desc.fWidth = 2 * S;
desc.fHeight = 2 * S; desc.fHeight = 2 * S;
GrTexture* texture = ctx->createTexture(desc, false, gTextureData.get(), 0); GrTexture* texture = ctx->textureProvider()->createTexture(
desc, false, gTextureData.get(), 0);
if (!texture) { if (!texture) {
return; return;

View File

@ -33,6 +33,7 @@
'<(skia_include_path)/gpu/GrSurface.h', '<(skia_include_path)/gpu/GrSurface.h',
'<(skia_include_path)/gpu/GrShaderVar.h', '<(skia_include_path)/gpu/GrShaderVar.h',
'<(skia_include_path)/gpu/GrTexture.h', '<(skia_include_path)/gpu/GrTexture.h',
'<(skia_include_path)/gpu/GrTextureProvider.h',
'<(skia_include_path)/gpu/GrTextureAccess.h', '<(skia_include_path)/gpu/GrTextureAccess.h',
'<(skia_include_path)/gpu/GrTestUtils.h', '<(skia_include_path)/gpu/GrTestUtils.h',
'<(skia_include_path)/gpu/GrTypes.h', '<(skia_include_path)/gpu/GrTypes.h',
@ -197,6 +198,7 @@
'<(skia_src_path)/gpu/GrTextContext.cpp', '<(skia_src_path)/gpu/GrTextContext.cpp',
'<(skia_src_path)/gpu/GrTextContext.h', '<(skia_src_path)/gpu/GrTextContext.h',
'<(skia_src_path)/gpu/GrTexture.cpp', '<(skia_src_path)/gpu/GrTexture.cpp',
'<(skia_src_path)/gpu/GrTextureProvider.cpp',
'<(skia_src_path)/gpu/GrTexturePriv.h', '<(skia_src_path)/gpu/GrTexturePriv.h',
'<(skia_src_path)/gpu/GrTextureAccess.cpp', '<(skia_src_path)/gpu/GrTextureAccess.cpp',
'<(skia_src_path)/gpu/GrTRecorder.h', '<(skia_src_path)/gpu/GrTRecorder.h',

View File

@ -13,7 +13,7 @@
#include "GrPaint.h" #include "GrPaint.h"
#include "GrPathRendererChain.h" #include "GrPathRendererChain.h"
#include "GrRenderTarget.h" #include "GrRenderTarget.h"
#include "GrTexture.h" #include "GrTextureProvider.h"
#include "SkMatrix.h" #include "SkMatrix.h"
#include "SkPathEffect.h" #include "SkPathEffect.h"
#include "SkTypes.h" #include "SkTypes.h"
@ -33,6 +33,7 @@ class GrPathRenderer;
class GrPipelineBuilder; class GrPipelineBuilder;
class GrResourceEntry; class GrResourceEntry;
class GrResourceCache; class GrResourceCache;
class GrResourceProvider;
class GrTestTarget; class GrTestTarget;
class GrTextBlobCache; class GrTextBlobCache;
class GrTextContext; class GrTextContext;
@ -111,7 +112,6 @@ public:
* GrGpuResources it created is to destroy them. * GrGpuResources it created is to destroy them.
*/ */
void abandonContext(); void abandonContext();
void contextDestroyed() { this->abandonContext(); } // legacy alias
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
// Resource Cache // Resource Cache
@ -147,21 +147,15 @@ public:
*/ */
void setResourceCacheLimits(int maxResources, size_t maxResourceBytes); void setResourceCacheLimits(int maxResources, size_t maxResourceBytes);
GrTextureProvider* textureProvider() { return fTextureProvider; }
const GrTextureProvider* textureProvider() const { return fTextureProvider; }
/** /**
* Frees GPU created by the context. Can be called to reduce GPU memory * Frees GPU created by the context. Can be called to reduce GPU memory
* pressure. * pressure.
*/ */
void freeGpuResources(); void freeGpuResources();
/**
* This method should be called whenever a GrResource is unreffed or
* switched from exclusive to non-exclusive. This
* gives the resource cache a chance to discard unneeded resources.
* Note: this entry point will be removed once totally ref-driven
* cache maintenance is implemented.
*/
void purgeCache();
/** /**
* Purge all the unlocked resources from the cache. * Purge all the unlocked resources from the cache.
* This entry point is mainly meant for timing texture uploads * This entry point is mainly meant for timing texture uploads
@ -169,106 +163,8 @@ public:
*/ */
void purgeAllUnlockedResources(); void purgeAllUnlockedResources();
/** //////////////////////////////////////////////////////////////////////////
* Sets a unique key on the resource. Upon key collision this resource takes the place of the /// Texture and Render Target Queries
* previous resource that had the key.
*/
void addResourceToCache(const GrUniqueKey&, GrGpuResource*);
/**
* Finds a resource in the cache, based on the specified key. This is intended for use in
* conjunction with addResourceToCache(). The return value will be NULL if not found. The
* caller must balance with a call to unref().
*/
GrGpuResource* findAndRefCachedResource(const GrUniqueKey&);
/** Helper for casting resource to a texture. Caller must be sure that the resource cached
with the key is either NULL or a texture and not another resource type. */
GrTexture* findAndRefCachedTexture(const GrUniqueKey& key) {
GrGpuResource* resource = this->findAndRefCachedResource(key);
if (resource) {
GrTexture* texture = static_cast<GrSurface*>(resource)->asTexture();
SkASSERT(texture);
return texture;
}
return NULL;
}
/**
* Determines whether a resource is in the cache. If the resource is found it
* will not be locked or returned. This call does not affect the priority of
* the resource for deletion.
*/
bool isResourceInCache(const GrUniqueKey& key) const;
///////////////////////////////////////////////////////////////////////////
// Textures
/**
* Creates a new texture in the resource cache and returns it. The caller owns a
* ref on the returned texture which must be balanced by a call to unref.
*
* @param desc Description of the texture properties.
* @param budgeted Does the texture count against the resource cache budget?
* @param srcData Pointer to the pixel values (optional).
* @param rowBytes The number of bytes between rows of the texture. Zero
* implies tightly packed rows. For compressed pixel configs, this
* field is ignored.
*/
GrTexture* createTexture(const GrSurfaceDesc& desc, bool budgeted, const void* srcData,
size_t rowBytes);
GrTexture* createTexture(const GrSurfaceDesc& desc, bool budgeted) {
return this->createTexture(desc, budgeted, NULL, 0);
}
/**
* DEPRECATED: use createTexture().
*/
GrTexture* createUncachedTexture(const GrSurfaceDesc& desc, void* srcData, size_t rowBytes) {
return this->createTexture(desc, false, srcData, rowBytes);
}
/**
* Enum that determines how closely a returned scratch texture must match
* a provided GrSurfaceDesc. TODO: Remove this. createTexture() should be used
* for exact match and refScratchTexture() should be replaced with createApproxTexture().
*/
enum ScratchTexMatch {
/**
* Finds a texture that exactly matches the descriptor.
*/
kExact_ScratchTexMatch,
/**
* Finds a texture that approximately matches the descriptor. Will be
* at least as large in width and height as desc specifies. If desc
* specifies that texture is a render target then result will be a
* render target. If desc specifies a render target and doesn't set the
* no stencil flag then result will have a stencil. Format and aa level
* will always match.
*/
kApprox_ScratchTexMatch
};
/**
* Returns a texture matching the desc. It's contents are unknown. The caller
* owns a ref on the returned texture and must balance with a call to unref.
* It is guaranteed that the same texture will not be returned in subsequent
* calls until all refs to the texture are dropped.
*
* Textures created by createTexture() hide the complications of
* tiling non-power-of-two textures on APIs that don't support this (e.g.
* unextended GLES2). NPOT scratch textures are not tilable on such APIs.
*
* internalFlag is a temporary workaround until changes in the internal
* architecture are complete. Use the default value.
*
* TODO: Once internal flag can be removed, this should be replaced with
* createApproxTexture() and exact textures should be created with
* createTexture().
*/
GrTexture* refScratchTexture(const GrSurfaceDesc&, ScratchTexMatch match,
bool internalFlag = false);
/** /**
* Can the provided configuration act as a texture? * Can the provided configuration act as a texture?
@ -324,33 +220,6 @@ public:
*/ */
int getRecommendedSampleCount(GrPixelConfig config, SkScalar dpi) const; int getRecommendedSampleCount(GrPixelConfig config, SkScalar dpi) const;
///////////////////////////////////////////////////////////////////////////
// Backend Surfaces
/**
* Wraps an existing texture with a GrTexture object.
*
* OpenGL: if the object is a texture Gr may change its GL texture params
* when it is drawn.
*
* @param desc description of the object to create.
*
* @return GrTexture object or NULL on failure.
*/
GrTexture* wrapBackendTexture(const GrBackendTextureDesc& desc);
/**
* Wraps an existing render target with a GrRenderTarget object. It is
* similar to wrapBackendTexture but can be used to draw into surfaces
* that are not also textures (e.g. FBO 0 in OpenGL, or an MSAA buffer that
* the client will resolve to a texture).
*
* @param desc description of the object to create.
*
* @return GrTexture object or NULL on failure.
*/
GrRenderTarget* wrapBackendRenderTarget(const GrBackendRenderTargetDesc& desc);
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
// Draws // Draws
@ -645,6 +514,23 @@ public:
*/ */
void discardRenderTarget(GrRenderTarget*); void discardRenderTarget(GrRenderTarget*);
///////////////////////////////////////////////////////////////////////////
// Legacy functions, to be removed once Chromium stops using them.
enum ScratchTexMatch {
kExact_ScratchTexMatch = GrTextureProvider::kExact_ScratchTexMatch,
kApprox_ScratchTexMatch = GrTextureProvider::kApprox_ScratchTexMatch
};
GrTexture* refScratchTexture(const GrSurfaceDesc& desc, ScratchTexMatch match) {
return this->textureProvider()->refScratchTexture(
desc, (GrTextureProvider::ScratchTexMatch) match);
}
GrTexture* wrapBackendTexture(const GrBackendTextureDesc& desc) {
return this->textureProvider()->wrapBackendTexture(desc);
}
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
// Functions intended for internal use only. // Functions intended for internal use only.
GrGpu* getGpu() { return fGpu; } GrGpu* getGpu() { return fGpu; }
@ -655,6 +541,8 @@ public:
GrDrawTarget* getTextTarget(); GrDrawTarget* getTextTarget();
const GrIndexBuffer* getQuadIndexBuffer() const; const GrIndexBuffer* getQuadIndexBuffer() const;
GrAARectRenderer* getAARectRenderer() { return fAARectRenderer; } GrAARectRenderer* getAARectRenderer() { return fAARectRenderer; }
GrResourceProvider* resourceProvider() { return fResourceProvider; }
const GrResourceProvider* resourceProvider() const { return fResourceProvider; }
GrResourceCache* getResourceCache() { return fResourceCache; } GrResourceCache* getResourceCache() { return fResourceCache; }
// Called by tests that draw directly to the context via GrDrawTarget // Called by tests that draw directly to the context via GrDrawTarget
@ -689,8 +577,14 @@ public:
private: private:
GrGpu* fGpu; GrGpu* fGpu;
GrResourceCache* fResourceCache; GrResourceCache* fResourceCache;
// this union exists because the inheritance of GrTextureProvider->GrResourceProvider
// is in a private header.
union {
GrResourceProvider* fResourceProvider;
GrTextureProvider* fTextureProvider;
};
GrBatchFontCache* fBatchFontCache; GrBatchFontCache* fBatchFontCache;
SkAutoTDelete<GrLayerCache> fLayerCache; SkAutoTDelete<GrLayerCache> fLayerCache;
SkAutoTDelete<GrTextBlobCache> fTextBlobCache; SkAutoTDelete<GrTextBlobCache> fTextBlobCache;
@ -748,8 +642,6 @@ private:
const SkPath&, const SkPath&,
const GrStrokeInfo&); const GrStrokeInfo&);
GrTexture* internalRefScratchTexture(const GrSurfaceDesc&, uint32_t flags);
/** /**
* Creates a new text rendering context that is optimal for the * Creates a new text rendering context that is optimal for the
* render target and the context. Caller assumes the ownership * render target and the context. Caller assumes the ownership

View File

@ -0,0 +1,167 @@
/*
* Copyright 2015 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef GrTextureProvider_DEFINED
#define GrTextureProvider_DEFINED
#include "GrTexture.h"
class SK_API GrTextureProvider {
public:
///////////////////////////////////////////////////////////////////////////
// Textures
/**
* Creates a new texture in the resource cache and returns it. The caller owns a
* ref on the returned texture which must be balanced by a call to unref.
*
* @param desc Description of the texture properties.
* @param budgeted Does the texture count against the resource cache budget?
* @param srcData Pointer to the pixel values (optional).
* @param rowBytes The number of bytes between rows of the texture. Zero
* implies tightly packed rows. For compressed pixel configs, this
* field is ignored.
*/
GrTexture* createTexture(const GrSurfaceDesc& desc, bool budgeted, const void* srcData,
size_t rowBytes);
/** Shortcut for creating a texture with no initial data to upload. */
GrTexture* createTexture(const GrSurfaceDesc& desc, bool budgeted) {
return this->createTexture(desc, budgeted, NULL, 0);
}
/** Assigns a unique key to the texture. The texture will be findable via this key using
findTextureByUniqueKey(). If an existing texture has this key, it's key will be removed. */
void assignUniqueKeyToTexture(const GrUniqueKey& key, GrTexture* texture) {
this->assignUniqueKeyToResource(key, texture);
}
/** Finds a texture by unique key. If the texture is found it is ref'ed and returned. */
GrTexture* findAndRefTextureByUniqueKey(const GrUniqueKey& key) {
GrGpuResource* resource = this->findAndRefResourceByUniqueKey(key);
if (resource) {
GrTexture* texture = static_cast<GrSurface*>(resource)->asTexture();
SkASSERT(texture);
return texture;
}
return NULL;
}
/**
* Determines whether a texture is associated with the unique key. If the texture is found it
* will not be locked or returned. This call does not affect the priority of the resource for
* deletion.
*/
bool existsTextureWithUniqueKey(const GrUniqueKey& key) const {
return this->existsResourceWithUniqueKey(key);
}
/**
* Enum that determines how closely a returned scratch texture must match
* a provided GrSurfaceDesc. TODO: Remove this. createTexture() should be used
* for exact match and refScratchTexture() should be replaced with createApproxTexture().
*/
enum ScratchTexMatch {
/**
* Finds a texture that exactly matches the descriptor.
*/
kExact_ScratchTexMatch,
/**
* Finds a texture that approximately matches the descriptor. Will be
* at least as large in width and height as desc specifies. If desc
* specifies that texture is a render target then result will be a
* render target. If desc specifies a render target and doesn't set the
* no stencil flag then result will have a stencil. Format and aa level
* will always match.
*/
kApprox_ScratchTexMatch
};
/**
* Returns a texture matching the desc. It's contents are unknown. The caller
* owns a ref on the returned texture and must balance with a call to unref.
* It is guaranteed that the same texture will not be returned in subsequent
* calls until all refs to the texture are dropped.
*
* internalFlag is a temporary workaround until changes in the internal
* architecture are complete. Use the default value.
*
* TODO: Once internal flag can be removed, this should be replaced with
* createApproxTexture() and exact textures should be created with
* createTexture().
*/
GrTexture* refScratchTexture(const GrSurfaceDesc&, ScratchTexMatch match,
bool internalFlag = false);
///////////////////////////////////////////////////////////////////////////
// Wrapped Backend Surfaces
/**
* Wraps an existing texture with a GrTexture object.
*
* OpenGL: if the object is a texture Gr may change its GL texture params
* when it is drawn.
*
* @param desc description of the object to create.
*
* @return GrTexture object or NULL on failure.
*/
GrTexture* wrapBackendTexture(const GrBackendTextureDesc& desc);
/**
* Wraps an existing render target with a GrRenderTarget object. It is
* similar to wrapBackendTexture but can be used to draw into surfaces
* that are not also textures (e.g. FBO 0 in OpenGL, or an MSAA buffer that
* the client will resolve to a texture).
*
* @param desc description of the object to create.
*
* @return GrTexture object or NULL on failure.
*/
GrRenderTarget* wrapBackendRenderTarget(const GrBackendRenderTargetDesc& desc);
protected:
GrTextureProvider(GrGpu* gpu, GrResourceCache* cache) : fCache(cache), fGpu(gpu) {}
/**
* Assigns a unique key to a resource. If the key is associated with another resource that
* association is removed and replaced by this resource.
*/
void assignUniqueKeyToResource(const GrUniqueKey&, GrGpuResource*);
/**
* Finds a resource in the cache, based on the specified key. This is intended for use in
* conjunction with addResourceToCache(). The return value will be NULL if not found. The
* caller must balance with a call to unref().
*/
GrGpuResource* findAndRefResourceByUniqueKey(const GrUniqueKey&);
/**
* Determines whether a resource is in the cache. If the resource is found it
* will not be locked or returned. This call does not affect the priority of
* the resource for deletion.
*/
bool existsResourceWithUniqueKey(const GrUniqueKey& key) const;
GrTexture* internalRefScratchTexture(const GrSurfaceDesc&, uint32_t flags);
void abandon() {
fCache = NULL;
fGpu = NULL;
}
private:
bool isAbandoned() const {
SkASSERT(SkToBool(fGpu) == SkToBool(fCache));
return !SkToBool(fCache);
}
GrResourceCache* fCache;
GrGpu* fGpu;
};
#endif

View File

@ -257,8 +257,8 @@ bool SkImageFilter::filterImageGPU(Proxy* proxy, const SkBitmap& src, const Cont
desc.fHeight = bounds.height(); desc.fHeight = bounds.height();
desc.fConfig = kRGBA_8888_GrPixelConfig; desc.fConfig = kRGBA_8888_GrPixelConfig;
SkAutoTUnref<GrTexture> dst( SkAutoTUnref<GrTexture> dst(context->textureProvider()->refScratchTexture(
context->refScratchTexture(desc, GrContext::kApprox_ScratchTexMatch)); desc, GrTextureProvider::kApprox_ScratchTexMatch));
if (!dst) { if (!dst) {
return false; return false;
} }

View File

@ -278,8 +278,8 @@ bool SkAlphaThresholdFilterImpl::asFragmentProcessor(GrFragmentProcessor** fp,
// the outside. // the outside.
maskDesc.fWidth = texture->width(); maskDesc.fWidth = texture->width();
maskDesc.fHeight = texture->height(); maskDesc.fHeight = texture->height();
SkAutoTUnref<GrTexture> maskTexture( SkAutoTUnref<GrTexture> maskTexture(context->textureProvider()->refScratchTexture(
context->refScratchTexture(maskDesc, GrContext::kApprox_ScratchTexMatch)); maskDesc, GrTextureProvider::kApprox_ScratchTexMatch));
if (!maskTexture) { if (!maskTexture) {
return false; return false;
} }

View File

@ -617,7 +617,8 @@ public:
/** /**
* Create a simple filter effect with custom bicubic coefficients. * Create a simple filter effect with custom bicubic coefficients.
*/ */
static GrFragmentProcessor* Create(GrContext *context, const SkRect& rect, float sigma) { static GrFragmentProcessor* Create(GrTextureProvider *textureProvider, const SkRect& rect,
float sigma) {
GrTexture *blurProfileTexture = NULL; GrTexture *blurProfileTexture = NULL;
int doubleProfileSize = SkScalarCeilToInt(12*sigma); int doubleProfileSize = SkScalarCeilToInt(12*sigma);
@ -628,7 +629,8 @@ public:
return NULL; return NULL;
} }
bool createdBlurProfileTexture = CreateBlurProfileTexture(context, sigma, &blurProfileTexture); bool createdBlurProfileTexture = CreateBlurProfileTexture(
textureProvider, sigma, &blurProfileTexture);
SkAutoTUnref<GrTexture> hunref(blurProfileTexture); SkAutoTUnref<GrTexture> hunref(blurProfileTexture);
if (!createdBlurProfileTexture) { if (!createdBlurProfileTexture) {
return NULL; return NULL;
@ -645,7 +647,7 @@ private:
void onComputeInvariantOutput(GrInvariantOutput* inout) const override; void onComputeInvariantOutput(GrInvariantOutput* inout) const override;
static bool CreateBlurProfileTexture(GrContext *context, float sigma, static bool CreateBlurProfileTexture(GrTextureProvider*, float sigma,
GrTexture **blurProfileTexture); GrTexture **blurProfileTexture);
SkRect fRect; SkRect fRect;
@ -748,7 +750,7 @@ void GrGLRectBlurEffect::setData(const GrGLProgramDataManager& pdman,
pdman.set1f(fProfileSizeUniform, SkScalarCeilToScalar(6*rbe.getSigma())); pdman.set1f(fProfileSizeUniform, SkScalarCeilToScalar(6*rbe.getSigma()));
} }
bool GrRectBlurEffect::CreateBlurProfileTexture(GrContext *context, float sigma, bool GrRectBlurEffect::CreateBlurProfileTexture(GrTextureProvider* textureProvider, float sigma,
GrTexture **blurProfileTexture) { GrTexture **blurProfileTexture) {
GrSurfaceDesc texDesc; GrSurfaceDesc texDesc;
@ -767,19 +769,19 @@ bool GrRectBlurEffect::CreateBlurProfileTexture(GrContext *context, float sigma,
uint8_t *profile = NULL; uint8_t *profile = NULL;
SkAutoTDeleteArray<uint8_t> ada(NULL); SkAutoTDeleteArray<uint8_t> ada(NULL);
*blurProfileTexture = context->findAndRefCachedTexture(key); *blurProfileTexture = textureProvider->findAndRefTextureByUniqueKey(key);
if (NULL == *blurProfileTexture) { if (NULL == *blurProfileTexture) {
SkBlurMask::ComputeBlurProfile(sigma, &profile); SkBlurMask::ComputeBlurProfile(sigma, &profile);
ada.reset(profile); ada.reset(profile);
*blurProfileTexture = context->createTexture(texDesc, true, profile, 0); *blurProfileTexture = textureProvider->createTexture(texDesc, true, profile, 0);
if (NULL == *blurProfileTexture) { if (NULL == *blurProfileTexture) {
return false; return false;
} }
context->addResourceToCache(key, *blurProfileTexture); textureProvider->assignUniqueKeyToTexture(key, *blurProfileTexture);
} }
return true; return true;
@ -825,7 +827,8 @@ GrFragmentProcessor* GrRectBlurEffect::TestCreate(SkRandom* random,
float sigma = random->nextRangeF(3,8); float sigma = random->nextRangeF(3,8);
float width = random->nextRangeF(200,300); float width = random->nextRangeF(200,300);
float height = random->nextRangeF(200,300); float height = random->nextRangeF(200,300);
return GrRectBlurEffect::Create(context, SkRect::MakeWH(width, height), sigma); return GrRectBlurEffect::Create(context->textureProvider(), SkRect::MakeWH(width, height),
sigma);
} }
@ -855,7 +858,8 @@ bool SkBlurMaskFilterImpl::directFilterMaskGPU(GrContext* context,
int pad=SkScalarCeilToInt(6*xformedSigma)/2; int pad=SkScalarCeilToInt(6*xformedSigma)/2;
rect.outset(SkIntToScalar(pad), SkIntToScalar(pad)); rect.outset(SkIntToScalar(pad), SkIntToScalar(pad));
SkAutoTUnref<GrFragmentProcessor> fp(GrRectBlurEffect::Create(context, rect, xformedSigma)); SkAutoTUnref<GrFragmentProcessor> fp(GrRectBlurEffect::Create(
context->textureProvider(), rect, xformedSigma));
if (!fp) { if (!fp) {
return false; return false;
} }
@ -927,7 +931,8 @@ GrFragmentProcessor* GrRRectBlurEffect::Create(GrContext* context, float sigma,
builder[1] = cornerRadius; builder[1] = cornerRadius;
builder.finish(); builder.finish();
SkAutoTUnref<GrTexture> blurNinePatchTexture(context->findAndRefCachedTexture(key)); SkAutoTUnref<GrTexture> blurNinePatchTexture(
context->textureProvider()->findAndRefTextureByUniqueKey(key));
if (!blurNinePatchTexture) { if (!blurNinePatchTexture) {
SkMask mask; SkMask mask;
@ -964,12 +969,13 @@ GrFragmentProcessor* GrRRectBlurEffect::Create(GrContext* context, float sigma,
texDesc.fHeight = texSide; texDesc.fHeight = texSide;
texDesc.fConfig = kAlpha_8_GrPixelConfig; texDesc.fConfig = kAlpha_8_GrPixelConfig;
blurNinePatchTexture.reset(context->createTexture(texDesc, true, blurredMask.fImage, 0)); blurNinePatchTexture.reset(
context->textureProvider()->createTexture(texDesc, true, blurredMask.fImage, 0));
SkMask::FreeImage(blurredMask.fImage); SkMask::FreeImage(blurredMask.fImage);
if (!blurNinePatchTexture) { if (!blurNinePatchTexture) {
return NULL; return NULL;
} }
context->addResourceToCache(key, blurNinePatchTexture); context->textureProvider()->assignUniqueKeyToTexture(key, blurNinePatchTexture);
} }
return SkNEW_ARGS(GrRRectBlurEffect, (sigma, rrect, blurNinePatchTexture)); return SkNEW_ARGS(GrRRectBlurEffect, (sigma, rrect, blurNinePatchTexture));
} }

View File

@ -351,11 +351,13 @@ bool SkColorCubeFilter::asFragmentProcessors(GrContext* context,
desc.fHeight = fCache.cubeDimension() * fCache.cubeDimension(); desc.fHeight = fCache.cubeDimension() * fCache.cubeDimension();
desc.fConfig = kRGBA_8888_GrPixelConfig; desc.fConfig = kRGBA_8888_GrPixelConfig;
SkAutoTUnref<GrTexture> textureCube(context->findAndRefCachedTexture(key)); SkAutoTUnref<GrTexture> textureCube(
context->textureProvider()->findAndRefTextureByUniqueKey(key));
if (!textureCube) { if (!textureCube) {
textureCube.reset(context->createTexture(desc, true, fCubeData->data(), 0)); textureCube.reset(context->textureProvider()->createTexture(
desc, true, fCubeData->data(), 0));
if (textureCube) { if (textureCube) {
context->addResourceToCache(key, textureCube); context->textureProvider()->assignUniqueKeyToTexture(key, textureCube);
} }
} }

View File

@ -429,8 +429,8 @@ bool SkDisplacementMapEffect::filterImageGPU(Proxy* proxy, const SkBitmap& src,
desc.fHeight = bounds.height(); desc.fHeight = bounds.height();
desc.fConfig = kSkia8888_GrPixelConfig; desc.fConfig = kSkia8888_GrPixelConfig;
SkAutoTUnref<GrTexture> dst( SkAutoTUnref<GrTexture> dst(context->textureProvider()->refScratchTexture(desc,
context->refScratchTexture(desc, GrContext::kApprox_ScratchTexMatch)); GrTextureProvider::kApprox_ScratchTexMatch));
if (!dst) { if (!dst) {
return false; return false;

View File

@ -180,12 +180,14 @@ GrTexture* GaussianBlur(GrContext* context,
GrTexture* tempTexture; GrTexture* tempTexture;
SkAutoTUnref<GrTexture> temp1, temp2; SkAutoTUnref<GrTexture> temp1, temp2;
temp1.reset(context->refScratchTexture(desc, GrContext::kApprox_ScratchTexMatch)); temp1.reset(context->textureProvider()->refScratchTexture(
desc, GrTextureProvider::kApprox_ScratchTexMatch));
dstTexture = temp1.get(); dstTexture = temp1.get();
if (canClobberSrc) { if (canClobberSrc) {
tempTexture = srcTexture; tempTexture = srcTexture;
} else { } else {
temp2.reset(context->refScratchTexture(desc, GrContext::kApprox_ScratchTexMatch)); temp2.reset(context->textureProvider()->refScratchTexture(
desc, GrTextureProvider::kApprox_ScratchTexMatch));
tempTexture = temp2.get(); tempTexture = temp2.get();
} }

View File

@ -365,8 +365,8 @@ bool SkLightingImageFilterInternal::filterImageGPU(Proxy* proxy,
desc.fHeight = bounds.height(); desc.fHeight = bounds.height();
desc.fConfig = kRGBA_8888_GrPixelConfig; desc.fConfig = kRGBA_8888_GrPixelConfig;
SkAutoTUnref<GrTexture> dst( SkAutoTUnref<GrTexture> dst(context->textureProvider()->refScratchTexture(desc,
context->refScratchTexture(desc, GrContext::kApprox_ScratchTexMatch)); GrTextureProvider::kApprox_ScratchTexMatch));
if (!dst) { if (!dst) {
return false; return false;
} }

View File

@ -667,7 +667,8 @@ bool apply_morphology(const SkBitmap& input,
SkIRect srcRect = rect; SkIRect srcRect = rect;
if (radius.fWidth > 0) { if (radius.fWidth > 0) {
GrTexture* texture = context->refScratchTexture(desc, GrContext::kApprox_ScratchTexMatch); GrTexture* texture = context->textureProvider()->refScratchTexture(
desc, GrTextureProvider::kApprox_ScratchTexMatch);
if (NULL == texture) { if (NULL == texture) {
return false; return false;
} }
@ -684,7 +685,8 @@ bool apply_morphology(const SkBitmap& input,
srcRect = dstRect; srcRect = dstRect;
} }
if (radius.fHeight > 0) { if (radius.fHeight > 0) {
GrTexture* texture = context->refScratchTexture(desc, GrContext::kApprox_ScratchTexMatch); GrTexture* texture = context->textureProvider()->refScratchTexture(desc,
GrTextureProvider::kApprox_ScratchTexMatch);
if (NULL == texture) { if (NULL == texture) {
return false; return false;
} }

View File

@ -148,8 +148,8 @@ bool SkXfermodeImageFilter::filterImageGPU(Proxy* proxy,
desc.fWidth = src.width(); desc.fWidth = src.width();
desc.fHeight = src.height(); desc.fHeight = src.height();
desc.fConfig = kSkia8888_GrPixelConfig; desc.fConfig = kSkia8888_GrPixelConfig;
SkAutoTUnref<GrTexture> dst( SkAutoTUnref<GrTexture> dst(context->textureProvider()->refScratchTexture(
context->refScratchTexture(desc, GrContext::kApprox_ScratchTexMatch)); desc, GrTextureProvider::kApprox_ScratchTexMatch));
if (!dst) { if (!dst) {
return false; return false;
} }

View File

@ -590,8 +590,8 @@ bool GrAADistanceFieldPathRenderer::onDrawPath(GrDrawTarget* target,
// We don't want to flush the context so we claim we're in the middle of flushing so as to // We don't want to flush the context so we claim we're in the middle of flushing so as to
// guarantee we do not recieve a texture with pending IO // guarantee we do not recieve a texture with pending IO
GrTexture* texture = fContext->refScratchTexture(desc, GrContext::kApprox_ScratchTexMatch, GrTexture* texture = fContext->textureProvider()->refScratchTexture(
true); desc, GrTextureProvider::kApprox_ScratchTexMatch, true);
if (texture) { if (texture) {
fAtlas = SkNEW_ARGS(GrBatchAtlas, (texture, NUM_PLOTS_X, NUM_PLOTS_Y)); fAtlas = SkNEW_ARGS(GrBatchAtlas, (texture, NUM_PLOTS_X, NUM_PLOTS_Y));
} else { } else {

View File

@ -27,7 +27,8 @@ static GrBatchAtlas* make_atlas(GrContext* context, GrPixelConfig config,
// We don't want to flush the context so we claim we're in the middle of flushing so as to // We don't want to flush the context so we claim we're in the middle of flushing so as to
// guarantee we do not recieve a texture with pending IO // guarantee we do not recieve a texture with pending IO
GrTexture* texture = context->refScratchTexture(desc, GrContext::kApprox_ScratchTexMatch, true); GrTexture* texture = context->textureProvider()->refScratchTexture(
desc, GrTextureProvider::kApprox_ScratchTexMatch, true);
if (!texture) { if (!texture) {
return NULL; return NULL;
} }

View File

@ -206,8 +206,8 @@ private:
// HACK: set the last param to true to indicate that this request is at // HACK: set the last param to true to indicate that this request is at
// flush time and therefore we require a scratch texture with no pending IO operations. // flush time and therefore we require a scratch texture with no pending IO operations.
fLastMask.reset(context->refScratchTexture(desc, GrContext::kApprox_ScratchTexMatch, fLastMask.reset(context->textureProvider()->refScratchTexture(
/*flushing=*/true)); desc, GrTextureProvider::kApprox_ScratchTexMatch, /*flushing=*/true));
fLastBound = bound; fLastBound = bound;
} }

View File

@ -496,7 +496,8 @@ GrTexture* GrClipMaskManager::createTempMask(int width, int height) {
desc.fConfig = kRGBA_8888_GrPixelConfig; desc.fConfig = kRGBA_8888_GrPixelConfig;
} }
return this->getContext()->refScratchTexture(desc, GrContext::kApprox_ScratchTexMatch); return this->getContext()->textureProvider()->refScratchTexture(
desc, GrTextureProvider::kApprox_ScratchTexMatch);
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////

View File

@ -27,6 +27,7 @@
#include "GrPathUtils.h" #include "GrPathUtils.h"
#include "GrRenderTargetPriv.h" #include "GrRenderTargetPriv.h"
#include "GrResourceCache.h" #include "GrResourceCache.h"
#include "GrResourceProvider.h"
#include "GrSoftwarePathRenderer.h" #include "GrSoftwarePathRenderer.h"
#include "GrStencilAndCoverTextContext.h" #include "GrStencilAndCoverTextContext.h"
#include "GrStrokeInfo.h" #include "GrStrokeInfo.h"
@ -92,9 +93,10 @@ GrContext* GrContext::Create(GrBackend backend, GrBackendContext backendContext,
GrContext::GrContext(const Options& opts) : fOptions(opts) { GrContext::GrContext(const Options& opts) : fOptions(opts) {
fGpu = NULL; fGpu = NULL;
fResourceCache = NULL;
fResourceProvider = NULL;
fPathRendererChain = NULL; fPathRendererChain = NULL;
fSoftwarePathRenderer = NULL; fSoftwarePathRenderer = NULL;
fResourceCache = NULL;
fBatchFontCache = NULL; fBatchFontCache = NULL;
fDrawBuffer = NULL; fDrawBuffer = NULL;
fDrawBufferVBAllocPool = NULL; fDrawBufferVBAllocPool = NULL;
@ -119,6 +121,7 @@ bool GrContext::init(GrBackend backend, GrBackendContext backendContext) {
void GrContext::initCommon() { void GrContext::initCommon() {
fResourceCache = SkNEW(GrResourceCache); fResourceCache = SkNEW(GrResourceCache);
fResourceCache->setOverBudgetCallback(OverBudgetCB, this); fResourceCache->setOverBudgetCallback(OverBudgetCB, this);
fResourceProvider = SkNEW_ARGS(GrResourceProvider, (fGpu, fResourceCache));
fLayerCache.reset(SkNEW_ARGS(GrLayerCache, (this))); fLayerCache.reset(SkNEW_ARGS(GrLayerCache, (this)));
@ -146,6 +149,7 @@ GrContext::~GrContext() {
(*fCleanUpData[i].fFunc)(this, fCleanUpData[i].fInfo); (*fCleanUpData[i].fFunc)(this, fCleanUpData[i].fInfo);
} }
SkDELETE(fResourceProvider);
SkDELETE(fResourceCache); SkDELETE(fResourceCache);
SkDELETE(fBatchFontCache); SkDELETE(fBatchFontCache);
SkDELETE(fDrawBuffer); SkDELETE(fDrawBuffer);
@ -161,6 +165,7 @@ GrContext::~GrContext() {
} }
void GrContext::abandonContext() { void GrContext::abandonContext() {
fResourceProvider->abandon();
// abandon first to so destructors // abandon first to so destructors
// don't try to free the resources in the API. // don't try to free the resources in the API.
fResourceCache->abandonAll(); fResourceCache->abandonAll();
@ -237,11 +242,6 @@ GrTextContext* GrContext::createTextContext(GrRenderTarget* renderTarget,
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
enum ScratchTextureFlags {
kExact_ScratchTextureFlag = 0x1,
kNoPendingIO_ScratchTextureFlag = 0x2,
kNoCreate_ScratchTextureFlag = 0x4,
};
bool GrContext::isConfigTexturable(GrPixelConfig config) const { bool GrContext::isConfigTexturable(GrPixelConfig config) const {
return fGpu->caps()->isConfigTexturable(config); return fGpu->caps()->isConfigTexturable(config);
@ -251,90 +251,6 @@ bool GrContext::npotTextureTileSupport() const {
return fGpu->caps()->npotTextureTileSupport(); return fGpu->caps()->npotTextureTileSupport();
} }
GrTexture* GrContext::createTexture(const GrSurfaceDesc& desc, bool budgeted, const void* srcData,
size_t rowBytes) {
RETURN_NULL_IF_ABANDONED
if ((desc.fFlags & kRenderTarget_GrSurfaceFlag) &&
!this->isConfigRenderable(desc.fConfig, desc.fSampleCnt > 0)) {
return NULL;
}
if (!GrPixelConfigIsCompressed(desc.fConfig)) {
static const uint32_t kFlags = kExact_ScratchTextureFlag |
kNoCreate_ScratchTextureFlag;
if (GrTexture* texture = this->internalRefScratchTexture(desc, kFlags)) {
if (!srcData || texture->writePixels(0, 0, desc.fWidth, desc.fHeight, desc.fConfig,
srcData, rowBytes)) {
if (!budgeted) {
texture->resourcePriv().makeUnbudgeted();
}
return texture;
}
texture->unref();
}
}
return fGpu->createTexture(desc, budgeted, srcData, rowBytes);
}
GrTexture* GrContext::refScratchTexture(const GrSurfaceDesc& desc, ScratchTexMatch match,
bool calledDuringFlush) {
RETURN_NULL_IF_ABANDONED
// Currently we don't recycle compressed textures as scratch.
if (GrPixelConfigIsCompressed(desc.fConfig)) {
return NULL;
} else {
uint32_t flags = 0;
if (kExact_ScratchTexMatch == match) {
flags |= kExact_ScratchTextureFlag;
}
if (calledDuringFlush) {
flags |= kNoPendingIO_ScratchTextureFlag;
}
return this->internalRefScratchTexture(desc, flags);
}
}
GrTexture* GrContext::internalRefScratchTexture(const GrSurfaceDesc& inDesc, uint32_t flags) {
SkASSERT(!GrPixelConfigIsCompressed(inDesc.fConfig));
SkTCopyOnFirstWrite<GrSurfaceDesc> desc(inDesc);
if (fGpu->caps()->reuseScratchTextures() || (desc->fFlags & kRenderTarget_GrSurfaceFlag)) {
if (!(kExact_ScratchTextureFlag & flags)) {
// bin by pow2 with a reasonable min
static const int MIN_SIZE = 16;
GrSurfaceDesc* wdesc = desc.writable();
wdesc->fWidth = SkTMax(MIN_SIZE, GrNextPow2(desc->fWidth));
wdesc->fHeight = SkTMax(MIN_SIZE, GrNextPow2(desc->fHeight));
}
GrScratchKey key;
GrTexturePriv::ComputeScratchKey(*desc, &key);
uint32_t scratchFlags = 0;
if (kNoPendingIO_ScratchTextureFlag & flags) {
scratchFlags = GrResourceCache::kRequireNoPendingIO_ScratchFlag;
} else if (!(desc->fFlags & kRenderTarget_GrSurfaceFlag)) {
// If it is not a render target then it will most likely be populated by
// writePixels() which will trigger a flush if the texture has pending IO.
scratchFlags = GrResourceCache::kPreferNoPendingIO_ScratchFlag;
}
GrGpuResource* resource = fResourceCache->findAndRefScratchResource(key, scratchFlags);
if (resource) {
GrSurface* surface = static_cast<GrSurface*>(resource);
GrRenderTarget* rt = surface->asRenderTarget();
if (rt && fGpu->caps()->discardRenderTargetSupport()) {
rt->discard();
}
return surface->asTexture();
}
}
if (!(kNoCreate_ScratchTextureFlag & flags)) {
return fGpu->createTexture(*desc, true, NULL, 0);
}
return NULL;
}
void GrContext::OverBudgetCB(void* data) { void GrContext::OverBudgetCB(void* data) {
SkASSERT(data); SkASSERT(data);
@ -369,18 +285,6 @@ int GrContext::getMaxSampleCount() const {
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
GrTexture* GrContext::wrapBackendTexture(const GrBackendTextureDesc& desc) {
RETURN_NULL_IF_ABANDONED
return fGpu->wrapBackendTexture(desc);
}
GrRenderTarget* GrContext::wrapBackendRenderTarget(const GrBackendRenderTargetDesc& desc) {
RETURN_NULL_IF_ABANDONED
return fGpu->wrapBackendRenderTarget(desc);
}
////////////////////////////////////////////////////////////////////////////////
void GrContext::clear(const SkIRect* rect, void GrContext::clear(const SkIRect* rect,
const GrColor color, const GrColor color,
bool canIgnoreRect, bool canIgnoreRect,
@ -1543,7 +1447,8 @@ bool GrContext::writeSurfacePixels(GrSurface* surface,
desc.fWidth = width; desc.fWidth = width;
desc.fHeight = height; desc.fHeight = height;
desc.fConfig = writeConfig; desc.fConfig = writeConfig;
SkAutoTUnref<GrTexture> texture(this->refScratchTexture(desc, kApprox_ScratchTexMatch)); SkAutoTUnref<GrTexture> texture(this->textureProvider()->refScratchTexture(desc,
GrTextureProvider::kApprox_ScratchTexMatch));
if (!texture) { if (!texture) {
return false; return false;
} }
@ -1688,15 +1593,15 @@ bool GrContext::readRenderTargetPixels(GrRenderTarget* target,
// match the passed rect. However, if we see many different size rectangles we will trash // match the passed rect. However, if we see many different size rectangles we will trash
// our texture cache and pay the cost of creating and destroying many textures. So, we only // our texture cache and pay the cost of creating and destroying many textures. So, we only
// request an exact match when the caller is reading an entire RT. // request an exact match when the caller is reading an entire RT.
ScratchTexMatch match = kApprox_ScratchTexMatch; GrTextureProvider::ScratchTexMatch match = GrTextureProvider::kApprox_ScratchTexMatch;
if (0 == left && if (0 == left &&
0 == top && 0 == top &&
target->width() == width && target->width() == width &&
target->height() == height && target->height() == height &&
fGpu->fullReadPixelsIsFasterThanPartial()) { fGpu->fullReadPixelsIsFasterThanPartial()) {
match = kExact_ScratchTexMatch; match = GrTextureProvider::kExact_ScratchTexMatch;
} }
tempTexture.reset(this->refScratchTexture(desc, match)); tempTexture.reset(this->textureProvider()->refScratchTexture(desc, match));
if (tempTexture) { if (tempTexture) {
// compute a matrix to perform the draw // compute a matrix to perform the draw
SkMatrix textureMatrix; SkMatrix textureMatrix;
@ -1990,22 +1895,6 @@ void GrContext::setResourceCacheLimits(int maxTextures, size_t maxTextureBytes)
fResourceCache->setLimits(maxTextures, maxTextureBytes); fResourceCache->setLimits(maxTextures, maxTextureBytes);
} }
void GrContext::addResourceToCache(const GrUniqueKey& key, GrGpuResource* resource) {
ASSERT_OWNED_RESOURCE(resource);
if (!resource) {
return;
}
resource->resourcePriv().setUniqueKey(key);
}
bool GrContext::isResourceInCache(const GrUniqueKey& key) const {
return fResourceCache->hasUniqueKey(key);
}
GrGpuResource* GrContext::findAndRefCachedResource(const GrUniqueKey& key) {
return fResourceCache->findAndRefUniqueResource(key);
}
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
void GrContext::addGpuTraceMarker(const GrGpuTraceMarker* marker) { void GrContext::addGpuTraceMarker(const GrGpuTraceMarker* marker) {
@ -2021,4 +1910,3 @@ void GrContext::removeGpuTraceMarker(const GrGpuTraceMarker* marker) {
fDrawBuffer->removeGpuTraceMarker(marker); fDrawBuffer->removeGpuTraceMarker(marker);
} }
} }

View File

@ -122,8 +122,8 @@ bool GrDrawTarget::setupDstReadIfNecessary(const GrPipelineBuilder& pipelineBuil
desc.fWidth = copyRect.width(); desc.fWidth = copyRect.width();
desc.fHeight = copyRect.height(); desc.fHeight = copyRect.height();
SkAutoTUnref<GrTexture> copy( SkAutoTUnref<GrTexture> copy(fContext->textureProvider()->refScratchTexture(desc,
fContext->refScratchTexture(desc, GrContext::kApprox_ScratchTexMatch)); GrTextureProvider::kApprox_ScratchTexMatch));
if (!copy) { if (!copy) {
SkDebugf("Failed to create temporary copy of destination texture.\n"); SkDebugf("Failed to create temporary copy of destination texture.\n");

View File

@ -248,12 +248,12 @@ bool GrLayerCache::lock(GrCachedLayer* layer, const GrSurfaceDesc& desc, bool* n
} }
// TODO: make the test for exact match depend on the image filters themselves // TODO: make the test for exact match depend on the image filters themselves
GrContext::ScratchTexMatch usage = GrContext::kApprox_ScratchTexMatch; GrTextureProvider::ScratchTexMatch usage = GrTextureProvider::kApprox_ScratchTexMatch;
if (layer->fFilter) { if (layer->fFilter) {
usage = GrContext::kExact_ScratchTexMatch; usage = GrTextureProvider::kExact_ScratchTexMatch;
} }
SkAutoTUnref<GrTexture> tex(fContext->refScratchTexture(desc, usage)); SkAutoTUnref<GrTexture> tex(fContext->textureProvider()->refScratchTexture(desc, usage));
if (!tex) { if (!tex) {
return false; return false;
} }

View File

@ -0,0 +1,30 @@
/*
* Copyright 2015 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef GrResourceProvider_DEFINED
#define GrResourceProvider_DEFINED
#include "GrTextureProvider.h"
/**
* An extension of the texture provider for arbitrary resource types. This class is intended for
* use within the Gr code base, not by clients or extensions (e.g. third party GrProcessor
* derivatives).
*/
class GrResourceProvider : public GrTextureProvider {
public:
GrResourceProvider(GrGpu* gpu, GrResourceCache* cache) : INHERITED(gpu, cache) {}
using GrTextureProvider::assignUniqueKeyToResource;
using GrTextureProvider::findAndRefResourceByUniqueKey;
using GrTextureProvider::abandon;
typedef GrTextureProvider INHERITED;
};
#endif

View File

@ -248,7 +248,8 @@ GrTexture* GrSWMaskHelper::createTexture() {
SkASSERT(fContext->getGpu()->caps()->isConfigTexturable(desc.fConfig)); SkASSERT(fContext->getGpu()->caps()->isConfigTexturable(desc.fConfig));
} }
return fContext->refScratchTexture(desc, GrContext::kApprox_ScratchTexMatch); return fContext->textureProvider()->refScratchTexture(
desc, GrTextureProvider::kApprox_ScratchTexMatch);
} }
void GrSWMaskHelper::sendTextureData(GrTexture *texture, const GrSurfaceDesc& desc, void GrSWMaskHelper::sendTextureData(GrTexture *texture, const GrSurfaceDesc& desc,

View File

@ -14,6 +14,7 @@
#include "GrPath.h" #include "GrPath.h"
#include "GrRenderTarget.h" #include "GrRenderTarget.h"
#include "GrRenderTargetPriv.h" #include "GrRenderTargetPriv.h"
#include "GrResourceProvider.h"
#include "GrStrokeInfo.h" #include "GrStrokeInfo.h"
/* /*
@ -76,10 +77,11 @@ static GrPath* get_gr_path(GrGpu* gpu, const SkPath& skPath, const SkStrokeRec&
GrContext* ctx = gpu->getContext(); GrContext* ctx = gpu->getContext();
GrUniqueKey key; GrUniqueKey key;
GrPath::ComputeKey(skPath, stroke, &key); GrPath::ComputeKey(skPath, stroke, &key);
SkAutoTUnref<GrPath> path(static_cast<GrPath*>(ctx->findAndRefCachedResource(key))); SkAutoTUnref<GrPath> path(
static_cast<GrPath*>(ctx->resourceProvider()->findAndRefResourceByUniqueKey(key)));
if (NULL == path || !path->isEqualTo(skPath, stroke)) { if (NULL == path || !path->isEqualTo(skPath, stroke)) {
path.reset(gpu->pathRendering()->createPath(skPath, stroke)); path.reset(gpu->pathRendering()->createPath(skPath, stroke));
ctx->addResourceToCache(key, path); ctx->resourceProvider()->assignUniqueKeyToResource(key, path);
} }
return path.detach(); return path.detach();
} }

View File

@ -11,6 +11,7 @@
#include "GrGpu.h" #include "GrGpu.h"
#include "GrPath.h" #include "GrPath.h"
#include "GrPathRange.h" #include "GrPathRange.h"
#include "GrResourceProvider.h"
#include "SkAutoKern.h" #include "SkAutoKern.h"
#include "SkDraw.h" #include "SkDraw.h"
#include "SkDrawProcs.h" #include "SkDrawProcs.h"
@ -235,10 +236,10 @@ static GrPathRange* get_gr_glyphs(GrContext* ctx,
builder.finish(); builder.finish();
SkAutoTUnref<GrPathRange> glyphs( SkAutoTUnref<GrPathRange> glyphs(
static_cast<GrPathRange*>(ctx->findAndRefCachedResource(key))); static_cast<GrPathRange*>(ctx->resourceProvider()->findAndRefResourceByUniqueKey(key)));
if (NULL == glyphs || (NULL != desc && !glyphs->isEqualTo(*desc))) { if (NULL == glyphs || (NULL != desc && !glyphs->isEqualTo(*desc))) {
glyphs.reset(ctx->getGpu()->pathRendering()->createGlyphs(typeface, desc, stroke)); glyphs.reset(ctx->getGpu()->pathRendering()->createGlyphs(typeface, desc, stroke));
ctx->addResourceToCache(key, glyphs); ctx->resourceProvider()->assignUniqueKeyToResource(key, glyphs);
} }
return glyphs.detach(); return glyphs.detach();

View File

@ -0,0 +1,134 @@
/*
* Copyright 2015 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "GrTextureProvider.h"
#include "GrTexturePriv.h"
#include "GrResourceCache.h"
#include "GrGpu.h"
enum ScratchTextureFlags {
kExact_ScratchTextureFlag = 0x1,
kNoPendingIO_ScratchTextureFlag = 0x2,
kNoCreate_ScratchTextureFlag = 0x4,
};
GrTexture* GrTextureProvider::createTexture(const GrSurfaceDesc& desc, bool budgeted,
const void* srcData, size_t rowBytes) {
if (this->isAbandoned()) {
return NULL;
}
if ((desc.fFlags & kRenderTarget_GrSurfaceFlag) &&
!fGpu->caps()->isConfigRenderable(desc.fConfig, desc.fSampleCnt > 0)) {
return NULL;
}
if (!GrPixelConfigIsCompressed(desc.fConfig)) {
static const uint32_t kFlags = kExact_ScratchTextureFlag |
kNoCreate_ScratchTextureFlag;
if (GrTexture* texture = this->internalRefScratchTexture(desc, kFlags)) {
if (!srcData || texture->writePixels(0, 0, desc.fWidth, desc.fHeight, desc.fConfig,
srcData, rowBytes)) {
if (!budgeted) {
texture->resourcePriv().makeUnbudgeted();
}
return texture;
}
texture->unref();
}
}
return fGpu->createTexture(desc, budgeted, srcData, rowBytes);
}
GrTexture* GrTextureProvider::refScratchTexture(const GrSurfaceDesc& desc, ScratchTexMatch match,
bool calledDuringFlush) {
if (this->isAbandoned()) {
return NULL;
}
// Currently we don't recycle compressed textures as scratch.
if (GrPixelConfigIsCompressed(desc.fConfig)) {
return NULL;
} else {
uint32_t flags = 0;
if (kExact_ScratchTexMatch == match) {
flags |= kExact_ScratchTextureFlag;
}
if (calledDuringFlush) {
flags |= kNoPendingIO_ScratchTextureFlag;
}
return this->internalRefScratchTexture(desc, flags);
}
}
GrTexture* GrTextureProvider::internalRefScratchTexture(const GrSurfaceDesc& inDesc,
uint32_t flags) {
SkASSERT(!this->isAbandoned());
SkASSERT(!GrPixelConfigIsCompressed(inDesc.fConfig));
SkTCopyOnFirstWrite<GrSurfaceDesc> desc(inDesc);
if (fGpu->caps()->reuseScratchTextures() || (desc->fFlags & kRenderTarget_GrSurfaceFlag)) {
if (!(kExact_ScratchTextureFlag & flags)) {
// bin by pow2 with a reasonable min
static const int MIN_SIZE = 16;
GrSurfaceDesc* wdesc = desc.writable();
wdesc->fWidth = SkTMax(MIN_SIZE, GrNextPow2(desc->fWidth));
wdesc->fHeight = SkTMax(MIN_SIZE, GrNextPow2(desc->fHeight));
}
GrScratchKey key;
GrTexturePriv::ComputeScratchKey(*desc, &key);
uint32_t scratchFlags = 0;
if (kNoPendingIO_ScratchTextureFlag & flags) {
scratchFlags = GrResourceCache::kRequireNoPendingIO_ScratchFlag;
} else if (!(desc->fFlags & kRenderTarget_GrSurfaceFlag)) {
// If it is not a render target then it will most likely be populated by
// writePixels() which will trigger a flush if the texture has pending IO.
scratchFlags = GrResourceCache::kPreferNoPendingIO_ScratchFlag;
}
GrGpuResource* resource = fCache->findAndRefScratchResource(key, scratchFlags);
if (resource) {
GrSurface* surface = static_cast<GrSurface*>(resource);
GrRenderTarget* rt = surface->asRenderTarget();
if (rt && fGpu->caps()->discardRenderTargetSupport()) {
rt->discard();
}
return surface->asTexture();
}
}
if (!(kNoCreate_ScratchTextureFlag & flags)) {
return fGpu->createTexture(*desc, true, NULL, 0);
}
return NULL;
}
GrTexture* GrTextureProvider::wrapBackendTexture(const GrBackendTextureDesc& desc) {
if (this->isAbandoned()) {
return NULL;
}
return fGpu->wrapBackendTexture(desc);
}
GrRenderTarget* GrTextureProvider::wrapBackendRenderTarget(const GrBackendRenderTargetDesc& desc) {
return this->isAbandoned() ? NULL : fGpu->wrapBackendRenderTarget(desc);
}
void GrTextureProvider::assignUniqueKeyToResource(const GrUniqueKey& key, GrGpuResource* resource) {
if (this->isAbandoned() || !resource) {
return;
}
resource->resourcePriv().setUniqueKey(key);
}
bool GrTextureProvider::existsResourceWithUniqueKey(const GrUniqueKey& key) const {
return this->isAbandoned() ? false : fCache->hasUniqueKey(key);
}
GrGpuResource* GrTextureProvider::findAndRefResourceByUniqueKey(const GrUniqueKey& key) {
return this->isAbandoned() ? NULL : fCache->findAndRefUniqueResource(key);
}

View File

@ -199,7 +199,8 @@ GrRenderTarget* SkGpuDevice::CreateRenderTarget(GrContext* context, SkSurface::B
desc.fHeight = info.height(); desc.fHeight = info.height();
desc.fConfig = SkImageInfo2GrPixelConfig(info); desc.fConfig = SkImageInfo2GrPixelConfig(info);
desc.fSampleCnt = sampleCount; desc.fSampleCnt = sampleCount;
GrTexture* texture = context->createTexture(desc, SkToBool(budgeted), NULL, 0); GrTexture* texture = context->textureProvider()->createTexture(
desc, SkToBool(budgeted), NULL, 0);
if (NULL == texture) { if (NULL == texture) {
return NULL; return NULL;
} }
@ -699,8 +700,8 @@ bool draw_with_mask_filter(GrContext* context,
desc.fHeight = dstM.fBounds.height(); desc.fHeight = dstM.fBounds.height();
desc.fConfig = kAlpha_8_GrPixelConfig; desc.fConfig = kAlpha_8_GrPixelConfig;
SkAutoTUnref<GrTexture> texture( SkAutoTUnref<GrTexture> texture(context->textureProvider()->refScratchTexture(
context->refScratchTexture(desc, GrContext::kApprox_ScratchTexMatch)); desc, GrTextureProvider::kApprox_ScratchTexMatch));
if (!texture) { if (!texture) {
return false; return false;
} }
@ -734,7 +735,8 @@ GrTexture* create_mask_GPU(GrContext* context,
desc.fConfig = kAlpha_8_GrPixelConfig; desc.fConfig = kAlpha_8_GrPixelConfig;
} }
GrTexture* mask = context->refScratchTexture(desc,GrContext::kApprox_ScratchTexMatch); GrTexture* mask = context->textureProvider()->refScratchTexture(
desc, GrTextureProvider::kApprox_ScratchTexMatch);
if (NULL == mask) { if (NULL == mask) {
return NULL; return NULL;
} }
@ -1951,10 +1953,10 @@ SkBaseDevice* SkGpuDevice::onCreateDevice(const CreateInfo& cinfo, const SkPaint
// layers are never draw in repeat modes, so we can request an approx // layers are never draw in repeat modes, so we can request an approx
// match and ignore any padding. // match and ignore any padding.
const GrContext::ScratchTexMatch match = (kNever_TileUsage == cinfo.fTileUsage) ? const GrTextureProvider::ScratchTexMatch match = (kNever_TileUsage == cinfo.fTileUsage) ?
GrContext::kApprox_ScratchTexMatch : GrTextureProvider::kApprox_ScratchTexMatch :
GrContext::kExact_ScratchTexMatch; GrTextureProvider::kExact_ScratchTexMatch;
texture.reset(fContext->refScratchTexture(desc, match)); texture.reset(fContext->textureProvider()->refScratchTexture(desc, match));
if (texture) { if (texture) {
SkSurfaceProps props(fSurfaceProps.flags(), cinfo.fPixelGeometry); SkSurfaceProps props(fSurfaceProps.flags(), cinfo.fPixelGeometry);

View File

@ -177,11 +177,11 @@ static GrTexture* create_texture_for_bmp(GrContext* ctx,
SkPixelRef* pixelRefForInvalidationNotification, SkPixelRef* pixelRefForInvalidationNotification,
const void* pixels, const void* pixels,
size_t rowBytes) { size_t rowBytes) {
GrTexture* result = ctx->createTexture(desc, true, pixels, rowBytes); GrTexture* result = ctx->textureProvider()->createTexture(desc, true, pixels, rowBytes);
if (result && optionalKey.isValid()) { if (result && optionalKey.isValid()) {
BitmapInvalidator* listener = SkNEW_ARGS(BitmapInvalidator, (optionalKey)); BitmapInvalidator* listener = SkNEW_ARGS(BitmapInvalidator, (optionalKey));
pixelRefForInvalidationNotification->addGenIDChangeListener(listener); pixelRefForInvalidationNotification->addGenIDChangeListener(listener);
ctx->addResourceToCache(optionalKey, result); ctx->textureProvider()->assignUniqueKeyToTexture(optionalKey, result);
} }
return result; return result;
} }
@ -368,9 +368,9 @@ static GrTexture* load_yuv_texture(GrContext* ctx, const GrUniqueKey& optionalKe
bool needsExactTexture = bool needsExactTexture =
(yuvDesc.fWidth != yuvInfo.fSize[0].fWidth) || (yuvDesc.fWidth != yuvInfo.fSize[0].fWidth) ||
(yuvDesc.fHeight != yuvInfo.fSize[0].fHeight); (yuvDesc.fHeight != yuvInfo.fSize[0].fHeight);
yuvTextures[i].reset(ctx->refScratchTexture(yuvDesc, yuvTextures[i].reset(ctx->textureProvider()->refScratchTexture(yuvDesc,
needsExactTexture ? GrContext::kExact_ScratchTexMatch : needsExactTexture ? GrTextureProvider::kExact_ScratchTexMatch :
GrContext::kApprox_ScratchTexMatch)); GrTextureProvider::kApprox_ScratchTexMatch));
if (!yuvTextures[i] || if (!yuvTextures[i] ||
!yuvTextures[i]->writePixels(0, 0, yuvDesc.fWidth, yuvDesc.fHeight, !yuvTextures[i]->writePixels(0, 0, yuvDesc.fWidth, yuvDesc.fHeight,
yuvDesc.fConfig, planes[i], yuvInfo.fRowBytes[i])) { yuvDesc.fConfig, planes[i], yuvInfo.fRowBytes[i])) {
@ -471,7 +471,7 @@ static GrTexture* create_bitmap_texture(GrContext* ctx,
SkAutoTUnref<GrTexture> unstretched; SkAutoTUnref<GrTexture> unstretched;
// Check if we have the unstretched version in the cache, if not create it. // Check if we have the unstretched version in the cache, if not create it.
if (unstretchedKey.isValid()) { if (unstretchedKey.isValid()) {
unstretched.reset(ctx->findAndRefCachedTexture(unstretchedKey)); unstretched.reset(ctx->textureProvider()->findAndRefTextureByUniqueKey(unstretchedKey));
} }
if (!unstretched) { if (!unstretched) {
unstretched.reset(create_unstretched_bitmap_texture(ctx, bmp, unstretchedKey)); unstretched.reset(create_unstretched_bitmap_texture(ctx, bmp, unstretchedKey));
@ -509,7 +509,7 @@ bool GrIsBitmapInCache(const GrContext* ctx,
} }
GrUniqueKey stretchedKey; GrUniqueKey stretchedKey;
make_stretched_key(key, stretch, &stretchedKey); make_stretched_key(key, stretch, &stretchedKey);
return ctx->isResourceInCache(stretchedKey); return ctx->textureProvider()->existsTextureWithUniqueKey(stretchedKey);
} }
// We don't cache volatile bitmaps // We don't cache volatile bitmaps
@ -519,7 +519,8 @@ bool GrIsBitmapInCache(const GrContext* ctx,
GrUniqueKey key, stretchedKey; GrUniqueKey key, stretchedKey;
make_bitmap_keys(bitmap, stretch, &key, &stretchedKey); make_bitmap_keys(bitmap, stretch, &key, &stretchedKey);
return ctx->isResourceInCache((kNo_Stretch == stretch) ? key : stretchedKey); return ctx->textureProvider()->existsTextureWithUniqueKey(
(kNo_Stretch == stretch) ? key : stretchedKey);
} }
GrTexture* GrRefCachedBitmapTexture(GrContext* ctx, GrTexture* GrRefCachedBitmapTexture(GrContext* ctx,
@ -539,7 +540,8 @@ GrTexture* GrRefCachedBitmapTexture(GrContext* ctx,
const GrUniqueKey& key = result->getUniqueKey(); const GrUniqueKey& key = result->getUniqueKey();
if (key.isValid()) { if (key.isValid()) {
make_stretched_key(key, stretch, &stretchedKey); make_stretched_key(key, stretch, &stretchedKey);
GrTexture* stretched = ctx->findAndRefCachedTexture(stretchedKey); GrTexture* stretched =
ctx->textureProvider()->findAndRefTextureByUniqueKey(stretchedKey);
if (stretched) { if (stretched) {
return stretched; return stretched;
} }
@ -554,7 +556,8 @@ GrTexture* GrRefCachedBitmapTexture(GrContext* ctx,
// If the bitmap isn't changing try to find a cached copy first. // If the bitmap isn't changing try to find a cached copy first.
make_bitmap_keys(bitmap, stretch, &key, &resizedKey); make_bitmap_keys(bitmap, stretch, &key, &resizedKey);
result = ctx->findAndRefCachedTexture(resizedKey.isValid() ? resizedKey : key); result = ctx->textureProvider()->findAndRefTextureByUniqueKey(
resizedKey.isValid() ? resizedKey : key);
if (result) { if (result) {
return result; return result;
} }

View File

@ -80,7 +80,7 @@ static SkGrPixelRef* copy_to_new_texture_pixelref(GrTexture* texture, SkColorTyp
desc.fFlags = kRenderTarget_GrSurfaceFlag; desc.fFlags = kRenderTarget_GrSurfaceFlag;
desc.fConfig = SkImageInfo2GrPixelConfig(dstCT, kPremul_SkAlphaType, dstPT); desc.fConfig = SkImageInfo2GrPixelConfig(dstCT, kPremul_SkAlphaType, dstPT);
GrTexture* dst = context->createTexture(desc, false, NULL, 0); GrTexture* dst = context->textureProvider()->createTexture(desc, false, NULL, 0);
if (NULL == dst) { if (NULL == dst) {
return NULL; return NULL;
} }

View File

@ -186,16 +186,16 @@ void GrConfigConversionEffect::TestForPreservingPMConversions(GrContext* context
desc.fHeight = 256; desc.fHeight = 256;
desc.fConfig = kRGBA_8888_GrPixelConfig; desc.fConfig = kRGBA_8888_GrPixelConfig;
SkAutoTUnref<GrTexture> readTex(context->createTexture(desc, true, NULL, 0)); SkAutoTUnref<GrTexture> readTex(context->textureProvider()->createTexture(desc, true, NULL, 0));
if (!readTex.get()) { if (!readTex.get()) {
return; return;
} }
SkAutoTUnref<GrTexture> tempTex(context->createTexture(desc, true, NULL, 0)); SkAutoTUnref<GrTexture> tempTex(context->textureProvider()->createTexture(desc, true, NULL, 0));
if (!tempTex.get()) { if (!tempTex.get()) {
return; return;
} }
desc.fFlags = kNone_GrSurfaceFlags; desc.fFlags = kNone_GrSurfaceFlags;
SkAutoTUnref<GrTexture> dataTex(context->createTexture(desc, true, data, 0)); SkAutoTUnref<GrTexture> dataTex(context->textureProvider()->createTexture(desc, true, data, 0));
if (!dataTex.get()) { if (!dataTex.get()) {
return; return;
} }

View File

@ -204,13 +204,13 @@ void GrTextureStripAtlas::lockTexture() {
builder[0] = static_cast<uint32_t>(fCacheKey); builder[0] = static_cast<uint32_t>(fCacheKey);
builder.finish(); builder.finish();
fTexture = fDesc.fContext->findAndRefCachedTexture(key); fTexture = fDesc.fContext->textureProvider()->findAndRefTextureByUniqueKey(key);
if (NULL == fTexture) { if (NULL == fTexture) {
fTexture = fDesc.fContext->createTexture(texDesc, true, NULL, 0); fTexture = fDesc.fContext->textureProvider()->createTexture(texDesc, true, NULL, 0);
if (!fTexture) { if (!fTexture) {
return; return;
} }
fDesc.fContext->addResourceToCache(key, fTexture); fDesc.fContext->textureProvider()->assignUniqueKeyToTexture(key, fTexture);
// This is a new texture, so all of our cache info is now invalid // This is a new texture, so all of our cache info is now invalid
this->initLRU(); this->initLRU();
fKeyTable.rewind(); fKeyTable.rewind();

View File

@ -107,7 +107,7 @@ SkSurface* SkSurface::NewWrappedRenderTarget(GrContext* context, GrBackendTextur
if (!SkToBool(desc.fFlags & kRenderTarget_GrBackendTextureFlag)) { if (!SkToBool(desc.fFlags & kRenderTarget_GrBackendTextureFlag)) {
return NULL; return NULL;
} }
SkAutoTUnref<GrSurface> surface(context->wrapBackendTexture(desc)); SkAutoTUnref<GrSurface> surface(context->textureProvider()->wrapBackendTexture(desc));
if (!surface) { if (!surface) {
return NULL; return NULL;
} }

View File

@ -360,7 +360,7 @@ GrRenderTarget* SkWindow::renderTarget(const AttachmentInfo& attachmentInfo,
GrGLint buffer; GrGLint buffer;
GR_GL_GetIntegerv(interface, GR_GL_FRAMEBUFFER_BINDING, &buffer); GR_GL_GetIntegerv(interface, GR_GL_FRAMEBUFFER_BINDING, &buffer);
desc.fRenderTargetHandle = buffer; desc.fRenderTargetHandle = buffer;
return grContext->wrapBackendRenderTarget(desc); return grContext->textureProvider()->wrapBackendRenderTarget(desc);
} }
#endif #endif

View File

@ -31,7 +31,7 @@ static GrTexture* createTexture(GrContext* context) {
desc.fHeight = Y_SIZE; desc.fHeight = Y_SIZE;
// We are initializing the texture with zeros here // We are initializing the texture with zeros here
GrTexture* texture = context->createTexture(desc, false, textureData, 0); GrTexture* texture = context->textureProvider()->createTexture(desc, false, textureData, 0);
if (!texture) { if (!texture) {
return NULL; return NULL;
} }
@ -52,7 +52,7 @@ static void test_clip_bounds(skiatest::Reporter* reporter, GrContext* context) {
desc.fWidth = kXSize; desc.fWidth = kXSize;
desc.fHeight = kYSize; desc.fHeight = kYSize;
GrTexture* texture = context->createTexture(desc, false, NULL, 0); GrTexture* texture = context->textureProvider()->createTexture(desc, false, NULL, 0);
if (!texture) { if (!texture) {
return; return;
} }

View File

@ -11,9 +11,10 @@
* 32 bit floating point textures, and indeed floating point test values * 32 bit floating point textures, and indeed floating point test values
* have been selected to require 32 bits of precision and full IEEE conformance * have been selected to require 32 bits of precision and full IEEE conformance
*/ */
#if SK_SUPPORT_GPU
#include <float.h> #include <float.h>
#include "Test.h" #include "Test.h"
#if SK_SUPPORT_GPU
#include "GrContext.h" #include "GrContext.h"
#include "GrTexture.h" #include "GrTexture.h"
#include "GrContextFactory.h" #include "GrContextFactory.h"
@ -59,8 +60,8 @@ DEF_GPUTEST(FloatingPointTextureTest, reporter, factory) {
continue; continue;
} }
SkAutoTUnref<GrTexture> fpTexture(context->createTexture(desc, false, SkAutoTUnref<GrTexture> fpTexture(context->textureProvider()->createTexture(
controlPixelData.begin(), 0)); desc, false, controlPixelData.begin(), 0));
// Floating point textures are NOT supported everywhere // Floating point textures are NOT supported everywhere
if (NULL == fpTexture) { if (NULL == fpTexture) {
continue; continue;
@ -106,8 +107,8 @@ DEF_GPUTEST(HalfFloatTextureTest, reporter, factory) {
continue; continue;
} }
SkAutoTUnref<GrTexture> fpTexture(context->createTexture(desc, false, SkAutoTUnref<GrTexture> fpTexture(context->textureProvider()->createTexture(
controlPixelData.begin(), 0)); desc, false, controlPixelData.begin(), 0));
// 16-bit floating point textures are NOT supported everywhere // 16-bit floating point textures are NOT supported everywhere
if (NULL == fpTexture) { if (NULL == fpTexture) {
continue; continue;

View File

@ -115,11 +115,11 @@ static GrRenderTarget* random_render_target(GrContext* context, SkRandom* random
builder[0] = texDesc.fOrigin; builder[0] = texDesc.fOrigin;
builder.finish(); builder.finish();
GrTexture* texture = context->findAndRefCachedTexture(key); GrTexture* texture = context->textureProvider()->findAndRefTextureByUniqueKey(key);
if (!texture) { if (!texture) {
texture = context->createTexture(texDesc, true); texture = context->textureProvider()->createTexture(texDesc, true);
if (texture) { if (texture) {
context->addResourceToCache(key, texture); context->textureProvider()->assignUniqueKeyToTexture(key, texture);
} }
} }
return texture ? texture->asRenderTarget() : NULL; return texture ? texture->asRenderTarget() : NULL;

View File

@ -27,7 +27,7 @@ DEF_GPUTEST(GrSurface, reporter, factory) {
desc.fWidth = 256; desc.fWidth = 256;
desc.fHeight = 256; desc.fHeight = 256;
desc.fSampleCnt = 0; desc.fSampleCnt = 0;
GrSurface* texRT1 = context->createTexture(desc, false, NULL, 0); GrSurface* texRT1 = context->textureProvider()->createTexture(desc, false, NULL, 0);
REPORTER_ASSERT(reporter, texRT1 == texRT1->asRenderTarget()); REPORTER_ASSERT(reporter, texRT1 == texRT1->asRenderTarget());
REPORTER_ASSERT(reporter, texRT1 == texRT1->asTexture()); REPORTER_ASSERT(reporter, texRT1 == texRT1->asTexture());
@ -39,7 +39,7 @@ DEF_GPUTEST(GrSurface, reporter, factory) {
static_cast<GrSurface*>(texRT1->asTexture())); static_cast<GrSurface*>(texRT1->asTexture()));
desc.fFlags = kNone_GrSurfaceFlags; desc.fFlags = kNone_GrSurfaceFlags;
GrSurface* tex1 = context->createTexture(desc, false, NULL, 0); GrSurface* tex1 = context->textureProvider()->createTexture(desc, false, NULL, 0);
REPORTER_ASSERT(reporter, NULL == tex1->asRenderTarget()); REPORTER_ASSERT(reporter, NULL == tex1->asRenderTarget());
REPORTER_ASSERT(reporter, tex1 == tex1->asTexture()); REPORTER_ASSERT(reporter, tex1 == tex1->asTexture());
REPORTER_ASSERT(reporter, static_cast<GrSurface*>(tex1) == tex1->asTexture()); REPORTER_ASSERT(reporter, static_cast<GrSurface*>(tex1) == tex1->asTexture());
@ -51,7 +51,7 @@ DEF_GPUTEST(GrSurface, reporter, factory) {
backendDesc.fHeight = 256; backendDesc.fHeight = 256;
backendDesc.fSampleCnt = 0; backendDesc.fSampleCnt = 0;
backendDesc.fTextureHandle = 5; backendDesc.fTextureHandle = 5;
GrSurface* texRT2 = context->wrapBackendTexture(backendDesc); GrSurface* texRT2 = context->textureProvider()->wrapBackendTexture(backendDesc);
REPORTER_ASSERT(reporter, texRT2 == texRT2->asRenderTarget()); REPORTER_ASSERT(reporter, texRT2 == texRT2->asRenderTarget());
REPORTER_ASSERT(reporter, texRT2 == texRT2->asTexture()); REPORTER_ASSERT(reporter, texRT2 == texRT2->asTexture());
REPORTER_ASSERT(reporter, static_cast<GrSurface*>(texRT2->asRenderTarget()) == REPORTER_ASSERT(reporter, static_cast<GrSurface*>(texRT2->asRenderTarget()) ==

View File

@ -318,7 +318,8 @@ DEF_GPUTEST(ReadPixels, reporter, factory) {
desc.fHeight = DEV_H; desc.fHeight = DEV_H;
desc.fConfig = kSkia8888_GrPixelConfig; desc.fConfig = kSkia8888_GrPixelConfig;
desc.fOrigin = 1 == dtype ? kBottomLeft_GrSurfaceOrigin : kTopLeft_GrSurfaceOrigin; desc.fOrigin = 1 == dtype ? kBottomLeft_GrSurfaceOrigin : kTopLeft_GrSurfaceOrigin;
SkAutoTUnref<GrTexture> texture(context->createTexture(desc, false)); SkAutoTUnref<GrTexture> texture(
context->textureProvider()->createTexture(desc, false));
surface.reset(SkSurface::NewRenderTargetDirect(texture->asRenderTarget())); surface.reset(SkSurface::NewRenderTargetDirect(texture->asRenderTarget()));
#else #else
continue; continue;

View File

@ -41,7 +41,7 @@ DEF_GPUTEST(ReadWriteAlpha, reporter, factory) {
desc.fHeight = Y_SIZE; desc.fHeight = Y_SIZE;
// We are initializing the texture with zeros here // We are initializing the texture with zeros here
GrTexture* texture = context->createTexture(desc, false, textureData, 0); GrTexture* texture = context->textureProvider()->createTexture(desc, false, textureData, 0);
if (!texture) { if (!texture) {
return; return;
} }

View File

@ -5,10 +5,10 @@
* found in the LICENSE file. * found in the LICENSE file.
*/ */
#if SK_SUPPORT_GPU
#include "Test.h" #include "Test.h"
#if SK_SUPPORT_GPU
#include "GrContextFactory.h" #include "GrContextFactory.h"
#include "GrLayerCache.h" #include "GrLayerCache.h"
#include "GrRecordReplaceDraw.h" #include "GrRecordReplaceDraw.h"
@ -124,7 +124,8 @@ void test_replacements(skiatest::Reporter* r, GrContext* context, bool useBBH) {
desc.fHeight = kHeight; desc.fHeight = kHeight;
desc.fSampleCnt = 0; desc.fSampleCnt = 0;
SkAutoTUnref<GrTexture> texture(context->createTexture(desc, false, NULL, 0)); SkAutoTUnref<GrTexture> texture(context->textureProvider()->createTexture(desc,
false, NULL, 0));
layer->setTexture(texture, SkIRect::MakeWH(kWidth, kHeight)); layer->setTexture(texture, SkIRect::MakeWH(kWidth, kHeight));
SkAutoTUnref<SkBBoxHierarchy> bbh; SkAutoTUnref<SkBBoxHierarchy> bbh;

View File

@ -76,13 +76,14 @@ static void test_stencil_buffers(skiatest::Reporter* reporter, GrContext* contex
smallDesc.fHeight = 4; smallDesc.fHeight = 4;
smallDesc.fSampleCnt = 0; smallDesc.fSampleCnt = 0;
GrTextureProvider* cache = context->textureProvider();
// Test that two budgeted RTs with the same desc share a stencil buffer. // Test that two budgeted RTs with the same desc share a stencil buffer.
SkAutoTUnref<GrTexture> smallRT0(context->createTexture(smallDesc, true)); SkAutoTUnref<GrTexture> smallRT0(cache->createTexture(smallDesc, true));
if (smallRT0 && smallRT0->asRenderTarget()) { if (smallRT0 && smallRT0->asRenderTarget()) {
smallRT0->asRenderTarget()->renderTargetPriv().attachStencilAttachment(); smallRT0->asRenderTarget()->renderTargetPriv().attachStencilAttachment();
} }
SkAutoTUnref<GrTexture> smallRT1(context->createTexture(smallDesc, true)); SkAutoTUnref<GrTexture> smallRT1(cache->createTexture(smallDesc, true));
if (smallRT1 && smallRT1->asRenderTarget()) { if (smallRT1 && smallRT1->asRenderTarget()) {
smallRT1->asRenderTarget()->renderTargetPriv().attachStencilAttachment(); smallRT1->asRenderTarget()->renderTargetPriv().attachStencilAttachment();
} }
@ -94,7 +95,7 @@ static void test_stencil_buffers(skiatest::Reporter* reporter, GrContext* contex
smallRT1->asRenderTarget()->renderTargetPriv().getStencilAttachment()); smallRT1->asRenderTarget()->renderTargetPriv().getStencilAttachment());
// An unbudgeted RT with the same desc should also share. // An unbudgeted RT with the same desc should also share.
SkAutoTUnref<GrTexture> smallRT2(context->createTexture(smallDesc, false)); SkAutoTUnref<GrTexture> smallRT2(cache->createTexture(smallDesc, false));
if (smallRT2 && smallRT2->asRenderTarget()) { if (smallRT2 && smallRT2->asRenderTarget()) {
smallRT2->asRenderTarget()->renderTargetPriv().attachStencilAttachment(); smallRT2->asRenderTarget()->renderTargetPriv().attachStencilAttachment();
} }
@ -111,7 +112,7 @@ static void test_stencil_buffers(skiatest::Reporter* reporter, GrContext* contex
bigDesc.fWidth = 400; bigDesc.fWidth = 400;
bigDesc.fHeight = 200; bigDesc.fHeight = 200;
bigDesc.fSampleCnt = 0; bigDesc.fSampleCnt = 0;
SkAutoTUnref<GrTexture> bigRT(context->createTexture(bigDesc, false)); SkAutoTUnref<GrTexture> bigRT(cache->createTexture(bigDesc, false));
if (bigRT && bigRT->asRenderTarget()) { if (bigRT && bigRT->asRenderTarget()) {
bigRT->asRenderTarget()->renderTargetPriv().attachStencilAttachment(); bigRT->asRenderTarget()->renderTargetPriv().attachStencilAttachment();
} }
@ -125,7 +126,7 @@ static void test_stencil_buffers(skiatest::Reporter* reporter, GrContext* contex
// An RT with a different sample count should not share. // An RT with a different sample count should not share.
GrSurfaceDesc smallMSAADesc = smallDesc; GrSurfaceDesc smallMSAADesc = smallDesc;
smallMSAADesc.fSampleCnt = 4; smallMSAADesc.fSampleCnt = 4;
SkAutoTUnref<GrTexture> smallMSAART0(context->createTexture(smallMSAADesc, false)); SkAutoTUnref<GrTexture> smallMSAART0(cache->createTexture(smallMSAADesc, false));
if (smallMSAART0 && smallMSAART0->asRenderTarget()) { if (smallMSAART0 && smallMSAART0->asRenderTarget()) {
smallMSAART0->asRenderTarget()->renderTargetPriv().attachStencilAttachment(); smallMSAART0->asRenderTarget()->renderTargetPriv().attachStencilAttachment();
} }
@ -141,7 +142,7 @@ static void test_stencil_buffers(skiatest::Reporter* reporter, GrContext* contex
smallRT0->asRenderTarget()->renderTargetPriv().getStencilAttachment() != smallRT0->asRenderTarget()->renderTargetPriv().getStencilAttachment() !=
smallMSAART0->asRenderTarget()->renderTargetPriv().getStencilAttachment()); smallMSAART0->asRenderTarget()->renderTargetPriv().getStencilAttachment());
// A second MSAA RT should share with the first MSAA RT. // A second MSAA RT should share with the first MSAA RT.
SkAutoTUnref<GrTexture> smallMSAART1(context->createTexture(smallMSAADesc, false)); SkAutoTUnref<GrTexture> smallMSAART1(cache->createTexture(smallMSAADesc, false));
if (smallMSAART1 && smallMSAART1->asRenderTarget()) { if (smallMSAART1 && smallMSAART1->asRenderTarget()) {
smallMSAART1->asRenderTarget()->renderTargetPriv().attachStencilAttachment(); smallMSAART1->asRenderTarget()->renderTargetPriv().attachStencilAttachment();
} }
@ -156,8 +157,8 @@ static void test_stencil_buffers(skiatest::Reporter* reporter, GrContext* contex
if (context->getMaxSampleCount() >= 8 && smallMSAART0 && smallMSAART0->asRenderTarget() && if (context->getMaxSampleCount() >= 8 && smallMSAART0 && smallMSAART0->asRenderTarget() &&
smallMSAART0->asRenderTarget()->numSamples() < 8) { smallMSAART0->asRenderTarget()->numSamples() < 8) {
smallMSAADesc.fSampleCnt = 8; smallMSAADesc.fSampleCnt = 8;
smallMSAART1.reset(context->createTexture(smallMSAADesc, false)); smallMSAART1.reset(cache->createTexture(smallMSAADesc, false));
SkAutoTUnref<GrTexture> smallMSAART1(context->createTexture(smallMSAADesc, false)); SkAutoTUnref<GrTexture> smallMSAART1(cache->createTexture(smallMSAADesc, false));
if (smallMSAART1 && smallMSAART1->asRenderTarget()) { if (smallMSAART1 && smallMSAART1->asRenderTarget()) {
smallMSAART1->asRenderTarget()->renderTargetPriv().attachStencilAttachment(); smallMSAART1->asRenderTarget()->renderTargetPriv().attachStencilAttachment();
} }

View File

@ -104,7 +104,7 @@ static void test_wrapped_texture_surface(skiatest::Reporter* reporter, GrContext
texDesc.fWidth = texDesc.fHeight = 100; texDesc.fWidth = texDesc.fHeight = 100;
texDesc.fSampleCnt = 0; texDesc.fSampleCnt = 0;
texDesc.fOrigin = kTopLeft_GrSurfaceOrigin; texDesc.fOrigin = kTopLeft_GrSurfaceOrigin;
SkAutoTUnref<GrSurface> dummySurface(ctx->createTexture(texDesc, false)); SkAutoTUnref<GrSurface> dummySurface(ctx->textureProvider()->createTexture(texDesc, false));
REPORTER_ASSERT(reporter, dummySurface && dummySurface->asTexture() && REPORTER_ASSERT(reporter, dummySurface && dummySurface->asTexture() &&
dummySurface->asRenderTarget()); dummySurface->asRenderTarget());

View File

@ -251,9 +251,8 @@ DEF_GPUTEST(TessellatingPathRendererTests, reporter, factory) {
desc.fHeight = 800; desc.fHeight = 800;
desc.fConfig = kSkia8888_GrPixelConfig; desc.fConfig = kSkia8888_GrPixelConfig;
desc.fOrigin = kTopLeft_GrSurfaceOrigin; desc.fOrigin = kTopLeft_GrSurfaceOrigin;
SkAutoTUnref<GrTexture> texture( SkAutoTUnref<GrTexture> texture(context->textureProvider()->refScratchTexture(desc,
context->refScratchTexture(desc, GrContext::kExact_ScratchTexMatch) GrTextureProvider::kExact_ScratchTexMatch));
);
GrTestTarget tt; GrTestTarget tt;
context->getTestTarget(&tt); context->getTestTarget(&tt);
GrRenderTarget* rt = texture->asRenderTarget(); GrRenderTarget* rt = texture->asRenderTarget();

View File

@ -319,7 +319,7 @@ static SkSurface* create_surface(const CanvasConfig& c, GrContext* grCtx) {
desc.fConfig = kSkia8888_GrPixelConfig; desc.fConfig = kSkia8888_GrPixelConfig;
desc.fOrigin = kGpu_TopLeft_DevType == c.fDevType ? desc.fOrigin = kGpu_TopLeft_DevType == c.fDevType ?
kTopLeft_GrSurfaceOrigin : kBottomLeft_GrSurfaceOrigin; kTopLeft_GrSurfaceOrigin : kBottomLeft_GrSurfaceOrigin;
SkAutoTUnref<GrTexture> texture(grCtx->createTexture(desc, false)); SkAutoTUnref<GrTexture> texture(grCtx->textureProvider()->createTexture(desc, false));
return SkSurface::NewRenderTargetDirect(texture->asRenderTarget()); return SkSurface::NewRenderTargetDirect(texture->asRenderTarget());
#endif #endif
} }

View File

@ -156,7 +156,7 @@ SkCanvas* PictureRenderer::setupCanvas(int width, int height) {
desc.fWidth = width; desc.fWidth = width;
desc.fHeight = height; desc.fHeight = height;
desc.fSampleCnt = fSampleCount; desc.fSampleCnt = fSampleCount;
target.reset(fGrContext->createTexture(desc, false, NULL, 0)); target.reset(fGrContext->textureProvider()->createTexture(desc, false, NULL, 0));
} }
uint32_t flags = fUseDFText ? SkSurfaceProps::kUseDistanceFieldFonts_Flag : 0; uint32_t flags = fUseDFText ? SkSurfaceProps::kUseDistanceFieldFonts_Flag : 0;