diff options
-rw-r--r-- | include/gpu/SkGpuDevice.h | 3 | ||||
-rw-r--r-- | include/gpu/SkGr.h | 46 | ||||
-rw-r--r-- | src/gpu/SkGpuDevice.cpp | 56 | ||||
-rw-r--r-- | src/gpu/SkGr.cpp | 44 | ||||
-rw-r--r-- | src/gpu/SkGrPixelRef.cpp | 2 |
5 files changed, 73 insertions, 78 deletions
diff --git a/include/gpu/SkGpuDevice.h b/include/gpu/SkGpuDevice.h index 2390cdb44c..2af11499ad 100644 --- a/include/gpu/SkGpuDevice.h +++ b/include/gpu/SkGpuDevice.h @@ -117,11 +117,8 @@ public: protected: typedef GrContext::TextureCacheEntry TexCache; - TexCache lockCachedTexture(const SkBitmap& bitmap, - const GrSamplerState* sampler); bool isBitmapInTextureCache(const SkBitmap& bitmap, const GrSamplerState& sampler) const; - void unlockCachedTexture(TexCache); // overrides from SkDevice virtual bool onReadPixels(const SkBitmap& bitmap, diff --git a/include/gpu/SkGr.h b/include/gpu/SkGr.h index 44a351eb74..975a1bad44 100644 --- a/include/gpu/SkGr.h +++ b/include/gpu/SkGr.h @@ -68,23 +68,28 @@ GR_STATIC_ASSERT((int)SkPath::kDone_Verb == (int)kEnd_PathCmd); #include "SkColorPriv.h" -class SkGr { -public: - /** - * Convert the SkBitmap::Config to the corresponding PixelConfig, or - * kUnknown_PixelConfig if the conversion cannot be done. - */ - static GrPixelConfig BitmapConfig2PixelConfig(SkBitmap::Config); - - static GrColor SkColor2GrColor(SkColor c) { - SkPMColor pm = SkPreMultiplyColor(c); - unsigned r = SkGetPackedR32(pm); - unsigned g = SkGetPackedG32(pm); - unsigned b = SkGetPackedB32(pm); - unsigned a = SkGetPackedA32(pm); - return GrColorPackRGBA(r, g, b, a); - } -}; +/** + * Convert the SkBitmap::Config to the corresponding PixelConfig, or + * kUnknown_PixelConfig if the conversion cannot be done. + */ +GrPixelConfig SkBitmapConfig2GrPixelConfig(SkBitmap::Config); + +static inline GrColor SkColor2GrColor(SkColor c) { + SkPMColor pm = SkPreMultiplyColor(c); + unsigned r = SkGetPackedR32(pm); + unsigned g = SkGetPackedG32(pm); + unsigned b = SkGetPackedB32(pm); + unsigned a = SkGetPackedA32(pm); + return GrColorPackRGBA(r, g, b, a); +} + +//////////////////////////////////////////////////////////////////////////////// + +GrContext::TextureCacheEntry GrLockCachedBitmapTexture(GrContext* ctx, + const SkBitmap& bitmap, + const GrSamplerState* sampler); + +void GrUnlockCachedBitmapTexture(GrContext* ctx, GrContext::TextureCacheEntry cache); //////////////////////////////////////////////////////////////////////////////// // Classes @@ -150,12 +155,5 @@ private: }; //////////////////////////////////////////////////////////////////////////////// -// Helper functions - -GrContext::TextureCacheEntry sk_gr_create_bitmap_texture(GrContext* ctx, - uint64_t key, - const GrSamplerState* sampler, - const SkBitmap& bitmap); - #endif diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp index ed5284812d..605b640197 100644 --- a/src/gpu/SkGpuDevice.cpp +++ b/src/gpu/SkGpuDevice.cpp @@ -93,7 +93,7 @@ public: ~SkAutoCachedTexture() { if (fTex.texture()) { - fDevice->unlockCachedTexture(fTex); + GrUnlockCachedBitmapTexture(fDevice->context(), fTex); } } @@ -101,7 +101,7 @@ public: const SkBitmap& bitmap, const GrSamplerState* sampler) { if (fTex.texture()) { - fDevice->unlockCachedTexture(fTex); + GrUnlockCachedBitmapTexture(fDevice->context(), fTex); } fDevice = device; GrTexture* texture = (GrTexture*)bitmap.getTexture(); @@ -110,7 +110,7 @@ public: fTex.reset(); } else { // look it up in our cache - fTex = device->lockCachedTexture(bitmap, sampler); + fTex = GrLockCachedBitmapTexture(device->context(), bitmap, sampler); texture = fTex.texture(); } return texture; @@ -238,7 +238,7 @@ SkGpuDevice::SkGpuDevice(GrContext* context, desc.fFlags = kRenderTarget_GrTextureFlagBit; desc.fWidth = width; desc.fHeight = height; - desc.fConfig = SkGr::BitmapConfig2PixelConfig(bm.config()); + desc.fConfig = SkBitmapConfig2GrPixelConfig(bm.config()); fTexture = fContext->createUncachedTexture(desc, NULL, 0); @@ -341,7 +341,7 @@ void SkGpuDevice::writePixels(const SkBitmap& bitmap, int x, int y, if (SkBitmap::kARGB_8888_Config == bitmap.config()) { config = config8888_to_gr_config(config8888); } else { - config= SkGr::BitmapConfig2PixelConfig(bitmap.config()); + config= SkBitmapConfig2GrPixelConfig(bitmap.config()); } fRenderTarget->writePixels(x, y, bitmap.width(), bitmap.height(), @@ -484,7 +484,7 @@ inline bool skPaint2GrPaintNoShader(SkGpuDevice* dev, // so constantColor should not also be true. GrAssert(!constantColor); } else { - grPaint->fColor = SkGr::SkColor2GrColor(skPaint.getColor()); + grPaint->fColor = SkColor2GrColor(skPaint.getColor()); grPaint->setTexture(kShaderTextureIdx, NULL); } SkColorFilter* colorFilter = skPaint.getColorFilter(); @@ -495,11 +495,11 @@ inline bool skPaint2GrPaintNoShader(SkGpuDevice* dev, if (colorFilter != NULL && colorFilter->asColorMode(&color, &filterMode)) { grPaint->fColorMatrixEnabled = false; if (!constantColor) { - grPaint->fColorFilterColor = SkGr::SkColor2GrColor(color); + grPaint->fColorFilterColor = SkColor2GrColor(color); grPaint->fColorFilterXfermode = filterMode; } else { SkColor filtered = colorFilter->filterColor(skPaint.getColor()); - grPaint->fColor = SkGr::SkColor2GrColor(filtered); + grPaint->fColor = SkColor2GrColor(filtered); grPaint->resetColorFilter(); } } else if (colorFilter != NULL && colorFilter->asColorMatrix(matrix)) { @@ -1738,7 +1738,7 @@ void SkGpuDevice::drawVertices(const SkDraw& draw, SkCanvas::VertexMode vmode, // need to convert byte order and from non-PM to PM convertedColors.reset(vertexCount); for (int i = 0; i < vertexCount; ++i) { - convertedColors[i] = SkGr::SkColor2GrColor(colors[i]); + convertedColors[i] = SkColor2GrColor(colors[i]); } colors = convertedColors.get(); } @@ -1902,42 +1902,6 @@ void SkGpuDevice::flush() { /////////////////////////////////////////////////////////////////////////////// -SkGpuDevice::TexCache SkGpuDevice::lockCachedTexture( - const SkBitmap& bitmap, - const GrSamplerState* sampler) { - GrContext::TextureCacheEntry entry; - GrContext* ctx = this->context(); - - if (!bitmap.isVolatile()) { - uint64_t key = bitmap.getGenerationID(); - key |= ((uint64_t) bitmap.pixelRefOffset()) << 32; - - GrTextureDesc desc; - desc.fWidth = bitmap.width(); - desc.fHeight = bitmap.height(); - desc.fConfig = SkGr::BitmapConfig2PixelConfig(bitmap.config()); - desc.fClientCacheID = key; - - entry = ctx->findAndLockTexture(desc, sampler); - if (NULL == entry.texture()) { - entry = sk_gr_create_bitmap_texture(ctx, key, sampler, - bitmap); - } - } else { - entry = sk_gr_create_bitmap_texture(ctx, kUncached_CacheID, - sampler, bitmap); - } - if (NULL == entry.texture()) { - GrPrintf("---- failed to create texture for cache [%d %d]\n", - bitmap.width(), bitmap.height()); - } - return entry; -} - -void SkGpuDevice::unlockCachedTexture(TexCache cache) { - this->context()->unlockTexture(cache); -} - bool SkGpuDevice::isBitmapInTextureCache(const SkBitmap& bitmap, const GrSamplerState& sampler) const { uint64_t key = bitmap.getGenerationID(); @@ -1946,7 +1910,7 @@ bool SkGpuDevice::isBitmapInTextureCache(const SkBitmap& bitmap, GrTextureDesc desc; desc.fWidth = bitmap.width(); desc.fHeight = bitmap.height(); - desc.fConfig = SkGr::BitmapConfig2PixelConfig(bitmap.config()); + desc.fConfig = SkBitmapConfig2GrPixelConfig(bitmap.config()); desc.fClientCacheID = key; return this->context()->isTextureInCache(desc, &sampler); diff --git a/src/gpu/SkGr.cpp b/src/gpu/SkGr.cpp index 6fc851a683..41f50f5cd3 100644 --- a/src/gpu/SkGr.cpp +++ b/src/gpu/SkGr.cpp @@ -56,7 +56,7 @@ static void build_compressed_data(void* buffer, const SkBitmap& bitmap) { //////////////////////////////////////////////////////////////////////////////// -GrContext::TextureCacheEntry sk_gr_create_bitmap_texture(GrContext* ctx, +static GrContext::TextureCacheEntry sk_gr_create_bitmap_texture(GrContext* ctx, uint64_t key, const GrSamplerState* sampler, const SkBitmap& origBitmap) { @@ -74,7 +74,7 @@ GrContext::TextureCacheEntry sk_gr_create_bitmap_texture(GrContext* ctx, GrTextureDesc desc; desc.fWidth = bitmap->width(); desc.fHeight = bitmap->height(); - desc.fConfig = SkGr::BitmapConfig2PixelConfig(bitmap->config()); + desc.fConfig = SkBitmapConfig2GrPixelConfig(bitmap->config()); desc.fClientCacheID = key; if (SkBitmap::kIndex8_Config == bitmap->config()) { @@ -110,7 +110,7 @@ GrContext::TextureCacheEntry sk_gr_create_bitmap_texture(GrContext* ctx, } } - desc.fConfig = SkGr::BitmapConfig2PixelConfig(bitmap->config()); + desc.fConfig = SkBitmapConfig2GrPixelConfig(bitmap->config()); if (kUncached_CacheID != key) { return ctx->createAndLockTexture(sampler, desc, bitmap->getPixels(), @@ -129,6 +129,42 @@ GrContext::TextureCacheEntry sk_gr_create_bitmap_texture(GrContext* ctx, /////////////////////////////////////////////////////////////////////////////// +GrContext::TextureCacheEntry GrLockCachedBitmapTexture(GrContext* ctx, + const SkBitmap& bitmap, const GrSamplerState* sampler) { + GrContext::TextureCacheEntry entry; + + if (!bitmap.isVolatile()) { + uint64_t key = bitmap.getGenerationID(); + key |= ((uint64_t) bitmap.pixelRefOffset()) << 32; + + GrTextureDesc desc; + desc.fWidth = bitmap.width(); + desc.fHeight = bitmap.height(); + desc.fConfig = SkBitmapConfig2GrPixelConfig(bitmap.config()); + desc.fClientCacheID = key; + + entry = ctx->findAndLockTexture(desc, sampler); + if (NULL == entry.texture()) { + entry = sk_gr_create_bitmap_texture(ctx, key, sampler, + bitmap); + } + } else { + entry = sk_gr_create_bitmap_texture(ctx, kUncached_CacheID, + sampler, bitmap); + } + if (NULL == entry.texture()) { + GrPrintf("---- failed to create texture for cache [%d %d]\n", + bitmap.width(), bitmap.height()); + } + return entry; +} + +void GrUnlockCachedBitmapTexture(GrContext* ctx, GrContext::TextureCacheEntry cache) { + ctx->unlockTexture(cache); +} + +/////////////////////////////////////////////////////////////////////////////// + void SkGrClipIterator::reset(const SkClipStack& clipStack) { fClipStack = &clipStack; fIter.reset(clipStack); @@ -192,7 +228,7 @@ GrPathFill SkGrClipIterator::getPathFill() const { /////////////////////////////////////////////////////////////////////////////// -GrPixelConfig SkGr::BitmapConfig2PixelConfig(SkBitmap::Config config) { +GrPixelConfig SkBitmapConfig2GrPixelConfig(SkBitmap::Config config) { switch (config) { case SkBitmap::kA8_Config: return kAlpha_8_GrPixelConfig; diff --git a/src/gpu/SkGrPixelRef.cpp b/src/gpu/SkGrPixelRef.cpp index 7e0e2cdceb..05c3f02c10 100644 --- a/src/gpu/SkGrPixelRef.cpp +++ b/src/gpu/SkGrPixelRef.cpp @@ -62,7 +62,7 @@ static SkGrPixelRef* copyToTexturePixelRef(GrTexture* texture, desc.fWidth = texture->width(); desc.fHeight = texture->height(); desc.fFlags = kRenderTarget_GrTextureFlagBit | kNoStencil_GrTextureFlagBit; - desc.fConfig = SkGr::BitmapConfig2PixelConfig(dstConfig); + desc.fConfig = SkBitmapConfig2GrPixelConfig(dstConfig); GrTexture* dst = context->createUncachedTexture(desc, NULL, 0); if (NULL == dst) { |