OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "Resources.h" | 8 #include "Resources.h" |
9 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
10 #include "SkPipe.h" | 10 #include "SkPipe.h" |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 } | 42 } |
43 | 43 |
44 for (int y = 0; y < info.height(); ++y) { | 44 for (int y = 0; y < info.height(); ++y) { |
45 if (memcmp(pmapA.addr32(0, y), pmapB.addr32(0, y), info.width() * sizeof
(SkPMColor))) { | 45 if (memcmp(pmapA.addr32(0, y), pmapB.addr32(0, y), info.width() * sizeof
(SkPMColor))) { |
46 return false; | 46 return false; |
47 } | 47 } |
48 } | 48 } |
49 return true; | 49 return true; |
50 } | 50 } |
51 | 51 |
52 DEF_TEST(Pipe_image, reporter) { | 52 DEF_TEST(Pipe_image_draw_first, reporter) { |
53 sk_sp<SkImage> img = GetResourceAsImage("mandrill_128.png"); | 53 sk_sp<SkImage> img = GetResourceAsImage("mandrill_128.png"); |
54 SkASSERT(img.get()); | 54 SkASSERT(img.get()); |
55 | 55 |
56 SkPipeSerializer serializer; | 56 SkPipeSerializer serializer; |
57 SkPipeDeserializer deserializer; | 57 SkPipeDeserializer deserializer; |
58 | 58 |
59 SkDynamicMemoryWStream stream; | 59 SkDynamicMemoryWStream stream; |
60 SkCanvas* wc = serializer.beginWrite(SkRect::MakeWH(100, 100), &stream); | 60 SkCanvas* wc = serializer.beginWrite(SkRect::MakeWH(100, 100), &stream); |
61 wc->drawImage(img, 0, 0, nullptr); | 61 wc->drawImage(img, 0, 0, nullptr); |
62 serializer.endWrite(); | 62 serializer.endWrite(); |
(...skipping 16 matching lines...) Expand all Loading... |
79 auto img1 = drain_as_image(&deserializer, &stream); | 79 auto img1 = drain_as_image(&deserializer, &stream); |
80 REPORTER_ASSERT(reporter, deep_equal(img.get(), img1.get())); | 80 REPORTER_ASSERT(reporter, deep_equal(img.get(), img1.get())); |
81 | 81 |
82 // try serializing the same image directly (again), check that it is the sam
e! | 82 // try serializing the same image directly (again), check that it is the sam
e! |
83 serializer.write(img.get(), &stream); | 83 serializer.write(img.get(), &stream); |
84 size_t offset3 = stream.bytesWritten(); | 84 size_t offset3 = stream.bytesWritten(); |
85 REPORTER_ASSERT(reporter, offset3 <= 32); | 85 REPORTER_ASSERT(reporter, offset3 <= 32); |
86 auto img2 = drain_as_image(&deserializer, &stream); | 86 auto img2 = drain_as_image(&deserializer, &stream); |
87 REPORTER_ASSERT(reporter, img1.get() == img2.get()); | 87 REPORTER_ASSERT(reporter, img1.get() == img2.get()); |
88 } | 88 } |
| 89 |
| 90 DEF_TEST(Pipe_image_draw_second, reporter) { |
| 91 sk_sp<SkImage> img = GetResourceAsImage("mandrill_128.png"); |
| 92 SkASSERT(img.get()); |
| 93 |
| 94 SkPipeSerializer serializer; |
| 95 SkPipeDeserializer deserializer; |
| 96 SkDynamicMemoryWStream stream; |
| 97 |
| 98 serializer.write(img.get(), &stream); |
| 99 size_t offset0 = stream.bytesWritten(); |
| 100 REPORTER_ASSERT(reporter, offset0 > 100); // the raw image must be sorta b
ig |
| 101 drain_as_image(&deserializer, &stream); |
| 102 |
| 103 // The 2nd image should be nice and small |
| 104 serializer.write(img.get(), &stream); |
| 105 size_t offset1 = stream.bytesWritten(); |
| 106 REPORTER_ASSERT(reporter, offset1 <= 32); |
| 107 drain_as_image(&deserializer, &stream); |
| 108 |
| 109 // Now try drawing the image, it should also be small |
| 110 SkCanvas* wc = serializer.beginWrite(SkRect::MakeWH(100, 100), &stream); |
| 111 wc->drawImage(img, 0, 0, nullptr); |
| 112 serializer.endWrite(); |
| 113 size_t offset2 = stream.bytesWritten(); |
| 114 REPORTER_ASSERT(reporter, offset2 <= 32); |
| 115 } |
OLD | NEW |