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

Unified Diff: src/core/SkDeviceLooper.cpp

Issue 23392006: add SkDeviceLooper to handle larger-than-fixedpoint (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years, 4 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/core/SkDeviceLooper.cpp
diff --git a/src/core/SkDeviceLooper.cpp b/src/core/SkDeviceLooper.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..78702393312a9289fbe49e3aadb74a2b1ed7b46b
--- /dev/null
+++ b/src/core/SkDeviceLooper.cpp
@@ -0,0 +1,97 @@
+/*
+ * 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 "SkDeviceLooper.h"
+
+SkDeviceLooper::SkDeviceLooper(const SkBitmap& base,
+ const SkRasterClip& rc,
+ const SkIRect& bounds, bool aa)
+: fBaseBitmap(base)
+, fBaseRC(rc)
+, fDelta(aa ? kAA_Delta : kBW_Delta)
+{
+ SkIRect bitmapBounds = SkIRect::MakeWH(base.width(), base.height());
+ if (!fClippedBounds.intersect(bounds, bitmapBounds)) {
+ fState = kDone_State;
+ } else if (this->fitsInDelta(bounds)) {
+ fCurrBitmap = &fBaseBitmap;
+ fCurrRC = &fBaseRC;
+ fState = kSimple_State;
+ } else {
+ fCurrBitmap = &fSubsetBitmap;
+ fCurrRC = &fSubsetRC;
+ // back up by 1 DX, so that next() will put us in a correct starting
+ // position.
+ fCurrOffset.set(fClippedBounds.left() - fDelta,
+ fClippedBounds.top());
+ fState = kComplex_State;
+ }
+}
+
+SkDeviceLooper::~SkDeviceLooper() {
+}
+
+void SkDeviceLooper::mapRect(SkRect* dst, const SkRect& src) const {
+ SkASSERT(kDone_State != fState);
+ *dst = src;
+ dst->offset(SkIntToScalar(-fCurrOffset.fX),
+ SkIntToScalar(-fCurrOffset.fY));
+}
+
+void SkDeviceLooper::mapMatrix(SkMatrix* dst, const SkMatrix& src) const {
+ SkASSERT(kDone_State != fState);
+ *dst = src;
+ dst->postTranslate(SkIntToScalar(-fCurrOffset.fX),
+ SkIntToScalar(-fCurrOffset.fY));
+}
+
+bool SkDeviceLooper::computeCurrBitmapAndClip() {
+ SkASSERT(kComplex_State == fState);
+
+ SkIRect r = SkIRect::MakeXYWH(fCurrOffset.x(), fCurrOffset.y(),
+ fDelta, fDelta);
+ if (!fBaseBitmap.extractSubset(&fSubsetBitmap, r)) {
+ fState = kDone_State;
+ return false;
+ }
+ fSubsetBitmap.lockPixels();
+
+ fBaseRC.translate(-r.left(), -r.top(), &fSubsetRC);
+ (void)fSubsetRC.op(SkIRect::MakeWH(fDelta, fDelta), SkRegion::kIntersect_Op);
+ return true;
+}
+
+bool SkDeviceLooper::next() {
+ if (kDone_State == fState) {
+ return false;
+ }
+
+ if (kSimple_State == fState) {
+ fCurrBitmap = &fBaseBitmap;
+ fCurrRC = &fBaseRC;
+ fCurrOffset.set(0, 0);
+ fState = kDone_State;
+ return true;
+ }
+
+ SkASSERT(kComplex_State == fState);
+
+ // need to propogate fCurrOffset through clippedbounds
+ // left to right, until we wrap around and move down
+
+ if (fCurrOffset.x() + fDelta < fClippedBounds.right()) {
+ fCurrOffset.fX += fDelta;
+ return this->computeCurrBitmapAndClip();
+ }
+ fCurrOffset.fX = fClippedBounds.left();
+ if (fCurrOffset.y() + fDelta < fClippedBounds.bottom()) {
+ fCurrOffset.fY += fDelta;
+ return this->computeCurrBitmapAndClip();
+ }
+ fState = kDone_State;
+ return false;
+}

Powered by Google App Engine
This is Rietveld 408576698