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

Unified Diff: third_party/WebKit/Source/platform/graphics/ImageBufferSurface.cpp

Issue 1331533002: [poc] curve-filter Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Fix CanvasRenderingContext2D::createPattern crash for #40 Created 4 years, 11 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: third_party/WebKit/Source/platform/graphics/ImageBufferSurface.cpp
diff --git a/third_party/WebKit/Source/platform/graphics/ImageBufferSurface.cpp b/third_party/WebKit/Source/platform/graphics/ImageBufferSurface.cpp
index 9bf60796d027bd4089bce72b1922b06ad77deb16..a5d67b7c2b0c4f5e7ca2a4ae1127bb2ea4d1e1aa 100644
--- a/third_party/WebKit/Source/platform/graphics/ImageBufferSurface.cpp
+++ b/third_party/WebKit/Source/platform/graphics/ImageBufferSurface.cpp
@@ -33,6 +33,7 @@
#include "platform/graphics/GraphicsContext.h"
#include "platform/graphics/ImageBuffer.h"
#include "platform/graphics/StaticBitmapImage.h"
+#include "third_party/skia/include/core/SkColorFilter.h"
#include "third_party/skia/include/core/SkImage.h"
class SkPicture;
@@ -60,7 +61,7 @@ void ImageBufferSurface::clear()
// color. Can we have another way to manage this?
if (isValid()) {
if (m_opacityMode == Opaque) {
- canvas()->clear(SK_ColorBLACK);
+ canvas()->clear(SK_ColorBLACK); // FIXME: not color correct.
} else {
canvas()->clear(SK_ColorTRANSPARENT);
}
@@ -68,12 +69,31 @@ void ImageBufferSurface::clear()
}
}
-void ImageBufferSurface::draw(GraphicsContext& context, const FloatRect& destRect, const FloatRect& srcRect, SkXfermode::Mode op)
+void ImageBufferSurface::draw(GraphicsContext& context, const FloatRect& destRect, const FloatRect& srcRect, SkXfermode::Mode op, SkColorFilter* transform)
{
RefPtr<SkImage> snapshot = newImageSnapshot(PreferNoAcceleration);
if (!snapshot)
return;
+ if (!transform) {
+ RefPtr<Image> image = StaticBitmapImage::create(snapshot.release());
+ context.drawImage(image.get(), destRect, srcRect, op);
+ return;
+ }
+
+ SkPaint transformPaint;
+ transformPaint.setColorFilter(transform);
+ transformPaint.setXfermodeMode(SkXfermode::kSrc_Mode);
+
+ SkPictureRecorder recorder;
+ FloatRect sourceRect = IntRect(0, 0, width(), height());
+ SkCanvas* canvas = recorder.beginRecording(sourceRect);
+ canvas->drawImage(snapshot.get(), 0, 0, &transformPaint);
+ RefPtr<SkPicture> recorded = adoptRef(recorder.endRecordingAsPicture());
+
+ SkISize size = SkISize::Make(width(), height());
+ snapshot = adoptRef(SkImage::NewFromPicture(recorded.get(), size, nullptr, nullptr));
+
RefPtr<Image> image = StaticBitmapImage::create(snapshot.release());
context.drawImage(image.get(), destRect, srcRect, op);
}

Powered by Google App Engine
This is Rietveld 408576698