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

Unified Diff: src/effects/SkFloodImageFilter.cpp

Issue 24157005: Moving 4 SkImageFilter derived classes from blink to skia (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Merged offset filters together Created 7 years, 3 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/effects/SkFloodImageFilter.cpp
diff --git a/src/effects/SkFloodImageFilter.cpp b/src/effects/SkFloodImageFilter.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..59792218f2f57f33e6004771e074a32f3b9b25e4
--- /dev/null
+++ b/src/effects/SkFloodImageFilter.cpp
@@ -0,0 +1,47 @@
+/*
+ * Copyright 2013 The Android Open Source Project
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "SkFloodImageFilter.h"
+#include "SkBitmap.h"
+#include "SkCanvas.h"
+#include "SkDevice.h"
+#include "SkFlattenableBuffers.h"
+#include "SkMatrix.h"
+#include "SkPaint.h"
+
+SkFloodImageFilter::SkFloodImageFilter(SkFlattenableReadBuffer& buffer) : INHERITED(buffer) {
+ fColor = buffer.readColor();
+}
+
+void SkFloodImageFilter::flatten(SkFlattenableWriteBuffer& buffer) const {
+ this->INHERITED::flatten(buffer);
+ buffer.writeColor(fColor);
+}
+
+bool SkFloodImageFilter::onFilterImage(Proxy* proxy, const SkBitmap& src, const SkMatrix& ctm,
+ SkBitmap* result, SkIPoint* offset) {
+ if (!src.width() || !src.height()) {
+ return false;
+ }
+
+ SkIRect bounds;
+ src.getBounds(&bounds);
+ if (!applyCropRect(&bounds, ctm)) {
+ return false;
+ }
+
+ SkAutoTUnref<SkBaseDevice> device(proxy->createDevice(bounds.width(), bounds.height()));
+ SkCanvas canvas(device.get());
+ SkPaint paint;
+ paint.setColor(fColor);
+ canvas.drawRect(SkRect::MakeWH(SkIntToScalar(src.width()),
+ SkIntToScalar(src.height())), paint);
+ *result = device->accessBitmap(false);
+ offset->fX += bounds.left();
+ offset->fY += bounds.top();
+ return true;
+}

Powered by Google App Engine
This is Rietveld 408576698