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

Unified Diff: src/gpu/SkGpuDevice.cpp

Issue 920513003: Make filters use SkImage instead of SkBitmap Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/gpu/SkGpuDevice.cpp
diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp
index 02ae84f729db5767d212e0522d3118212c6e6bd1..b03fd99a73b5d29434f56a822a3662bef4fa42d0 100644
--- a/src/gpu/SkGpuDevice.cpp
+++ b/src/gpu/SkGpuDevice.cpp
@@ -94,6 +94,14 @@ public:
*texture = this->set(context, bitmap, params);
}
+ AutoBitmapTexture(GrContext* context,
+ const SkImage* image,
+ const GrTextureParams* params,
+ GrTexture** texture) {
+ SkASSERT(texture);
+ *texture = this->set(context, image, params);
+ }
+
GrTexture* set(GrContext* context,
const SkBitmap& bitmap,
const GrTextureParams* params) {
@@ -108,6 +116,20 @@ public:
}
}
+ GrTexture* set(GrContext* context,
+ const SkImage* image,
+ const GrTextureParams* params) {
+ if (GrTexture* bmpTexture = image->getTexture()) {
+ fTexture.reset(NULL);
+ return bmpTexture;
+ } else {
+ SkBitmap bitmap;
+ as_IB(image)->getROPixels(&bitmap);
+ fTexture.reset(GrRefCachedBitmapTexture(context, bitmap, params));
+ return fTexture.get();
+ }
+ }
+
private:
SkAutoTUnref<GrTexture> fTexture;
};
@@ -813,11 +835,12 @@ GrTexture* create_mask_GPU(GrContext* context,
return mask;
}
-SkBitmap wrap_texture(GrTexture* texture) {
+static SkImage* wrap_texture(GrTexture* texture) {
SkBitmap result;
result.setInfo(texture->surfacePriv().info());
result.setPixelRef(SkNEW_ARGS(SkGrPixelRef, (result.info(), texture)))->unref();
- return result;
+ return SkNewImageFromBitmapTexture(result, texture->desc().fSampleCnt,
+ SkSurface::kYes_Budgeted);
}
};
@@ -1539,7 +1562,7 @@ void SkGpuDevice::internalDrawBitmap(const SkBitmap& bitmap,
bool SkGpuDevice::filterTexture(GrContext* context, GrTexture* texture,
const SkImageFilter* filter,
const SkImageFilter::Context& ctx,
- SkBitmap* result, SkIPoint* offset) {
+ SkAutoTUnref<const SkImage>& result, SkIPoint* offset) {
SkASSERT(filter);
// FIXME: plumb actual surface props such that we don't have to lie about the flags here
@@ -1549,7 +1572,8 @@ bool SkGpuDevice::filterTexture(GrContext* context, GrTexture* texture,
if (filter->canFilterImageGPU()) {
// Set the clip wide open and the matrix to identity.
GrContext::AutoWideOpenIdentityDraw awo(context);
- return filter->filterImageGPU(&proxy, wrap_texture(texture), ctx, result, offset);
+ SkAutoTUnref<const SkImage> src(wrap_texture(texture));
+ return filter->filterImageGPU(&proxy, src, ctx, result, offset);
} else {
return false;
}
@@ -1565,31 +1589,48 @@ void SkGpuDevice::drawSprite(const SkDraw& draw, const SkBitmap& bitmap,
return;
}
- int w = bitmap.width();
- int h = bitmap.height();
-
GrTexture* texture;
// draw sprite uses the default texture params
AutoBitmapTexture abt(fContext, bitmap, NULL, &texture);
+ if (NULL != texture) {
+ this->internalDrawSprite(draw, texture, left, top, bitmap.width(), bitmap.height(), paint);
+ }
+}
- SkImageFilter* filter = paint.getImageFilter();
- // This bitmap will own the filtered result as a texture.
- SkBitmap filteredBitmap;
+void SkGpuDevice::drawSprite(const SkDraw& draw, const SkImage& image,
+ int left, int top, const SkPaint& paint) {
+ // drawSprite is defined to be in device coords.
+ CHECK_SHOULD_DRAW(draw);
- if (filter) {
+ GrTexture* texture;
+ // draw sprite uses the default texture params
+ AutoBitmapTexture abt(fContext, &image, NULL, &texture);
+ if (NULL != texture) {
+ this->internalDrawSprite(draw, texture, left, top, image.width(), image.height(), paint);
+ }
+}
+
+void SkGpuDevice::internalDrawSprite(const SkDraw& draw, GrTexture* texture,
+ int left, int top, int width, int height,
+ const SkPaint& paint) {
+
+ SkAutoTUnref<GrTexture> src(SkRef(texture));
+ if (SkImageFilter* filter = paint.getImageFilter()) {
+ // This bitmap will own the filtered result as a texture.
+ SkAutoTUnref<const SkImage> filteredImage;
SkIPoint offset = SkIPoint::Make(0, 0);
SkMatrix matrix(*draw.fMatrix);
matrix.postTranslate(SkIntToScalar(-left), SkIntToScalar(-top));
- SkIRect clipBounds = SkIRect::MakeWH(bitmap.width(), bitmap.height());
+ SkIRect clipBounds = SkIRect::MakeWH(width, height);
SkAutoTUnref<SkImageFilter::Cache> cache(getImageFilterCache());
// This cache is transient, and is freed (along with all its contained
// textures) when it goes out of scope.
SkImageFilter::Context ctx(matrix, clipBounds, cache);
- if (this->filterTexture(fContext, texture, filter, ctx, &filteredBitmap,
+ if (this->filterTexture(fContext, texture, filter, ctx, filteredImage,
&offset)) {
- texture = (GrTexture*) filteredBitmap.getTexture();
- w = filteredBitmap.width();
- h = filteredBitmap.height();
+ src.reset(SkRef(filteredImage->getTexture()));
+ width = filteredImage->width();
+ height = filteredImage->height();
left += offset.x();
top += offset.y();
} else {
@@ -1598,7 +1639,7 @@ void SkGpuDevice::drawSprite(const SkDraw& draw, const SkBitmap& bitmap,
}
GrPaint grPaint;
- grPaint.addColorTextureProcessor(texture, SkMatrix::I());
+ grPaint.addColorTextureProcessor(src, SkMatrix::I());
SkPaint2GrPaintNoShader(this->context(), fRenderTarget, paint,
SkColor2GrColorJustAlpha(paint.getColor()), false, &grPaint);
@@ -1608,12 +1649,12 @@ void SkGpuDevice::drawSprite(const SkDraw& draw, const SkBitmap& bitmap,
SkMatrix::I(),
SkRect::MakeXYWH(SkIntToScalar(left),
SkIntToScalar(top),
- SkIntToScalar(w),
- SkIntToScalar(h)),
+ SkIntToScalar(width),
+ SkIntToScalar(height)),
SkRect::MakeXYWH(0,
0,
- SK_Scalar1 * w / texture->width(),
- SK_Scalar1 * h / texture->height()));
+ SK_Scalar1 * width / src->width(),
+ SK_Scalar1 * height / src->height()));
}
void SkGpuDevice::drawBitmapRect(const SkDraw& origDraw, const SkBitmap& bitmap,
@@ -1682,8 +1723,7 @@ void SkGpuDevice::drawDevice(const SkDraw& draw, SkBaseDevice* device,
int h = devImage->height();
SkImageFilter* filter = paint.getImageFilter();
- // This bitmap will own the filtered result as a texture.
- SkBitmap filteredBitmap;
+ SkAutoTUnref<const SkImage> filteredImage;
if (filter) {
SkIPoint offset = SkIPoint::Make(0, 0);
@@ -1694,11 +1734,11 @@ void SkGpuDevice::drawDevice(const SkDraw& draw, SkBaseDevice* device,
// textures) when it goes out of scope.
SkAutoTUnref<SkImageFilter::Cache> cache(getImageFilterCache());
SkImageFilter::Context ctx(matrix, clipBounds, cache);
- if (this->filterTexture(fContext, devTex, filter, ctx, &filteredBitmap,
+ if (this->filterTexture(fContext, devTex, filter, ctx, filteredImage,
&offset)) {
- devTex = filteredBitmap.getTexture();
- w = filteredBitmap.width();
- h = filteredBitmap.height();
+ devTex = filteredImage->getTexture();
+ w = filteredImage->width();
+ h = filteredImage->height();
x += offset.fX;
y += offset.fY;
} else {
@@ -1731,23 +1771,24 @@ bool SkGpuDevice::canHandleImageFilter(const SkImageFilter* filter) {
return filter->canFilterImageGPU();
}
-bool SkGpuDevice::filterImage(const SkImageFilter* filter, const SkBitmap& src,
+bool SkGpuDevice::filterImage(const SkImageFilter* filter, const SkImage* src,
const SkImageFilter::Context& ctx,
- SkBitmap* result, SkIPoint* offset) {
+ SkAutoTUnref<const SkImage>& result, SkIPoint* offset) {
// want explicitly our impl, so guard against a subclass of us overriding it
if (!this->SkGpuDevice::canHandleImageFilter(filter)) {
return false;
}
- SkAutoLockPixels alp(src, !src.getTexture());
- if (!src.getTexture() && !src.readyToDraw()) {
- return false;
- }
+ //TODO: SkAutoLockPixels alp(src, !src.getTexture());
+ //TODO: if !src->readyToDraw()
GrTexture* texture;
// We assume here that the filter will not attempt to tile the src. Otherwise, this cache lookup
// must be pushed upstack.
AutoBitmapTexture abt(fContext, src, NULL, &texture);
+ if (!texture) {
+ return false;
+ }
return this->filterTexture(fContext, texture, filter, ctx, result, offset);
}
« include/core/SkDevice.h ('K') | « src/gpu/SkGpuDevice.h ('k') | src/image/SkImage.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698