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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « cc/playback/image_hijack_canvas.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 #include "cc/playback/image_hijack_canvas.h"
5
6 #include "cc/tiles/image_decode_cache.h"
7 #include "testing/gmock/include/gmock/gmock.h"
8 #include "testing/gtest/include/gtest/gtest.h"
9 #include "third_party/skia/include/core/SkBitmap.h"
10 #include "third_party/skia/include/core/SkImage.h"
11 #include "third_party/skia/include/core/SkPath.h"
12
13 namespace cc {
14 namespace {
15
16 class MockImageDecodeCache : public ImageDecodeCache {
17 public:
18 MOCK_METHOD3(GetTaskForImageAndRef,
19 bool(const DrawImage& image,
20 const TracingInfo& tracing_info,
21 scoped_refptr<TileTask>* task));
22 MOCK_METHOD1(UnrefImage, void(const DrawImage& image));
23 MOCK_METHOD1(GetDecodedImageForDraw,
24 DecodedDrawImage(const DrawImage& image));
25 MOCK_METHOD2(DrawWithImageFinished,
26 void(const DrawImage& image,
27 const DecodedDrawImage& decoded_image));
28 MOCK_METHOD0(ReduceCacheUsage, void());
29 MOCK_METHOD1(SetShouldAggressivelyFreeResources,
30 void(bool aggressively_free_resources));
31 };
32
33 TEST(ImageHijackCanvasTest, NonLazyImagesSkipped) {
34 // Use a strict mock so that if *any* ImageDecodeCache methods are called, we
35 // will hit an error.
36 testing::StrictMock<MockImageDecodeCache> image_decode_cache;
37 ImageHijackCanvas canvas(100, 100, &image_decode_cache);
38
39 // Use an SkBitmap backed image to ensure that the image is not
40 // lazy-generated.
41 SkBitmap bitmap;
42 bitmap.allocN32Pixels(10, 10, true);
43 sk_sp<SkImage> image = SkImage::MakeFromBitmap(bitmap);
44
45 SkPaint paint;
46 canvas.drawImage(image, 0, 0, &paint);
47 canvas.drawImageRect(image, SkRect::MakeXYWH(0, 0, 10, 10),
48 SkRect::MakeXYWH(10, 10, 10, 10), &paint);
49
50 SkPaint image_paint;
51 image_paint.setShader(
52 image->makeShader(SkShader::kClamp_TileMode, SkShader::kClamp_TileMode));
53 SkRect paint_rect = SkRect::MakeXYWH(0, 0, 100, 100);
54 canvas.drawRect(paint_rect, image_paint);
55 SkPath path;
56 path.addRect(paint_rect, SkPath::kCW_Direction);
57 canvas.drawPath(path, image_paint);
58 canvas.drawOval(paint_rect, image_paint);
59 canvas.drawArc(paint_rect, 0, 40, true, image_paint);
60 canvas.drawRRect(SkRRect::MakeRect(paint_rect), image_paint);
61 }
62
63 } // namespace
64
65 } // namespace cc
OLDNEW
« 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