typedef uint64_t TextureKey;
/**
+ * Create a new entry, based on the specified key and texture, and return
+ * its "locked" entry. Must call be balanced with an unlockTexture() call.
+ *
+ * @param key A client-generated key that identifies the contents
+ * of the texture. Respecified to findAndLockTexture
+ * for subsequent uses of the texture.
+ * @param sampler The sampler state used to draw a texture may be used
+ * to determine how to store the pixel data in the texture
+ * cache. (e.g. different versions may exist for different
+ * wrap modes on GPUs with limited or no NPOT texture
+ * support). Only the wrap and filter fields are used. NULL
+ * implies clamp wrap modes and nearest filtering.
+ * @param desc Description of the texture properties.
+ * @param srcData Pointer to the pixel values.
+ * @param rowBytes The number of bytes between rows of the texture. Zero
+ * implies tightly packed rows.
+ */
+ TextureCacheEntry createAndLockTexture(TextureKey key,
+ const GrSamplerState* sampler,
+ const GrTextureDesc& desc,
+ void* srcData, size_t rowBytes);
+
+ /**
* Search for an entry based on key and dimensions. If found, "lock" it and
* return it. The entry's texture() function will return NULL if not found.
- * Must call be balanced with an unlockTexture() call.
+ * Must be balanced with an unlockTexture() call.
+ *
+ * @param key A client-generated key that identifies the contents
+ * of the texture.
+ * @param width The width of the texture in pixels as specifed in
+ * the GrTextureDesc originally passed to
+ * createAndLockTexture
+ * @param width The height of the texture in pixels as specifed in
+ * the GrTextureDesc originally passed to
+ * createAndLockTexture
+ * @param sampler The sampler state used to draw a texture may be used
+ * to determine the cache entry used. (e.g. different
+ * versions may exist for different wrap modes on GPUs with
+ * limited or no NPOT texture support). Only the wrap and
+ * filter fields are used. NULL implies clamp wrap modes
+ * and nearest filtering.
*/
TextureCacheEntry findAndLockTexture(TextureKey key,
int width,
int height,
- const GrSamplerState&);
+ const GrSamplerState* sampler);
/**
* Determines whether a texture is in the cache. If the texture is found it
* will not be locked or returned. This call does not affect the priority of
bool isTextureInCache(TextureKey key,
int width,
int height,
- const GrSamplerState&) const;
-
- /**
- * Create a new entry, based on the specified key and texture, and return
- * its "locked" entry. Must call be balanced with an unlockTexture() call.
- */
- TextureCacheEntry createAndLockTexture(TextureKey key,
- const GrSamplerState&,
- const GrTextureDesc&,
- void* srcData, size_t rowBytes);
+ const GrSamplerState*) const;
/**
* Enum that determines how closely a returned scratch texture must match
/**
* Returns true if the specified use of an indexed texture is supported.
*/
- bool supportsIndex8PixelConfig(const GrSamplerState&,
+ bool supportsIndex8PixelConfig(const GrSamplerState*,
int width,
int height) const;
}
}
- static const GrSamplerState& ClampNearest() { return gClampNearest; }
-
private:
WrapMode fWrapX : 8;
WrapMode fWrapY : 8;
uint8_t fKernelWidth;
float fImageIncrement[2];
float fKernel[MAX_KERNEL_WIDTH];
-
- static const GrSamplerState gClampNearest;
};
#endif
kSaveLayerDeviceRenderTarget_TexType
};
TexCache lockCachedTexture(const SkBitmap& bitmap,
- const GrSamplerState& sampler,
+ const GrSamplerState* sampler,
TexType type = kBitmap_TexType);
bool isBitmapInTextureCache(const SkBitmap& bitmap,
const GrSamplerState& sampler) const;
SkAutoCachedTexture();
SkAutoCachedTexture(SkGpuDevice* device,
const SkBitmap& bitmap,
- const GrSamplerState& sampler,
+ const GrSamplerState* sampler,
GrTexture** texture);
~SkAutoCachedTexture();
- GrTexture* set(SkGpuDevice*, const SkBitmap&, const GrSamplerState&);
+ GrTexture* set(SkGpuDevice*, const SkBitmap&, const GrSamplerState*);
private:
SkGpuDevice* fDevice;
static const GrContext::TextureKey gUNCACHED_KEY = ~0;
GrContext::TextureCacheEntry sk_gr_create_bitmap_texture(GrContext* ctx,
GrContext::TextureKey key,
- const GrSamplerState& sampler,
+ const GrSamplerState* sampler,
const SkBitmap& bitmap);
*/
+#include "GrContext.h"
+
#include "GrBufferAllocPool.h"
#include "GrClipIterator.h"
-#include "GrContext.h"
#include "GrGpu.h"
#include "GrIndexBuffer.h"
#include "GrInOrderDrawBuffer.h"
namespace {
// returns true if this is a "special" texture because of gpu NPOT limitations
bool gen_texture_key_values(const GrGpu* gpu,
- const GrSamplerState& sampler,
+ const GrSamplerState* sampler,
GrContext::TextureKey clientKey,
int width,
int height,
if (!gpu->getCaps().fNPOTTextureTileSupport) {
bool isPow2 = GrIsPow2(width) && GrIsPow2(height);
- bool tiled = (sampler.getWrapX() != GrSamplerState::kClamp_WrapMode) ||
- (sampler.getWrapY() != GrSamplerState::kClamp_WrapMode);
+ bool tiled = NULL != sampler &&
+ ((sampler->getWrapX() != GrSamplerState::kClamp_WrapMode) ||
+ (sampler->getWrapY() != GrSamplerState::kClamp_WrapMode));
if (tiled && !isPow2) {
v[3] |= kNPOTBit;
- if (GrSamplerState::kNearest_Filter != sampler.getFilter()) {
+ if (GrSamplerState::kNearest_Filter != sampler->getFilter()) {
v[3] |= kFilterBit;
}
}
}
}
-GrContext::TextureCacheEntry GrContext::findAndLockTexture(TextureKey key,
- int width,
- int height,
- const GrSamplerState& sampler) {
+GrContext::TextureCacheEntry GrContext::findAndLockTexture(
+ TextureKey key,
+ int width,
+ int height,
+ const GrSamplerState* sampler) {
uint32_t v[4];
gen_texture_key_values(fGpu, sampler, key, width, height, false, v);
GrResourceKey resourceKey(v);
bool GrContext::isTextureInCache(TextureKey key,
int width,
int height,
- const GrSamplerState& sampler) const {
+ const GrSamplerState* sampler) const {
uint32_t v[4];
gen_texture_key_values(fGpu, sampler, key, width, height, false, v);
GrResourceKey resourceKey(v);
}
}
-GrContext::TextureCacheEntry GrContext::createAndLockTexture(TextureKey key,
- const GrSamplerState& sampler,
- const GrTextureDesc& desc,
- void* srcData, size_t rowBytes) {
+GrContext::TextureCacheEntry GrContext::createAndLockTexture(
+ TextureKey key,
+ const GrSamplerState* sampler,
+ const GrTextureDesc& desc,
+ void* srcData,
+ size_t rowBytes) {
SK_TRACE_EVENT0("GrContext::createAndLockTexture");
#if GR_DUMP_TEXTURE_UPLOAD
GrResourceKey resourceKey(v);
if (special) {
- TextureCacheEntry clampEntry =
- findAndLockTexture(key, desc.fWidth, desc.fHeight,
- GrSamplerState::ClampNearest());
+ GrAssert(NULL != sampler);
+ TextureCacheEntry clampEntry = this->findAndLockTexture(key,
+ desc.fWidth,
+ desc.fHeight,
+ NULL);
if (NULL == clampEntry.texture()) {
- clampEntry = createAndLockTexture(key,
- GrSamplerState::ClampNearest(),
- desc, srcData, rowBytes);
+ clampEntry = this->createAndLockTexture(key, NULL, desc,
+ srcData, rowBytes);
GrAssert(NULL != clampEntry.texture());
if (NULL == clampEntry.texture()) {
return entry;
// if filtering is not desired then we want to ensure all
// texels in the resampled image are copies of texels from
// the original.
- if (GrSamplerState::kNearest_Filter == sampler.getFilter()) {
+ if (GrSamplerState::kNearest_Filter == sampler->getFilter()) {
filter = GrSamplerState::kNearest_Filter;
} else {
filter = GrSamplerState::kBilinear_Filter;
((uint64_t) desc.fConfig << 32);
// this code path isn't friendly to tiling with NPOT restricitons
// We just pass ClampNoFilter()
- gen_texture_key_values(gpu, GrSamplerState::ClampNearest(), descKey,
- desc.fWidth, desc.fHeight, true, v);
+ gen_texture_key_values(gpu, NULL, descKey, desc.fWidth,
+ desc.fHeight, true, v);
}
}
///////////////////////////////////////////////////////////////////////////////
-bool GrContext::supportsIndex8PixelConfig(const GrSamplerState& sampler,
+bool GrContext::supportsIndex8PixelConfig(const GrSamplerState* sampler,
int width, int height) const {
const GrDrawTarget::Caps& caps = fGpu->getCaps();
if (!caps.f8BitPaletteSupport) {
bool isPow2 = GrIsPow2(width) && GrIsPow2(height);
if (!isPow2) {
- bool tiled = sampler.getWrapX() != GrSamplerState::kClamp_WrapMode ||
- sampler.getWrapY() != GrSamplerState::kClamp_WrapMode;
+ bool tiled = NULL != sampler &&
+ (sampler->getWrapX() != GrSamplerState::kClamp_WrapMode ||
+ sampler->getWrapY() != GrSamplerState::kClamp_WrapMode);
if (tiled && !caps.fNPOTTextureTileSupport) {
return false;
}
}
}
-////////////////////////////////////////////////////////////////////////////////
-
-const GrSamplerState GrSamplerState::gClampNearest;
SkGpuDevice::SkAutoCachedTexture::
SkAutoCachedTexture(SkGpuDevice* device,
const SkBitmap& bitmap,
- const GrSamplerState& sampler,
+ const GrSamplerState* sampler,
GrTexture** texture) {
GrAssert(texture);
*texture = this->set(device, bitmap, sampler);
GrTexture* SkGpuDevice::SkAutoCachedTexture::set(SkGpuDevice* device,
const SkBitmap& bitmap,
- const GrSamplerState& sampler) {
+ const GrSamplerState* sampler) {
if (fTex.texture()) {
fDevice->unlockCachedTexture(fTex);
}
TexType type = (kSaveLayer_Usage == usage) ?
kSaveLayerDeviceRenderTarget_TexType :
kDeviceRenderTarget_TexType;
- fCache = this->lockCachedTexture(bm, GrSamplerState::ClampNearest(), type);
+ fCache = this->lockCachedTexture(bm, NULL, type);
fTexture = fCache.texture();
if (fTexture) {
SkASSERT(NULL != fTexture->asRenderTarget());
twoPointParams[2] < 0);
}
- GrTexture* texture = act->set(this, bitmap, *sampler);
+ GrTexture* texture = act->set(this, bitmap, sampler);
if (NULL == texture) {
SkDebugf("Couldn't convert bitmap to texture.\n");
return false;
sampler->setMatrix(GrMatrix::I());
GrTexture* texture;
- SkAutoCachedTexture act(this, bitmap, *sampler, &texture);
+ SkAutoCachedTexture act(this, bitmap, sampler, &texture);
if (NULL == texture) {
return;
}
GrTexture* texture;
sampler->reset();
- SkAutoCachedTexture act(this, bitmap, *sampler, &texture);
+ SkAutoCachedTexture act(this, bitmap, sampler, &texture);
grPaint.setTexture(kBitmapTextureIdx, texture);
///////////////////////////////////////////////////////////////////////////////
SkGpuDevice::TexCache SkGpuDevice::lockCachedTexture(const SkBitmap& bitmap,
- const GrSamplerState& sampler,
+ const GrSamplerState* sampler,
TexType type) {
GrContext::TextureCacheEntry entry;
GrContext* ctx = this->context();
entry = ctx->findAndLockTexture(key, bitmap.width(),
bitmap.height(), sampler);
if (NULL == entry.texture()) {
- entry = sk_gr_create_bitmap_texture(ctx, key, sampler,
+ entry = sk_gr_create_bitmap_texture(ctx, key, sampler,
bitmap);
}
} else {
- entry = sk_gr_create_bitmap_texture(ctx, gUNCACHED_KEY, sampler, bitmap);
+ entry = sk_gr_create_bitmap_texture(ctx, gUNCACHED_KEY,
+ sampler, bitmap);
}
if (NULL == entry.texture()) {
GrPrintf("---- failed to create texture for cache [%d %d]\n",
GrContext::TextureKey key = bitmap.getGenerationID();
key |= ((uint64_t) bitmap.pixelRefOffset()) << 32;
return this->context()->isTextureInCache(key, bitmap.width(),
- bitmap.height(), sampler);
+ bitmap.height(), &sampler);
}
GrContext::TextureCacheEntry sk_gr_create_bitmap_texture(GrContext* ctx,
GrContext::TextureKey key,
- const GrSamplerState& sampler,
+ const GrSamplerState* sampler,
const SkBitmap& origBitmap) {
SkAutoLockPixels alp(origBitmap);
GrContext::TextureCacheEntry entry;