aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools/sk_pixel_iter.h
diff options
context:
space:
mode:
authorGravatar Mike Reed <reed@google.com>2018-01-30 10:12:22 -0500
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2018-01-30 15:56:35 +0000
commit63227ca63b09ad534b52b1b1957202ab18aa53f7 (patch)
treed806fb6ce3fc95d4c08595943239455279f1ff57 /tools/sk_pixel_iter.h
parentab2621d3e2d2055096b9fbebf16ee443e4ea90fb (diff)
handle clipping large triangles
originally found by fuzzer. Bug: skia: Change-Id: I45007a619f13936153c0db8a60b3631a2c9db20c Reviewed-on: https://skia-review.googlesource.com/101741 Reviewed-by: Cary Clark <caryclark@google.com> Commit-Queue: Mike Reed <reed@google.com>
Diffstat (limited to 'tools/sk_pixel_iter.h')
-rw-r--r--tools/sk_pixel_iter.h61
1 files changed, 61 insertions, 0 deletions
diff --git a/tools/sk_pixel_iter.h b/tools/sk_pixel_iter.h
new file mode 100644
index 0000000000..8bf5a55647
--- /dev/null
+++ b/tools/sk_pixel_iter.h
@@ -0,0 +1,61 @@
+/*
+ * Copyright 2018 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef sk_pixel_iter_DEFINED
+#define sk_pixel_iter_DEFINED
+
+#include "SkPixmap.h"
+#include "SkSurface.h"
+
+namespace sk_tool_utils {
+
+ class PixelIter {
+ public:
+ PixelIter();
+ PixelIter(SkSurface* surf) {
+ SkPixmap pm;
+ if (!surf->peekPixels(&pm)) {
+ pm.reset();
+ }
+ this->reset(pm);
+ }
+
+ void reset(const SkPixmap& pm) {
+ fPM = pm;
+ fLoc = { -1, 0 };
+ }
+
+ void* next(SkIPoint* loc = nullptr) {
+ if (!fPM.addr()) {
+ return nullptr;
+ }
+ fLoc.fX += 1;
+ if (fLoc.fX >= fPM.width()) {
+ fLoc.fX = 0;
+ if (++fLoc.fY >= fPM.height()) {
+ this->setDone();
+ return nullptr;
+ }
+ }
+ if (loc) {
+ *loc = fLoc;
+ }
+ return fPM.writable_addr(fLoc.fX, fLoc.fY);
+ }
+
+ void setDone() {
+ fPM.reset();
+ }
+
+ private:
+ SkPixmap fPM;
+ SkIPoint fLoc;
+ };
+
+} // namespace sk_tool_utils
+
+#endif // sk_tool_utils_DEFINED