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

Side by Side Diff: tests/SurfaceTest.cpp

Issue 1784563002: unify peekPixels around pixmap parameter (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: update GrUploadPixmapToTexture to know about the new desc if readPixels was called Created 4 years, 9 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 | « tests/ImageTest.cpp ('k') | tools/android/SkAndroidSDKCanvas.cpp » ('j') | 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 2013 Google Inc. 2 * Copyright 2013 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 "SkCanvas.h" 9 #include "SkCanvas.h"
10 #include "SkData.h" 10 #include "SkData.h"
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 gpu->deleteTestingOnlyBackendTexture(texHandle); 150 gpu->deleteTestingOnlyBackendTexture(texHandle);
151 } 151 }
152 #endif 152 #endif
153 153
154 static void test_canvas_peek(skiatest::Reporter* reporter, 154 static void test_canvas_peek(skiatest::Reporter* reporter,
155 SkSurface* surface, 155 SkSurface* surface,
156 const SkImageInfo& requestInfo, 156 const SkImageInfo& requestInfo,
157 bool expectPeekSuccess) { 157 bool expectPeekSuccess) {
158 const SkColor color = SK_ColorRED; 158 const SkColor color = SK_ColorRED;
159 const SkPMColor pmcolor = SkPreMultiplyColor(color); 159 const SkPMColor pmcolor = SkPreMultiplyColor(color);
160 SkImageInfo info;
161 size_t rowBytes;
162 surface->getCanvas()->clear(color); 160 surface->getCanvas()->clear(color);
163 161
164 const void* addr = surface->getCanvas()->peekPixels(&info, &rowBytes); 162 SkPixmap pmap;
165 bool success = SkToBool(addr); 163 bool success = surface->getCanvas()->peekPixels(&pmap);
166 REPORTER_ASSERT(reporter, expectPeekSuccess == success); 164 REPORTER_ASSERT(reporter, expectPeekSuccess == success);
167 165
168 SkImageInfo info2; 166 SkPixmap pmap2;
169 size_t rb2; 167 const void* addr2 = surface->peekPixels(&pmap2) ? pmap2.addr() : nullptr;
170 const void* addr2 = surface->peekPixels(&info2, &rb2);
171 168
172 if (success) { 169 if (success) {
173 REPORTER_ASSERT(reporter, requestInfo == info); 170 REPORTER_ASSERT(reporter, requestInfo == pmap.info());
174 REPORTER_ASSERT(reporter, requestInfo.minRowBytes() <= rowBytes); 171 REPORTER_ASSERT(reporter, requestInfo.minRowBytes() <= pmap.rowBytes());
175 REPORTER_ASSERT(reporter, pmcolor == *(const SkPMColor*)addr); 172 REPORTER_ASSERT(reporter, pmcolor == *pmap.addr32());
176 173
177 REPORTER_ASSERT(reporter, addr2 == addr); 174 REPORTER_ASSERT(reporter, pmap.addr() == pmap2.addr());
178 REPORTER_ASSERT(reporter, info2 == info); 175 REPORTER_ASSERT(reporter, pmap.info() == pmap2.info());
179 REPORTER_ASSERT(reporter, rb2 == rowBytes); 176 REPORTER_ASSERT(reporter, pmap.rowBytes() == pmap2.rowBytes());
180 } else { 177 } else {
181 REPORTER_ASSERT(reporter, nullptr == addr2); 178 REPORTER_ASSERT(reporter, nullptr == addr2);
182 } 179 }
183 } 180 }
184 DEF_TEST(SurfaceCanvasPeek, reporter) { 181 DEF_TEST(SurfaceCanvasPeek, reporter) {
185 for (auto& surface_func : { &create_surface, &create_direct_surface }) { 182 for (auto& surface_func : { &create_surface, &create_direct_surface }) {
186 SkImageInfo requestInfo; 183 SkImageInfo requestInfo;
187 SkAutoTUnref<SkSurface> surface(surface_func(kPremul_SkAlphaType, &reque stInfo)); 184 SkAutoTUnref<SkSurface> surface(surface_func(kPremul_SkAlphaType, &reque stInfo));
188 test_canvas_peek(reporter, surface, requestInfo, true); 185 test_canvas_peek(reporter, surface, requestInfo, true);
189 } 186 }
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 } 377 }
381 378
382 DEF_TEST(UniqueImageSnapshot, reporter) { 379 DEF_TEST(UniqueImageSnapshot, reporter) {
383 auto getImageBackingStore = [reporter](SkImage* image) { 380 auto getImageBackingStore = [reporter](SkImage* image) {
384 SkPixmap pm; 381 SkPixmap pm;
385 bool success = image->peekPixels(&pm); 382 bool success = image->peekPixels(&pm);
386 REPORTER_ASSERT(reporter, success); 383 REPORTER_ASSERT(reporter, success);
387 return reinterpret_cast<intptr_t>(pm.addr()); 384 return reinterpret_cast<intptr_t>(pm.addr());
388 }; 385 };
389 auto getSufaceBackingStore = [reporter](SkSurface* surface) { 386 auto getSufaceBackingStore = [reporter](SkSurface* surface) {
390 SkImageInfo info; 387 SkPixmap pmap;
391 size_t rowBytes; 388 const void* pixels = surface->getCanvas()->peekPixels(&pmap) ? pmap.addr () : nullptr;
392 const void* pixels = surface->getCanvas()->peekPixels(&info, &rowBytes);
393 REPORTER_ASSERT(reporter, pixels); 389 REPORTER_ASSERT(reporter, pixels);
394 return reinterpret_cast<intptr_t>(pixels); 390 return reinterpret_cast<intptr_t>(pixels);
395 }; 391 };
396 392
397 SkAutoTUnref<SkSurface> surface(create_surface()); 393 SkAutoTUnref<SkSurface> surface(create_surface());
398 test_unique_image_snap(reporter, surface, false, getImageBackingStore, getSu faceBackingStore); 394 test_unique_image_snap(reporter, surface, false, getImageBackingStore, getSu faceBackingStore);
399 surface.reset(create_direct_surface()); 395 surface.reset(create_direct_surface());
400 test_unique_image_snap(reporter, surface, true, getImageBackingStore, getSuf aceBackingStore); 396 test_unique_image_snap(reporter, surface, true, getImageBackingStore, getSuf aceBackingStore);
401 } 397 }
402 398
(...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after
778 SkAutoTUnref<SkSurface> surface( 774 SkAutoTUnref<SkSurface> surface(
779 surface_func(context, kPremul_SkAlphaType, nullptr)); 775 surface_func(context, kPremul_SkAlphaType, nullptr));
780 test_func(reporter, surface, mode); 776 test_func(reporter, surface, mode);
781 } 777 }
782 } 778 }
783 } 779 }
784 } 780 }
785 #endif 781 #endif
786 782
787 static void check_rowbytes_remain_consistent(SkSurface* surface, skiatest::Repor ter* reporter) { 783 static void check_rowbytes_remain_consistent(SkSurface* surface, skiatest::Repor ter* reporter) {
788 SkImageInfo info; 784 SkPixmap surfacePM;
789 size_t rowBytes; 785 REPORTER_ASSERT(reporter, surface->peekPixels(&surfacePM));
790 REPORTER_ASSERT(reporter, surface->peekPixels(&info, &rowBytes));
791 786
792 SkAutoTUnref<SkImage> image(surface->newImageSnapshot()); 787 SkAutoTUnref<SkImage> image(surface->newImageSnapshot());
793 SkImageInfo im_info; 788 SkPixmap pm;
794 size_t im_rowbytes; 789 REPORTER_ASSERT(reporter, image->peekPixels(&pm));
795 REPORTER_ASSERT(reporter, image->peekPixels(&im_info, &im_rowbytes));
796 790
797 REPORTER_ASSERT(reporter, rowBytes == im_rowbytes); 791 REPORTER_ASSERT(reporter, surfacePM.rowBytes() == pm.rowBytes());
798 792
799 // trigger a copy-on-write 793 // trigger a copy-on-write
800 surface->getCanvas()->drawPaint(SkPaint()); 794 surface->getCanvas()->drawPaint(SkPaint());
801 SkAutoTUnref<SkImage> image2(surface->newImageSnapshot()); 795 SkAutoTUnref<SkImage> image2(surface->newImageSnapshot());
802 REPORTER_ASSERT(reporter, image->uniqueID() != image2->uniqueID()); 796 REPORTER_ASSERT(reporter, image->uniqueID() != image2->uniqueID());
803 797
804 SkImageInfo im_info2; 798 SkPixmap pm2;
805 size_t im_rowbytes2; 799 REPORTER_ASSERT(reporter, image2->peekPixels(&pm2));
806 REPORTER_ASSERT(reporter, image2->peekPixels(&im_info2, &im_rowbytes2)); 800 REPORTER_ASSERT(reporter, pm2.rowBytes() == pm.rowBytes());
807
808 REPORTER_ASSERT(reporter, im_rowbytes2 == im_rowbytes);
809 } 801 }
810 802
811 DEF_TEST(surface_rowbytes, reporter) { 803 DEF_TEST(surface_rowbytes, reporter) {
812 const SkImageInfo info = SkImageInfo::MakeN32Premul(100, 100); 804 const SkImageInfo info = SkImageInfo::MakeN32Premul(100, 100);
813 805
814 SkAutoTUnref<SkSurface> surf0(SkSurface::NewRaster(info)); 806 SkAutoTUnref<SkSurface> surf0(SkSurface::NewRaster(info));
815 check_rowbytes_remain_consistent(surf0, reporter); 807 check_rowbytes_remain_consistent(surf0, reporter);
816 808
817 // specify a larger rowbytes 809 // specify a larger rowbytes
818 SkAutoTUnref<SkSurface> surf1(SkSurface::NewRaster(info, 500, nullptr)); 810 SkAutoTUnref<SkSurface> surf1(SkSurface::NewRaster(info, 500, nullptr));
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
898 desc.fHeight = kHeight; 890 desc.fHeight = kHeight;
899 desc.fFlags = kRenderTarget_GrBackendTextureFlag; 891 desc.fFlags = kRenderTarget_GrBackendTextureFlag;
900 desc.fTextureHandle = textureObject; 892 desc.fTextureHandle = textureObject;
901 893
902 SkSurface* surface = SkSurface::NewFromBackendTexture(context, desc, nul lptr); 894 SkSurface* surface = SkSurface::NewFromBackendTexture(context, desc, nul lptr);
903 test_surface_clear(reporter, surface, grSurfaceGetter, 0xABABABAB); 895 test_surface_clear(reporter, surface, grSurfaceGetter, 0xABABABAB);
904 context->getGpu()->deleteTestingOnlyBackendTexture(textureObject); 896 context->getGpu()->deleteTestingOnlyBackendTexture(textureObject);
905 } 897 }
906 } 898 }
907 #endif 899 #endif
OLDNEW
« no previous file with comments | « tests/ImageTest.cpp ('k') | tools/android/SkAndroidSDKCanvas.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698