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

Unified Diff: src/effects/SkTileImageFilter.cpp

Issue 24157005: Moving 4 SkImageFilter derived classes from blink to skia (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Merged new filters into existing ones 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/SkTileImageFilter.cpp
diff --git a/src/effects/SkTileImageFilter.cpp b/src/effects/SkTileImageFilter.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..f2c586dca219a4ca2c3f294f6d52396a0b7e3515
--- /dev/null
+++ b/src/effects/SkTileImageFilter.cpp
@@ -0,0 +1,66 @@
+/*
+ * Copyright 2013 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "SkTileImageFilter.h"
+#include "SkBitmap.h"
+#include "SkCanvas.h"
+#include "SkDevice.h"
+#include "SkFlattenableBuffers.h"
+#include "SkMatrix.h"
+#include "SkPaint.h"
+#include "SkShader.h"
+
+bool SkTileImageFilter::onFilterImage(Proxy* proxy, const SkBitmap& src, const SkMatrix& ctm,
+ SkBitmap* dst, SkIPoint* offset) {
+ SkBitmap source = src;
+ SkImageFilter* input = getInput(0);
+ SkIPoint localOffset = SkIPoint::Make(0, 0);
+ if (input && !input->filterImage(proxy, src, ctm, &source, &localOffset)) {
+ return false;
+ }
+
+ int w = SkScalarTruncToInt(fDstRect.width());
+ int h = SkScalarTruncToInt(fDstRect.height());
+ if (!fSrcRect.width() || !fSrcRect.height() || !w || !h) {
+ return false;
+ }
+
+ SkIRect srcRect;
+ fSrcRect.roundOut(&srcRect);
+ SkBitmap subset;
+ if (!source.extractSubset(&subset, srcRect)) {
+ return false;
+ }
+
+ SkAutoTUnref<SkBaseDevice> device(proxy->createDevice(w, h));
+ SkIRect bounds;
+ source.getBounds(&bounds);
+ SkCanvas canvas(device);
+ SkPaint paint;
+ paint.setXfermodeMode(SkXfermode::kSrc_Mode);
+
+ SkAutoTUnref<SkShader> shader(SkShader::CreateBitmapShader(subset,
+ SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode));
+ paint.setShader(shader);
+ SkRect dstRect = fDstRect;
+ dstRect.offset(SkIntToScalar(localOffset.fX), SkIntToScalar(localOffset.fY));
+ canvas.drawRect(dstRect, paint);
+ *dst = device->accessBitmap(false);
+ return true;
+}
+
+SkTileImageFilter::SkTileImageFilter(SkFlattenableReadBuffer& buffer) : INHERITED(buffer) {
+ buffer.readRect(&fSrcRect);
+ buffer.readRect(&fDstRect);
+}
+
+void SkTileImageFilter::flatten(SkFlattenableWriteBuffer& buffer) const {
+ this->INHERITED::flatten(buffer);
+ buffer.writeRect(fSrcRect);
+ buffer.writeRect(fDstRect);
+}
+

Powered by Google App Engine
This is Rietveld 408576698