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

Unified Diff: cc/playback/image_hijack_canvas_unittest.cc

Issue 2572783005: ImageHijackCanvas should skip non-lazy images from SkImageShader (Closed)
Patch Set: Created 4 years 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 | « cc/playback/image_hijack_canvas.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cc/playback/image_hijack_canvas_unittest.cc
diff --git a/cc/playback/image_hijack_canvas_unittest.cc b/cc/playback/image_hijack_canvas_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..214de879b8535e56f1d88be9c4f6da9c86c58772
--- /dev/null
+++ b/cc/playback/image_hijack_canvas_unittest.cc
@@ -0,0 +1,65 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+#include "cc/playback/image_hijack_canvas.h"
+
+#include "cc/tiles/image_decode_cache.h"
+#include "testing/gmock/include/gmock/gmock.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "third_party/skia/include/core/SkBitmap.h"
+#include "third_party/skia/include/core/SkImage.h"
+#include "third_party/skia/include/core/SkPath.h"
+
+namespace cc {
+namespace {
+
+class MockImageDecodeCache : public ImageDecodeCache {
+ public:
+ MOCK_METHOD3(GetTaskForImageAndRef,
+ bool(const DrawImage& image,
+ const TracingInfo& tracing_info,
+ scoped_refptr<TileTask>* task));
+ MOCK_METHOD1(UnrefImage, void(const DrawImage& image));
+ MOCK_METHOD1(GetDecodedImageForDraw,
+ DecodedDrawImage(const DrawImage& image));
+ MOCK_METHOD2(DrawWithImageFinished,
+ void(const DrawImage& image,
+ const DecodedDrawImage& decoded_image));
+ MOCK_METHOD0(ReduceCacheUsage, void());
+ MOCK_METHOD1(SetShouldAggressivelyFreeResources,
+ void(bool aggressively_free_resources));
+};
+
+TEST(ImageHijackCanvasTest, NonLazyImagesSkipped) {
+ // Use a strict mock so that if *any* ImageDecodeCache methods are called, we
+ // will hit an error.
+ testing::StrictMock<MockImageDecodeCache> image_decode_cache;
+ ImageHijackCanvas canvas(100, 100, &image_decode_cache);
+
+ // Use an SkBitmap backed image to ensure that the image is not
+ // lazy-generated.
+ SkBitmap bitmap;
+ bitmap.allocN32Pixels(10, 10, true);
+ sk_sp<SkImage> image = SkImage::MakeFromBitmap(bitmap);
+
+ SkPaint paint;
+ canvas.drawImage(image, 0, 0, &paint);
+ canvas.drawImageRect(image, SkRect::MakeXYWH(0, 0, 10, 10),
+ SkRect::MakeXYWH(10, 10, 10, 10), &paint);
+
+ SkPaint image_paint;
+ image_paint.setShader(
+ image->makeShader(SkShader::kClamp_TileMode, SkShader::kClamp_TileMode));
+ SkRect paint_rect = SkRect::MakeXYWH(0, 0, 100, 100);
+ canvas.drawRect(paint_rect, image_paint);
+ SkPath path;
+ path.addRect(paint_rect, SkPath::kCW_Direction);
+ canvas.drawPath(path, image_paint);
+ canvas.drawOval(paint_rect, image_paint);
+ canvas.drawArc(paint_rect, 0, 40, true, image_paint);
+ canvas.drawRRect(SkRRect::MakeRect(paint_rect), image_paint);
+}
+
+} // namespace
+
+} // namespace cc
« no previous file with comments | « cc/playback/image_hijack_canvas.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698