aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar reed <reed@google.com>2016-07-19 14:33:20 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2016-07-19 14:33:20 -0700
commite51c356ae4e074b9c286c50a4efce11205f7463c (patch)
tree5955b6697e9db747ba502c04aeacd1e621aad627
parenta3f3caccdfa6e5e044cc1c76e256e55b8a6004ad (diff)
pre-land special methods on device
-rw-r--r--include/core/SkBitmapDevice.h7
-rw-r--r--include/core/SkDevice.h2
-rw-r--r--src/core/SkBitmapDevice.cpp50
-rw-r--r--src/core/SkDevice.cpp22
-rw-r--r--src/gpu/SkGpuDevice.cpp5
-rw-r--r--src/gpu/SkGpuDevice.h2
-rw-r--r--src/pdf/SkPDFDevice.cpp49
-rw-r--r--src/pdf/SkPDFDevice.h5
8 files changed, 122 insertions, 20 deletions
diff --git a/include/core/SkBitmapDevice.h b/include/core/SkBitmapDevice.h
index f8cc5bec7a..b62a88b47f 100644
--- a/include/core/SkBitmapDevice.h
+++ b/include/core/SkBitmapDevice.h
@@ -122,6 +122,13 @@ protected:
virtual void drawDevice(const SkDraw&, SkBaseDevice*, int x, int y, const SkPaint&) override;
///////////////////////////////////////////////////////////////////////////
+
+ void drawSpecial(const SkDraw&, SkSpecialImage*, int x, int y, const SkPaint&) override;
+ sk_sp<SkSpecialImage> makeSpecial(const SkBitmap&) override;
+ sk_sp<SkSpecialImage> makeSpecial(const SkImage*) override;
+ sk_sp<SkSpecialImage> snapSpecial() override;
+
+ ///////////////////////////////////////////////////////////////////////////
/** Update as needed the pixel value in the bitmap, so that the caller can
access the pixels directly. Note: only the pixels field should be
diff --git a/include/core/SkDevice.h b/include/core/SkDevice.h
index 864f71225f..827897c20e 100644
--- a/include/core/SkDevice.h
+++ b/include/core/SkDevice.h
@@ -279,7 +279,7 @@ protected:
virtual void drawSpecial(const SkDraw&, SkSpecialImage*, int x, int y, const SkPaint&);
virtual sk_sp<SkSpecialImage> makeSpecial(const SkBitmap&);
- virtual sk_sp<SkSpecialImage> makeSpecial(SkImage*);
+ virtual sk_sp<SkSpecialImage> makeSpecial(const SkImage*);
virtual sk_sp<SkSpecialImage> snapSpecial();
bool readPixels(const SkImageInfo&, void* dst, size_t rowBytes, int x, int y);
diff --git a/src/core/SkBitmapDevice.cpp b/src/core/SkBitmapDevice.cpp
index 119a434cc9..433bd66c62 100644
--- a/src/core/SkBitmapDevice.cpp
+++ b/src/core/SkBitmapDevice.cpp
@@ -8,6 +8,7 @@
#include "SkBitmapDevice.h"
#include "SkConfig8888.h"
#include "SkDraw.h"
+#include "SkImageFilter.h"
#include "SkImageFilterCache.h"
#include "SkMallocPixelRef.h"
#include "SkMatrix.h"
@@ -15,7 +16,9 @@
#include "SkPath.h"
#include "SkPixelRef.h"
#include "SkPixmap.h"
+#include "SkRasterClip.h"
#include "SkShader.h"
+#include "SkSpecialImage.h"
#include "SkSurface.h"
#include "SkXfermode.h"
@@ -364,6 +367,53 @@ void SkBitmapDevice::drawDevice(const SkDraw& draw, SkBaseDevice* device,
draw.drawSprite(static_cast<SkBitmapDevice*>(device)->fBitmap, x, y, paint);
}
+///////////////////////////////////////////////////////////////////////////////
+
+void SkBitmapDevice::drawSpecial(const SkDraw& draw, SkSpecialImage* srcImg, int x, int y,
+ const SkPaint& paint) {
+ SkASSERT(!srcImg->isTextureBacked());
+
+ SkBitmap resultBM;
+
+ SkImageFilter* filter = paint.getImageFilter();
+ if (filter) {
+ SkIPoint offset = SkIPoint::Make(0, 0);
+ SkMatrix matrix = *draw.fMatrix;
+ matrix.postTranslate(SkIntToScalar(-x), SkIntToScalar(-y));
+ const SkIRect clipBounds = draw.fRC->getBounds().makeOffset(-x, -y);
+ SkAutoTUnref<SkImageFilterCache> cache(this->getImageFilterCache());
+ SkImageFilter::Context ctx(matrix, clipBounds, cache.get());
+
+ sk_sp<SkSpecialImage> resultImg(filter->filterImage(srcImg, ctx, &offset));
+ if (resultImg) {
+ SkPaint tmpUnfiltered(paint);
+ tmpUnfiltered.setImageFilter(nullptr);
+ if (resultImg->getROPixels(&resultBM)) {
+ this->drawSprite(draw, resultBM, x + offset.x(), y + offset.y(), tmpUnfiltered);
+ }
+ }
+ } else {
+ if (srcImg->getROPixels(&resultBM)) {
+ this->drawSprite(draw, resultBM, x, y, paint);
+ }
+ }
+}
+
+sk_sp<SkSpecialImage> SkBitmapDevice::makeSpecial(const SkBitmap& bitmap) {
+ return SkSpecialImage::MakeFromRaster(bitmap.bounds(), bitmap);
+}
+
+sk_sp<SkSpecialImage> SkBitmapDevice::makeSpecial(const SkImage* image) {
+ return SkSpecialImage::MakeFromImage(SkIRect::MakeWH(image->width(), image->height()),
+ image->makeNonTextureImage());
+}
+
+sk_sp<SkSpecialImage> SkBitmapDevice::snapSpecial() {
+ return this->makeSpecial(fBitmap);
+}
+
+///////////////////////////////////////////////////////////////////////////////
+
sk_sp<SkSurface> SkBitmapDevice::makeSurface(const SkImageInfo& info, const SkSurfaceProps& props) {
return SkSurface::MakeRaster(info, &props);
}
diff --git a/src/core/SkDevice.cpp b/src/core/SkDevice.cpp
index 7ecdbef095..f54fba2ba7 100644
--- a/src/core/SkDevice.cpp
+++ b/src/core/SkDevice.cpp
@@ -23,21 +23,6 @@
#include "SkTextBlobRunIterator.h"
#include "SkTextToPathIter.h"
-void SkBaseDevice::drawSpecial(const SkDraw&, SkSpecialImage*, int x, int y, const SkPaint&) {
-}
-
-sk_sp<SkSpecialImage> SkBaseDevice::makeSpecial(const SkBitmap&) {
- return nullptr;
-}
-
-sk_sp<SkSpecialImage> SkBaseDevice::makeSpecial(SkImage*) {
- return nullptr;
-}
-
-sk_sp<SkSpecialImage> SkBaseDevice::snapSpecial() {
- return nullptr;
-}
-
SkBaseDevice::SkBaseDevice(const SkSurfaceProps& surfaceProps)
: fSurfaceProps(surfaceProps)
#ifdef SK_DEBUG
@@ -236,6 +221,13 @@ void SkBaseDevice::drawAtlas(const SkDraw& draw, const SkImage* atlas, const SkR
///////////////////////////////////////////////////////////////////////////////////////////////////
+void SkBaseDevice::drawSpecial(const SkDraw&, SkSpecialImage*, int x, int y, const SkPaint&) {}
+sk_sp<SkSpecialImage> SkBaseDevice::makeSpecial(const SkBitmap&) { return nullptr; }
+sk_sp<SkSpecialImage> SkBaseDevice::makeSpecial(const SkImage*) { return nullptr; }
+sk_sp<SkSpecialImage> SkBaseDevice::snapSpecial() { return nullptr; }
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
bool SkBaseDevice::readPixels(const SkImageInfo& info, void* dstP, size_t rowBytes, int x, int y) {
#ifdef SK_DEBUG
SkASSERT(info.width() > 0 && info.height() > 0);
diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp
index 23f5798c1a..8ce4b30ff7 100644
--- a/src/gpu/SkGpuDevice.cpp
+++ b/src/gpu/SkGpuDevice.cpp
@@ -1426,7 +1426,7 @@ sk_sp<SkSpecialImage> SkGpuDevice::makeSpecial(const SkBitmap& bitmap) {
&this->surfaceProps());
}
-sk_sp<SkSpecialImage> SkGpuDevice::makeSpecial(SkImage* image) {
+sk_sp<SkSpecialImage> SkGpuDevice::makeSpecial(const SkImage* image) {
SkPixmap pm;
if (image->isTextureBacked()) {
GrTexture* texture = as_IB(image)->peekTexture();
@@ -1457,8 +1457,7 @@ sk_sp<SkSpecialImage> SkGpuDevice::snapSpecial() {
return nullptr;
}
- if (!fContext->copySurface(this->accessDrawContext()->accessRenderTarget(),
- texture.get())) {
+ if (!fContext->copySurface(texture.get(), this->accessDrawContext()->accessRenderTarget())){
return nullptr;
}
}
diff --git a/src/gpu/SkGpuDevice.h b/src/gpu/SkGpuDevice.h
index 85764467cb..8fec082ffd 100644
--- a/src/gpu/SkGpuDevice.h
+++ b/src/gpu/SkGpuDevice.h
@@ -134,7 +134,7 @@ public:
void drawSpecial(const SkDraw&, SkSpecialImage*,
int left, int top, const SkPaint& paint) override;
sk_sp<SkSpecialImage> makeSpecial(const SkBitmap&) override;
- sk_sp<SkSpecialImage> makeSpecial(SkImage*) override;
+ sk_sp<SkSpecialImage> makeSpecial(const SkImage*) override;
sk_sp<SkSpecialImage> snapSpecial() override;
void flush() override;
diff --git a/src/pdf/SkPDFDevice.cpp b/src/pdf/SkPDFDevice.cpp
index 01e8c82526..ff2806a672 100644
--- a/src/pdf/SkPDFDevice.cpp
+++ b/src/pdf/SkPDFDevice.cpp
@@ -2216,3 +2216,52 @@ void SkPDFDevice::internalDrawImage(const SkMatrix& origMatrix,
SkPDFUtils::DrawFormXObject(this->addXObjectResource(pdfimage.get()),
&content.entry()->fContent);
}
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+#include "SkSpecialImage.h"
+#include "SkImageFilter.h"
+
+void SkPDFDevice::drawSpecial(const SkDraw& draw, SkSpecialImage* srcImg, int x, int y,
+ const SkPaint& paint) {
+ SkASSERT(!srcImg->isTextureBacked());
+
+ SkBitmap resultBM;
+
+ SkImageFilter* filter = paint.getImageFilter();
+ if (filter) {
+ SkIPoint offset = SkIPoint::Make(0, 0);
+ SkMatrix matrix = *draw.fMatrix;
+ matrix.postTranslate(SkIntToScalar(-x), SkIntToScalar(-y));
+ const SkIRect clipBounds = draw.fRC->getBounds().makeOffset(-x, -y);
+// SkAutoTUnref<SkImageFilterCache> cache(this->getImageFilterCache());
+ SkImageFilter::Context ctx(matrix, clipBounds, nullptr /*cache.get()*/);
+
+ sk_sp<SkSpecialImage> resultImg(filter->filterImage(srcImg, ctx, &offset));
+ if (resultImg) {
+ SkPaint tmpUnfiltered(paint);
+ tmpUnfiltered.setImageFilter(nullptr);
+ if (resultImg->getROPixels(&resultBM)) {
+ this->drawSprite(draw, resultBM, x + offset.x(), y + offset.y(), tmpUnfiltered);
+ }
+ }
+ } else {
+ if (srcImg->getROPixels(&resultBM)) {
+ this->drawSprite(draw, resultBM, x, y, paint);
+ }
+ }
+}
+
+sk_sp<SkSpecialImage> SkPDFDevice::makeSpecial(const SkBitmap& bitmap) {
+ return SkSpecialImage::MakeFromRaster(bitmap.bounds(), bitmap);
+}
+
+sk_sp<SkSpecialImage> SkPDFDevice::makeSpecial(const SkImage* image) {
+ return SkSpecialImage::MakeFromImage(SkIRect::MakeWH(image->width(), image->height()),
+ image->makeNonTextureImage());
+}
+
+sk_sp<SkSpecialImage> SkPDFDevice::snapSpecial() {
+ SkASSERT(false);
+ return nullptr;
+}
diff --git a/src/pdf/SkPDFDevice.h b/src/pdf/SkPDFDevice.h
index 7c7ddf43cb..ca78663347 100644
--- a/src/pdf/SkPDFDevice.h
+++ b/src/pdf/SkPDFDevice.h
@@ -201,6 +201,11 @@ protected:
void drawAnnotation(const SkDraw&, const SkRect&, const char key[], SkData* value) override;
+ void drawSpecial(const SkDraw&, SkSpecialImage*, int x, int y, const SkPaint&) override;
+ sk_sp<SkSpecialImage> makeSpecial(const SkBitmap&) override;
+ sk_sp<SkSpecialImage> makeSpecial(const SkImage*) override;
+ sk_sp<SkSpecialImage> snapSpecial() override;
+
private:
struct RectWithData {
SkRect rect;