aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--gyp/tests.gyp1
-rw-r--r--src/core/SkCanvas.cpp16
-rw-r--r--tests/QuickRejectTest.cpp80
3 files changed, 93 insertions, 4 deletions
diff --git a/gyp/tests.gyp b/gyp/tests.gyp
index 4d35312fa2..bb99c87a16 100644
--- a/gyp/tests.gyp
+++ b/gyp/tests.gyp
@@ -46,6 +46,7 @@
'../tests/PathTest.cpp',
'../tests/PDFPrimitivesTest.cpp',
'../tests/PointTest.cpp',
+ '../tests/QuickRejectTest.cpp',
'../tests/Reader32Test.cpp',
'../tests/ReadPixelsTest.cpp',
'../tests/RefDictTest.cpp',
diff --git a/src/core/SkCanvas.cpp b/src/core/SkCanvas.cpp
index cd835ace89..13ca462bd6 100644
--- a/src/core/SkCanvas.cpp
+++ b/src/core/SkCanvas.cpp
@@ -1313,7 +1313,7 @@ void SkCanvas::drawBitmap(const SkBitmap& bitmap, SkScalar x, SkScalar y,
const SkPaint* paint) {
SkDEBUGCODE(bitmap.validate();)
- if (NULL == paint || (paint->getMaskFilter() == NULL)) {
+ if (NULL == paint || paint->canComputeFastBounds()) {
SkRect fastBounds;
fastBounds.set(x, y,
x + SkIntToScalar(bitmap.width()),
@@ -1336,10 +1336,12 @@ void SkCanvas::internalDrawBitmapRect(const SkBitmap& bitmap, const SkIRect* src
}
// do this now, to avoid the cost of calling extract for RLE bitmaps
- if (this->quickReject(dst, paint2EdgeType(paint))) {
- return;
+ if (NULL == paint || paint->canComputeFastBounds()) {
+ if (this->quickReject(dst, paint2EdgeType(paint))) {
+ return;
+ }
}
-
+
const SkBitmap* bitmapPtr = &bitmap;
SkMatrix matrix;
@@ -1403,6 +1405,12 @@ void SkCanvas::commonDrawBitmap(const SkBitmap& bitmap, const SkIRect* srcRect,
void SkCanvas::internalDrawBitmapNine(const SkBitmap& bitmap,
const SkIRect& center, const SkRect& dst,
const SkPaint* paint) {
+ if (NULL == paint || paint->canComputeFastBounds()) {
+ if (this->quickReject(dst, paint2EdgeType(paint))) {
+ return;
+ }
+ }
+
const int32_t w = bitmap.width();
const int32_t h = bitmap.height();
diff --git a/tests/QuickRejectTest.cpp b/tests/QuickRejectTest.cpp
new file mode 100644
index 0000000000..8cde32785a
--- /dev/null
+++ b/tests/QuickRejectTest.cpp
@@ -0,0 +1,80 @@
+/*
+ * Copyright 2011 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "SkCanvas.h"
+#include "SkDrawLooper.h"
+#include "Test.h"
+
+/*
+ * Subclass of looper that just draws once, with an offset in X.
+ */
+class TestLooper : public SkDrawLooper {
+public:
+ bool fOnce;
+
+ virtual void init(SkCanvas*) SK_OVERRIDE {
+ fOnce = true;
+ }
+
+ virtual bool next(SkCanvas* canvas, SkPaint*) SK_OVERRIDE {
+ if (fOnce) {
+ fOnce = false;
+ canvas->translate(SkIntToScalar(10), 0);
+ return true;
+ }
+ return false;
+ }
+
+ virtual Factory getFactory() SK_OVERRIDE {
+ return NULL;
+ }
+};
+
+static void test_drawBitmap(skiatest::Reporter* reporter) {
+ SkBitmap src;
+ src.setConfig(SkBitmap::kARGB_8888_Config, 10, 10);
+ src.allocPixels();
+ src.eraseColor(SK_ColorWHITE);
+
+ SkBitmap dst;
+ dst.setConfig(SkBitmap::kARGB_8888_Config, 10, 10);
+ dst.allocPixels();
+ dst.eraseColor(0);
+
+ SkCanvas canvas(dst);
+ SkPaint paint;
+
+ // we are initially transparent
+ REPORTER_ASSERT(reporter, 0 == *dst.getAddr32(5, 5));
+
+ // we see the bitmap drawn
+ canvas.drawBitmap(src, 0, 0, &paint);
+ REPORTER_ASSERT(reporter, 0xFFFFFFFF == *dst.getAddr32(5, 5));
+
+ // reverify we are clear again
+ dst.eraseColor(0);
+ REPORTER_ASSERT(reporter, 0 == *dst.getAddr32(5, 5));
+
+ // if the bitmap is clipped out, we don't draw it
+ canvas.drawBitmap(src, SkIntToScalar(-10), 0, &paint);
+ REPORTER_ASSERT(reporter, 0 == *dst.getAddr32(5, 5));
+
+ // now install our looper, which will draw, since it internally translates
+ // to the left. The test is to ensure that canvas' quickReject machinary
+ // allows us through, even though sans-looper we would look like we should
+ // be clipped out.
+ paint.setLooper(new TestLooper)->unref();
+ canvas.drawBitmap(src, SkIntToScalar(-10), 0, &paint);
+ REPORTER_ASSERT(reporter, 0xFFFFFFFF == *dst.getAddr32(5, 5));
+}
+
+static void test(skiatest::Reporter* reporter) {
+ test_drawBitmap(reporter);
+}
+
+#include "TestClassDef.h"
+DEFINE_TESTCLASS("QuickReject", QuickRejectClass, test)