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

Side by Side Diff: tests/ImageTest.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/CanvasTest.cpp ('k') | tests/SurfaceTest.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 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 "DMGpuSupport.h" 10 #include "DMGpuSupport.h"
(...skipping 14 matching lines...) Expand all
25 #include "SkUtils.h" 25 #include "SkUtils.h"
26 #include "Test.h" 26 #include "Test.h"
27 27
28 static void assert_equal(skiatest::Reporter* reporter, SkImage* a, const SkIRect * subsetA, 28 static void assert_equal(skiatest::Reporter* reporter, SkImage* a, const SkIRect * subsetA,
29 SkImage* b) { 29 SkImage* b) {
30 const int widthA = subsetA ? subsetA->width() : a->width(); 30 const int widthA = subsetA ? subsetA->width() : a->width();
31 const int heightA = subsetA ? subsetA->height() : a->height(); 31 const int heightA = subsetA ? subsetA->height() : a->height();
32 32
33 REPORTER_ASSERT(reporter, widthA == b->width()); 33 REPORTER_ASSERT(reporter, widthA == b->width());
34 REPORTER_ASSERT(reporter, heightA == b->height()); 34 REPORTER_ASSERT(reporter, heightA == b->height());
35 #if 0 35 REPORTER_ASSERT(reporter, a->isOpaque() == b->isOpaque());
36 // see https://bug.skia.org/3965
37 bool AO = a->isOpaque();
38 bool BO = b->isOpaque();
39 REPORTER_ASSERT(reporter, AO == BO);
40 #endif
41 36
42 SkImageInfo info = SkImageInfo::MakeN32(widthA, heightA, 37 SkImageInfo info = SkImageInfo::MakeN32(widthA, heightA,
43 a->isOpaque() ? kOpaque_SkAlphaType : kP remul_SkAlphaType); 38 a->isOpaque() ? kOpaque_SkAlphaType : kP remul_SkAlphaType);
44 SkAutoPixmapStorage pmapA, pmapB; 39 SkAutoPixmapStorage pmapA, pmapB;
45 pmapA.alloc(info); 40 pmapA.alloc(info);
46 pmapB.alloc(info); 41 pmapB.alloc(info);
47 42
48 const int srcX = subsetA ? subsetA->x() : 0; 43 const int srcX = subsetA ? subsetA->x() : 0;
49 const int srcY = subsetA ? subsetA->y() : 0; 44 const int srcY = subsetA ? subsetA->y() : 0;
50 45
(...skipping 18 matching lines...) Expand all
69 return surface->newImageSnapshot(); 64 return surface->newImageSnapshot();
70 } 65 }
71 #if 0 66 #if 0
72 static SkImage* create_image_565() { 67 static SkImage* create_image_565() {
73 const SkImageInfo info = SkImageInfo::Make(20, 20, kRGB_565_SkColorType, kOp aque_SkAlphaType); 68 const SkImageInfo info = SkImageInfo::Make(20, 20, kRGB_565_SkColorType, kOp aque_SkAlphaType);
74 SkAutoTUnref<SkSurface> surface(SkSurface::NewRaster(info)); 69 SkAutoTUnref<SkSurface> surface(SkSurface::NewRaster(info));
75 draw_image_test_pattern(surface->getCanvas()); 70 draw_image_test_pattern(surface->getCanvas());
76 return surface->newImageSnapshot(); 71 return surface->newImageSnapshot();
77 } 72 }
78 #endif 73 #endif
79 #if 0
80 static SkImage* create_image_ct() { 74 static SkImage* create_image_ct() {
81 SkPMColor colors[] = { 75 SkPMColor colors[] = {
82 SkPreMultiplyARGB(0xFF, 0xFF, 0xFF, 0x00), 76 SkPreMultiplyARGB(0xFF, 0xFF, 0xFF, 0x00),
83 SkPreMultiplyARGB(0x80, 0x00, 0xA0, 0xFF), 77 SkPreMultiplyARGB(0x80, 0x00, 0xA0, 0xFF),
84 SkPreMultiplyARGB(0xFF, 0xBB, 0x00, 0xBB) 78 SkPreMultiplyARGB(0xFF, 0xBB, 0x00, 0xBB)
85 }; 79 };
86 SkAutoTUnref<SkColorTable> colorTable(new SkColorTable(colors, SK_ARRAY_COUN T(colors))); 80 SkAutoTUnref<SkColorTable> colorTable(new SkColorTable(colors, SK_ARRAY_COUN T(colors)));
87 uint8_t data[] = { 81 uint8_t data[] = {
88 0, 0, 0, 0, 0, 82 0, 0, 0, 0, 0,
89 0, 1, 1, 1, 0, 83 0, 1, 1, 1, 0,
90 0, 1, 2, 1, 0, 84 0, 1, 2, 1, 0,
91 0, 1, 1, 1, 0, 85 0, 1, 1, 1, 0,
92 0, 0, 0, 0, 0 86 0, 0, 0, 0, 0
93 }; 87 };
94 SkImageInfo info = SkImageInfo::Make(5, 5, kIndex_8_SkColorType, kPremul_SkA lphaType); 88 SkImageInfo info = SkImageInfo::Make(5, 5, kIndex_8_SkColorType, kPremul_SkA lphaType);
95 return SkImage::NewRasterCopy(info, data, 5, colorTable); 89 return SkImage::NewRasterCopy(info, data, 5, colorTable);
96 } 90 }
97 #endif
98 static SkData* create_image_data(SkImageInfo* info) { 91 static SkData* create_image_data(SkImageInfo* info) {
99 *info = SkImageInfo::MakeN32(20, 20, kOpaque_SkAlphaType); 92 *info = SkImageInfo::MakeN32(20, 20, kOpaque_SkAlphaType);
100 const size_t rowBytes = info->minRowBytes(); 93 const size_t rowBytes = info->minRowBytes();
101 SkAutoTUnref<SkData> data(SkData::NewUninitialized(rowBytes * info->height() )); 94 SkAutoTUnref<SkData> data(SkData::NewUninitialized(rowBytes * info->height() ));
102 { 95 {
103 SkBitmap bm; 96 SkBitmap bm;
104 bm.installPixels(*info, data->writable_data(), rowBytes); 97 bm.installPixels(*info, data->writable_data(), rowBytes);
105 SkCanvas canvas(bm); 98 SkCanvas canvas(bm);
106 draw_image_test_pattern(&canvas); 99 draw_image_test_pattern(&canvas);
107 } 100 }
(...skipping 543 matching lines...) Expand 10 before | Expand all | Expand 10 after
651 SkImage::kRW_LegacyBitmapMode, 644 SkImage::kRW_LegacyBitmapMode,
652 }; 645 };
653 for (auto& mode : modes) { 646 for (auto& mode : modes) {
654 SkAutoTUnref<SkImage> image(create_gpu_image(context)); 647 SkAutoTUnref<SkImage> image(create_gpu_image(context));
655 test_legacy_bitmap(reporter, image, mode); 648 test_legacy_bitmap(reporter, image, mode);
656 } 649 }
657 } 650 }
658 #endif 651 #endif
659 652
660 static void test_peek(skiatest::Reporter* reporter, SkImage* image, bool expectP eekSuccess) { 653 static void test_peek(skiatest::Reporter* reporter, SkImage* image, bool expectP eekSuccess) {
661 SkImageInfo info; 654 SkPixmap pm;
662 size_t rowBytes; 655 bool success = image->peekPixels(&pm);
663 const void* addr = image->peekPixels(&info, &rowBytes);
664 bool success = SkToBool(addr);
665 REPORTER_ASSERT(reporter, expectPeekSuccess == success); 656 REPORTER_ASSERT(reporter, expectPeekSuccess == success);
666 if (success) { 657 if (success) {
658 const SkImageInfo& info = pm.info();
667 REPORTER_ASSERT(reporter, 20 == info.width()); 659 REPORTER_ASSERT(reporter, 20 == info.width());
668 REPORTER_ASSERT(reporter, 20 == info.height()); 660 REPORTER_ASSERT(reporter, 20 == info.height());
669 REPORTER_ASSERT(reporter, kN32_SkColorType == info.colorType()); 661 REPORTER_ASSERT(reporter, kN32_SkColorType == info.colorType());
670 REPORTER_ASSERT(reporter, kPremul_SkAlphaType == info.alphaType() || 662 REPORTER_ASSERT(reporter, kPremul_SkAlphaType == info.alphaType() ||
671 kOpaque_SkAlphaType == info.alphaType()); 663 kOpaque_SkAlphaType == info.alphaType());
672 REPORTER_ASSERT(reporter, info.minRowBytes() <= rowBytes); 664 REPORTER_ASSERT(reporter, info.minRowBytes() <= pm.rowBytes());
673 REPORTER_ASSERT(reporter, SkPreMultiplyColor(SK_ColorWHITE) == *(const S kPMColor*)addr); 665 REPORTER_ASSERT(reporter, SkPreMultiplyColor(SK_ColorWHITE) == *pm.addr3 2(0, 0));
674 } 666 }
675 } 667 }
676 DEF_TEST(ImagePeek, reporter) { 668 DEF_TEST(ImagePeek, reporter) {
677 SkAutoTUnref<SkImage> image(create_image()); 669 SkAutoTUnref<SkImage> image(create_image());
678 test_peek(reporter, image, true); 670 test_peek(reporter, image, true);
679 671
680 image.reset(create_data_image()); 672 image.reset(create_data_image());
681 test_peek(reporter, image, true); 673 test_peek(reporter, image, true);
682 674
683 RasterDataHolder dataHolder; 675 RasterDataHolder dataHolder;
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
799 if (pixelA != pixelB) { 791 if (pixelA != pixelB) {
800 ERRORF(reporter, "Expected image pixels to be the same. At %d,%d 0x%08x != 0x%08x", 792 ERRORF(reporter, "Expected image pixels to be the same. At %d,%d 0x%08x != 0x%08x",
801 x, y, pixelA, pixelB); 793 x, y, pixelA, pixelB);
802 return; 794 return;
803 } 795 }
804 } 796 }
805 } 797 }
806 } 798 }
807 799
808 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(NewTextureFromPixmap, reporter, context) { 800 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(NewTextureFromPixmap, reporter, context) {
809 for (auto create : {&create_image, 801 for (auto create : {&create_image
810 #if 0 // read pixels failing for non RT formats (565 not a RT on some desktop GL s). 802 #if 0 // read pixels failing for non RT formats (565 not a RT on some desktop GL s).
811 &create_image_565 803 , &create_image_565
812 #if 0 // peekPixels on color table images is currently broken. 804 #endif
813 , &create_image_ct 805 , &create_image_ct
814 #endif
815 #endif
816 }) { 806 }) {
817 SkAutoTUnref<SkImage> image((*create)()); 807 SkAutoTUnref<SkImage> image((*create)());
818 if (!image) { 808 if (!image) {
819 ERRORF(reporter, "Could not create image"); 809 ERRORF(reporter, "Could not create image");
820 return; 810 return;
821 } 811 }
822 812
823 SkPixmap pixmap; 813 SkPixmap pixmap;
824 if (!image->peekPixels(&pixmap)) { 814 if (!image->peekPixels(&pixmap)) {
825 ERRORF(reporter, "peek failed"); 815 ERRORF(reporter, "peek failed");
826 } else { 816 } else {
827 SkAutoTUnref<SkImage> texImage(SkImage::NewTextureFromPixmap(context , pixmap, 817 SkAutoTUnref<SkImage> texImage(SkImage::NewTextureFromPixmap(context , pixmap,
828 SkBudge ted::kNo)); 818 SkBudge ted::kNo));
829 if (!texImage) { 819 if (!texImage) {
830 ERRORF(reporter, "NewTextureFromPixmap failed."); 820 ERRORF(reporter, "NewTextureFromPixmap failed.");
831 } else { 821 } else {
832 check_images_same(reporter, image, texImage); 822 check_images_same(reporter, image, texImage);
833 } 823 }
834 } 824 }
835 } 825 }
836 } 826 }
837 827
838 #endif 828 #endif
OLDNEW
« no previous file with comments | « tests/CanvasTest.cpp ('k') | tests/SurfaceTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698