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

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 8912851d8f369c88a9b36aeb7d281c8b2490c690..671924f46d91cfcd47a33183fa25261cfdb54555 100644
--- a/src/gpu/SkGpuDevice.cpp
+++ b/src/gpu/SkGpuDevice.cpp
@@ -43,6 +43,8 @@
#include "SkVertState.h"
#include "SkXfermode.h"
#include "SkErrorInternals.h"
+#include "SkImage_Base.h"
+#include "SkImagePriv.h"
#if SK_SUPPORT_GPU
@@ -93,6 +95,14 @@ public:
*texture = this->set(context, bitmap, params);
}
+ AutoBitmapTexture(GrContext* context,
+ 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) {
@@ -107,6 +117,20 @@ public:
}
}
+ GrTexture* set(GrContext* context,
+ 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;
};
@@ -695,11 +719,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);
}
};
@@ -1409,7 +1434,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<SkImage>& result, SkIPoint* offset) {
SkASSERT(filter);
// FIXME: plumb actual surface props such that we don't have to lie about the flags here
@@ -1420,7 +1445,8 @@ bool SkGpuDevice::filterTexture(GrContext* context, GrTexture* texture,
// Save the render target and set it to NULL, so we don't accidentally draw to it in the
// filter. Also set the clip wide open and the matrix to identity.
GrContext::AutoWideOpenIdentityDraw awo(context, NULL);
- return filter->filterImageGPU(&proxy, wrap_texture(texture), ctx, result, offset);
+ SkAutoTUnref<SkImage> src(wrap_texture(texture));
+ return filter->filterImageGPU(&proxy, *src, ctx, result, offset);
} else {
return false;
}
@@ -1445,7 +1471,7 @@ void SkGpuDevice::drawSprite(const SkDraw& draw, const SkBitmap& bitmap,
SkImageFilter* filter = paint.getImageFilter();
// This bitmap will own the filtered result as a texture.
- SkBitmap filteredBitmap;
+ SkAutoTUnref<SkImage> filteredImage;
if (filter) {
SkIPoint offset = SkIPoint::Make(0, 0);
@@ -1456,11 +1482,11 @@ void SkGpuDevice::drawSprite(const SkDraw& draw, const SkBitmap& bitmap,
// 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();
+ texture = filteredImage->getTexture();
+ w = filteredImage->width();
+ h = filteredImage->height();
left += offset.x();
top += offset.y();
} else {
@@ -1486,6 +1512,39 @@ void SkGpuDevice::drawSprite(const SkDraw& draw, const SkBitmap& bitmap,
SK_Scalar1 * h / texture->height()));
}
+void SkGpuDevice::drawImage(const SkDraw& draw, const SkImage& image,
+ int left, int top, const SkPaint& paint) {
+
+ GrTexture* texture = image.getTexture();
+ if (NULL == texture) {
+ INHERITED::drawImage(draw, image, left, top, paint);
+ return;
+ }
+
+ CHECK_SHOULD_DRAW(draw);
+ int w = image.width();
+ int h = image.height();
+
+ GrPaint grPaint;
+ grPaint.addColorTextureProcessor(texture, SkMatrix::I());
+
+ SkPaint2GrPaintNoShader(this->context(), paint, SkColor2GrColorJustAlpha(paint.getColor()),
+ false, &grPaint);
+
+ fContext->drawNonAARectToRect(grPaint,
+ SkMatrix::I(),
+ SkRect::MakeXYWH(SkIntToScalar(left),
+ SkIntToScalar(top),
+ SkIntToScalar(w),
+ SkIntToScalar(h)),
+ SkRect::MakeXYWH(0,
+ 0,
+ SK_Scalar1 * w / texture->width(),
+ SK_Scalar1 * h / texture->height()));
+
+}
+
+
void SkGpuDevice::drawBitmapRect(const SkDraw& origDraw, const SkBitmap& bitmap,
const SkRect* src, const SkRect& dst,
const SkPaint& paint,
@@ -1556,8 +1615,7 @@ void SkGpuDevice::drawDevice(const SkDraw& draw, SkBaseDevice* device,
int h = ii.height();
SkImageFilter* filter = paint.getImageFilter();
- // This bitmap will own the filtered result as a texture.
- SkBitmap filteredBitmap;
+ SkAutoTUnref<SkImage> filteredImage;
if (filter) {
SkIPoint offset = SkIPoint::Make(0, 0);
@@ -1568,11 +1626,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 {
@@ -1603,23 +1661,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, SkImage& src,
const SkImageFilter::Context& ctx,
- SkBitmap* result, SkIPoint* offset) {
+ SkAutoTUnref<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/SkImageFilter.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