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

Unified Diff: Source/platform/graphics/GraphicsContextTest.cpp

Issue 907453003: Move overdraw tracking code from GraphicsContext to CanvasRenderingContext2D (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: fix test copypasta Created 5 years, 10 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
« no previous file with comments | « Source/platform/graphics/GraphicsContextState.cpp ('k') | Source/platform/graphics/ImageBuffer.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/platform/graphics/GraphicsContextTest.cpp
diff --git a/Source/platform/graphics/GraphicsContextTest.cpp b/Source/platform/graphics/GraphicsContextTest.cpp
index a3bd177875dcfd912d32d302d05858b35fd01486..26fe2d45709974e0a6237b025729e83eac51ccf4 100644
--- a/Source/platform/graphics/GraphicsContextTest.cpp
+++ b/Source/platform/graphics/GraphicsContextTest.cpp
@@ -27,7 +27,6 @@
#include "platform/graphics/GraphicsContext.h"
#include "platform/graphics/BitmapImage.h"
-#include "platform/graphics/GraphicsContextClient.h"
#include "platform/graphics/ImageBuffer.h"
#include "platform/graphics/skia/NativeImageSkia.h"
#include "third_party/skia/include/core/SkBitmap.h"
@@ -169,232 +168,6 @@ TEST(GraphicsContextTest, trackImageMaskWithOpaqueRect)
EXPECT_OPAQUE_PIXELS_ONLY_IN_RECT(bitmap, IntRect(12, 12, 3, 3));
}
-#define TEST_CLEAR_SETUP \
- SkBitmap bitmap; \
- bitmap.allocN32Pixels(10, 10); \
- bitmap.eraseColor(0); \
- SkCanvas canvas(bitmap); \
- TestGraphicsContextClient gcClient; \
- GraphicsContext context(&canvas, nullptr); \
- context.setClient(&gcClient);
-
-#define TEST_CLEAR_1(SHOULD_CLEAR, CALL1) \
- do { \
- TEST_CLEAR_SETUP \
- context.CALL1; \
- EXPECT_TRUE((SHOULD_CLEAR == gcClient.didClear())); \
- } while (0)
-
-#define TEST_CLEAR_2(SHOULD_CLEAR, CALL1, CALL2) \
- do { \
- TEST_CLEAR_SETUP \
- context.CALL1; \
- context.CALL2; \
- EXPECT_TRUE((SHOULD_CLEAR == gcClient.didClear())); \
- } while (0)
-
-#define TEST_CLEAR_3(SHOULD_CLEAR, CALL1, CALL2, CALL3) \
- do { \
- TEST_CLEAR_SETUP \
- context.CALL1; \
- context.CALL2; \
- context.CALL3; \
- EXPECT_TRUE((SHOULD_CLEAR == gcClient.didClear())); \
- } while (0)
-
-class TestGraphicsContextClient : public blink::GraphicsContextClient {
-public:
- TestGraphicsContextClient() : m_didClear(false) { }
- bool didClear() { return m_didClear; }
-
-protected:
- virtual void willOverwriteCanvas() { m_didClear = true; }
-
-private:
- bool m_didClear;
-};
-
-enum BitmapOpacity {
- OpaqueBitmap,
- TransparentBitmap
-};
-
-static SkBitmap createTestBitmap(BitmapOpacity opacity)
-{
- SkBitmap bitmap;
- SkColor color = opacity == OpaqueBitmap ? SK_ColorWHITE : SK_ColorTRANSPARENT;
- bitmap.allocN32Pixels(10, 10, opacity == OpaqueBitmap);
- for (int y = 0; y < bitmap.height(); ++y)
- for (int x = 0; x < bitmap.width(); ++x)
- *bitmap.getAddr32(x, y) = color;
- return bitmap;
-}
-
-TEST(GraphicsContextTest, detectClear)
-{
- SkRect fullRect = SkRect::MakeWH(10, 10);
- SkPaint opaquePaint;
- SkPaint alphaPaint;
- alphaPaint.setAlpha(0x7F);
- SkRect partialRect = SkRect::MakeWH(1, 1);
- SkImageInfo opaqueImageInfo = SkImageInfo::MakeN32(10, 10, kOpaque_SkAlphaType);
- SkImageInfo alphaImageInfo = SkImageInfo::MakeN32(10, 10, kPremul_SkAlphaType);
- SkImageInfo smallImageInfo = SkImageInfo::MakeN32(1, 1, kOpaque_SkAlphaType);
-
- SkBitmap opaqueBitmap = createTestBitmap(OpaqueBitmap);
- SkBitmap alphaBitmap = createTestBitmap(TransparentBitmap);
-
- SkAutoLockPixels alp(opaqueBitmap);
- const void* imageData = opaqueBitmap.getAddr32(0, 0);
- size_t imageRowBytes = opaqueBitmap.rowBytes();
-
- // Test drawRect
- TEST_CLEAR_1(true, drawRect(fullRect, opaquePaint));
- TEST_CLEAR_1(false, drawRect(fullRect, alphaPaint));
- TEST_CLEAR_1(false, drawRect(partialRect, opaquePaint));
- TEST_CLEAR_2(false, translate(1, 1), drawRect(fullRect, opaquePaint));
-
- // Test drawBitmap
- TEST_CLEAR_1(true, drawBitmap(opaqueBitmap, 0, 0, 0));
- TEST_CLEAR_1(true, drawBitmap(opaqueBitmap, 0, 0, &opaquePaint));
- TEST_CLEAR_1(true, drawBitmap(opaqueBitmap, 0, 0, &alphaPaint));
- TEST_CLEAR_1(false, drawBitmap(alphaBitmap, 0, 0, &opaquePaint));
- TEST_CLEAR_1(false, drawBitmap(alphaBitmap, 0, 0, &alphaPaint));
- TEST_CLEAR_1(false, drawBitmap(opaqueBitmap, 1, 0, 0));
- TEST_CLEAR_2(true, translate(-1, 0), drawBitmap(opaqueBitmap, 1, 0, 0));
- TEST_CLEAR_1(true, drawBitmapRect(opaqueBitmap, 0, fullRect, 0));
- TEST_CLEAR_1(true, drawBitmapRect(opaqueBitmap, &partialRect, fullRect, 0));
- TEST_CLEAR_1(false, drawBitmapRect(opaqueBitmap, 0, partialRect, 0));
- TEST_CLEAR_2(true, scale(10, 10), drawBitmapRect(opaqueBitmap, 0, partialRect, 0));
-
- // Test writePixels
- TEST_CLEAR_1(true, writePixels(opaqueImageInfo, imageData, imageRowBytes, 0, 0));
- TEST_CLEAR_1(true, writePixels(alphaImageInfo, imageData, imageRowBytes, 0, 0)); // alpha has no effect
- TEST_CLEAR_1(false, writePixels(smallImageInfo, imageData, imageRowBytes, 0, 0));
- TEST_CLEAR_2(true, translate(1, 1), writePixels(opaqueImageInfo, imageData, imageRowBytes, 0, 0)); // ignores tranforms
- TEST_CLEAR_1(false, writePixels(opaqueImageInfo, imageData, imageRowBytes, 1, 0));
-
- // Test clipping
- TEST_CLEAR_2(false, clipRect(partialRect), drawRect(fullRect, opaquePaint));
-}
-
-TEST(GraphicsContextTest, detectClearWithOpaquePaint)
-{
- // This test ensures that a draw that covers the canvas is detected as a clear
- // if its paint is opaque.
-
- SkRect fullRect = SkRect::MakeWH(10, 10);
-
- SkBitmap opaqueBitmap = createTestBitmap(OpaqueBitmap);
- SkBitmap alphaBitmap = createTestBitmap(TransparentBitmap);
-
- SkAutoTUnref<SkShader> opaqueShader(SkShader::CreateBitmapShader(opaqueBitmap, SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode));
-
- {
- SkPaint paint;
- paint.setStyle(SkPaint::kFill_Style);
- TEST_CLEAR_1(true, drawRect(fullRect, paint));
- }
- {
- SkPaint paint;
- paint.setStyle(SkPaint::kStrokeAndFill_Style);
- TEST_CLEAR_1(true, drawRect(fullRect, paint));
- }
- {
- SkPaint paint;
- paint.setShader(opaqueShader);
- TEST_CLEAR_1(true, drawRect(fullRect, paint));
- }
- {
- SkPaint paint;
- paint.setAlpha(0x7F); // shader overrides color
- paint.setShader(opaqueShader);
- TEST_CLEAR_1(true, drawRect(fullRect, paint));
- }
- {
- SkPaint paint;
- paint.setShader(opaqueShader); // shader overrides the bitmap
- TEST_CLEAR_1(true, drawBitmap(alphaBitmap, 0, 0, &paint));
- }
- {
- SkPaint paint;
- paint.setAlpha(0); // bitmap overrides color
- TEST_CLEAR_1(true, drawBitmap(opaqueBitmap, 0, 0, &paint));
- }
- {
- SkPaint paint;
- paint.setAlpha(0x7F);
- paint.setXfermodeMode(SkXfermode::kSrc_Mode);
- TEST_CLEAR_1(true, drawRect(fullRect, paint));
- }
- {
- SkPaint paint;
- paint.setAlpha(0x7F);
- paint.setXfermodeMode(SkXfermode::kClear_Mode);
- TEST_CLEAR_1(true, drawRect(fullRect, paint));
- }
-}
-
-TEST(GraphicsContextTest, detectNoClearWithTransparentPaint)
-{
- // This test ensures that a draw that covers the canvas is never detected as a clear
- // if its paint has any properties that make it non-opaque
- SkRect fullRect = SkRect::MakeWH(10, 10);
-
- SkBitmap opaqueBitmap = createTestBitmap(OpaqueBitmap);
- SkBitmap alphaBitmap = createTestBitmap(TransparentBitmap);
-
- SkAutoTUnref<SkShader> alphaShader(SkShader::CreateBitmapShader(alphaBitmap, SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode));
-
- {
- SkPaint paint;
- paint.setStyle(SkPaint::kStroke_Style);
- TEST_CLEAR_1(false, drawRect(fullRect, paint));
- }
- {
- SkPaint paint;
- paint.setColor(SK_ColorTRANSPARENT);
- TEST_CLEAR_1(false, drawRect(fullRect, paint));
- }
- {
- SkPaint paint;
- paint.setShader(alphaShader);
- TEST_CLEAR_1(false, drawRect(fullRect, paint));
- }
- {
- SkPaint paint;
- paint.setShader(alphaShader); // shader overrides the bitmap.
- TEST_CLEAR_1(false, drawBitmap(opaqueBitmap, 0, 0, &paint));
- }
- for (int mode = SkXfermode::kDstOver_Mode; mode <= SkXfermode::kLastMode; mode++) {
- SkPaint paint;
- paint.setXfermodeMode(static_cast<SkXfermode::Mode>(mode));
- TEST_CLEAR_1(false, drawRect(fullRect, paint));
- }
- {
- SkPaint paint;
- SkAutoTUnref<SkMaskFilter> filter(SkBlurMaskFilter::Create(kNormal_SkBlurStyle, 1));
- paint.setMaskFilter(filter.get());
- TEST_CLEAR_1(false, drawRect(fullRect, paint));
- }
- {
- SkPaint paint;
- SkAutoTUnref<SkImageFilter> filter(SkBlurImageFilter::Create(1, 1));
- paint.setImageFilter(filter.get());
- TEST_CLEAR_1(false, drawRect(fullRect, paint));
- }
- {
- SkPaint paint;
- SkAutoTUnref<SkDrawLooper> looper(SkBlurDrawLooper::Create(SK_ColorWHITE, 1, 1, 1));
- paint.setLooper(looper.get());
- TEST_CLEAR_1(false, drawRect(fullRect, paint));
- }
- {
- SkPaint paint;
- TEST_CLEAR_3(false, beginLayer(1.0f, SkXfermode::kSrcOver_Mode), drawRect(fullRect, paint), endLayer());
- }
-}
-
TEST(GraphicsContextTest, UnboundedDrawsAreClipped)
{
SkBitmap bitmap;
« no previous file with comments | « Source/platform/graphics/GraphicsContextState.cpp ('k') | Source/platform/graphics/ImageBuffer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698