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

Side by Side Diff: tests/ImageTest.cpp

Issue 2199813002: make an image from a mutable bitmap (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: fixx mmy spilling Created 4 years, 4 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 unified diff | Download patch
« no previous file with comments | « src/image/SkImage_Raster.cpp ('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
1 /* 1 /*
2 * Copyright 2015 Google Inc. 2 * Copyright 2015 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 <functional> 8 #include <functional>
9 #include <initializer_list> 9 #include <initializer_list>
10 #include <vector> 10 #include <vector>
11 #include "DMGpuSupport.h" 11 #include "DMGpuSupport.h"
12 12
13 #include "SkAutoPixmapStorage.h" 13 #include "SkAutoPixmapStorage.h"
14 #include "SkBitmap.h" 14 #include "SkBitmap.h"
15 #include "SkCanvas.h" 15 #include "SkCanvas.h"
16 #include "SkData.h" 16 #include "SkData.h"
17 #include "SkImageEncoder.h" 17 #include "SkImageEncoder.h"
18 #include "SkImageGenerator.h" 18 #include "SkImageGenerator.h"
19 #include "SkImage_Base.h" 19 #include "SkImage_Base.h"
20 #include "SkImagePriv.h"
20 #include "SkPicture.h" 21 #include "SkPicture.h"
21 #include "SkPictureRecorder.h" 22 #include "SkPictureRecorder.h"
22 #include "SkPixelSerializer.h" 23 #include "SkPixelSerializer.h"
23 #include "SkRRect.h" 24 #include "SkRRect.h"
24 #include "SkStream.h" 25 #include "SkStream.h"
25 #include "SkSurface.h" 26 #include "SkSurface.h"
26 #include "SkUtils.h" 27 #include "SkUtils.h"
27 #include "Test.h" 28 #include "Test.h"
28 29
29 #if SK_SUPPORT_GPU 30 #if SK_SUPPORT_GPU
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 DEF_TEST(ImageEncode, reporter) { 188 DEF_TEST(ImageEncode, reporter) {
188 test_encode(reporter, create_image().get()); 189 test_encode(reporter, create_image().get());
189 } 190 }
190 191
191 #if SK_SUPPORT_GPU 192 #if SK_SUPPORT_GPU
192 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ImageEncode_Gpu, reporter, ctxInfo) { 193 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ImageEncode_Gpu, reporter, ctxInfo) {
193 test_encode(reporter, create_gpu_image(ctxInfo.grContext()).get()); 194 test_encode(reporter, create_gpu_image(ctxInfo.grContext()).get());
194 } 195 }
195 #endif 196 #endif
196 197
198 DEF_TEST(Image_MakeFromRasterBitmap, reporter) {
199 const struct {
200 ForceCopyMode fMode;
201 bool fExpectSameAsMutable;
202 bool fExpectSameAsImmutable;
203 } recs[] = {
204 { kNo_ForceCopyMode, false, true },
205 { kYes_ForceCopyMode, false, false },
206 { kNever_ForceCopyMode, true, true },
207 };
208 for (auto rec : recs) {
209 SkPixmap pm;
210 SkBitmap bm;
211 bm.allocN32Pixels(100, 100);
212
213 auto img = SkMakeImageFromRasterBitmap(bm, rec.fMode);
214 REPORTER_ASSERT(reporter, img->peekPixels(&pm));
215 const bool sameMutable = pm.addr32(0, 0) == bm.getAddr32(0, 0);
216 REPORTER_ASSERT(reporter, rec.fExpectSameAsMutable == sameMutable);
217
218 bm.notifyPixelsChanged(); // force a new generation ID
219
220 bm.setImmutable();
221 img = SkMakeImageFromRasterBitmap(bm, rec.fMode);
222 REPORTER_ASSERT(reporter, img->peekPixels(&pm));
223 const bool sameImmutable = pm.addr32(0, 0) == bm.getAddr32(0, 0);
224 REPORTER_ASSERT(reporter, rec.fExpectSameAsImmutable == sameImmutable);
225 }
226 }
227
197 namespace { 228 namespace {
198 229
199 const char* kSerializedData = "serialized"; 230 const char* kSerializedData = "serialized";
200 231
201 class MockSerializer : public SkPixelSerializer { 232 class MockSerializer : public SkPixelSerializer {
202 public: 233 public:
203 MockSerializer(SkData* (*func)()) : fFunc(func), fDidEncode(false) { } 234 MockSerializer(SkData* (*func)()) : fFunc(func), fDidEncode(false) { }
204 235
205 bool didEncode() const { return fDidEncode; } 236 bool didEncode() const { return fDidEncode; }
206 237
(...skipping 778 matching lines...) Expand 10 before | Expand all | Expand 10 after
985 SkBitmap bm1; 1016 SkBitmap bm1;
986 bm1.allocPixels(SkImageInfo::MakeN32(256, 256, kUnpremul_SkAlphaType)); 1017 bm1.allocPixels(SkImageInfo::MakeN32(256, 256, kUnpremul_SkAlphaType));
987 bm0.readPixels(bm1.info(), bm1.getPixels(), bm1.rowBytes(), 0, 0); 1018 bm0.readPixels(bm1.info(), bm1.getPixels(), bm1.rowBytes(), 0, 0);
988 1019
989 SkBitmap bm2; 1020 SkBitmap bm2;
990 bm2.allocPixels(SkImageInfo::MakeN32(256, 256, kPremul_SkAlphaType)); 1021 bm2.allocPixels(SkImageInfo::MakeN32(256, 256, kPremul_SkAlphaType));
991 bm1.readPixels(bm2.info(), bm2.getPixels(), bm2.rowBytes(), 0, 0); 1022 bm1.readPixels(bm2.info(), bm2.getPixels(), bm2.rowBytes(), 0, 0);
992 1023
993 REPORTER_ASSERT(reporter, equal(bm0, bm2)); 1024 REPORTER_ASSERT(reporter, equal(bm0, bm2));
994 } 1025 }
OLDNEW
« no previous file with comments | « src/image/SkImage_Raster.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698