| OLD | NEW |
| 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> | |
| 10 #include "DMGpuSupport.h" | 9 #include "DMGpuSupport.h" |
| 11 | 10 |
| 12 #include "SkBitmap.h" | 11 #include "SkBitmap.h" |
| 13 #include "SkCanvas.h" | 12 #include "SkCanvas.h" |
| 14 #include "SkData.h" | 13 #include "SkData.h" |
| 15 #include "SkDevice.h" | 14 #include "SkDevice.h" |
| 16 #include "SkImageEncoder.h" | 15 #include "SkImageEncoder.h" |
| 17 #include "SkImageGenerator.h" | 16 #include "SkImageGenerator.h" |
| 18 #include "SkImage_Base.h" | 17 #include "SkImage_Base.h" |
| 19 #include "SkPicture.h" | 18 #include "SkPicture.h" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 SkPaint paint; | 55 SkPaint paint; |
| 57 paint.setColor(SK_ColorBLACK); | 56 paint.setColor(SK_ColorBLACK); |
| 58 canvas->drawRect(SkRect::MakeXYWH(5, 5, 10, 10), paint); | 57 canvas->drawRect(SkRect::MakeXYWH(5, 5, 10, 10), paint); |
| 59 } | 58 } |
| 60 static SkImage* create_image() { | 59 static SkImage* create_image() { |
| 61 const SkImageInfo info = SkImageInfo::MakeN32(20, 20, kOpaque_SkAlphaType); | 60 const SkImageInfo info = SkImageInfo::MakeN32(20, 20, kOpaque_SkAlphaType); |
| 62 SkAutoTUnref<SkSurface> surface(SkSurface::NewRaster(info)); | 61 SkAutoTUnref<SkSurface> surface(SkSurface::NewRaster(info)); |
| 63 draw_image_test_pattern(surface->getCanvas()); | 62 draw_image_test_pattern(surface->getCanvas()); |
| 64 return surface->newImageSnapshot(); | 63 return surface->newImageSnapshot(); |
| 65 } | 64 } |
| 66 #if 0 | |
| 67 static SkImage* create_image_565() { | |
| 68 const SkImageInfo info = SkImageInfo::Make(20, 20, kRGB_565_SkColorType, kOp
aque_SkAlphaType); | |
| 69 SkAutoTUnref<SkSurface> surface(SkSurface::NewRaster(info)); | |
| 70 draw_image_test_pattern(surface->getCanvas()); | |
| 71 return surface->newImageSnapshot(); | |
| 72 } | |
| 73 #endif | |
| 74 static SkImage* create_image_ct() { | |
| 75 SkPMColor colors[] = { | |
| 76 SkPreMultiplyARGB(0xFF, 0xFF, 0xFF, 0x00), | |
| 77 SkPreMultiplyARGB(0x80, 0x00, 0xA0, 0xFF), | |
| 78 SkPreMultiplyARGB(0xFF, 0xBB, 0x00, 0xBB) | |
| 79 }; | |
| 80 SkAutoTUnref<SkColorTable> colorTable(new SkColorTable(colors, SK_ARRAY_COUN
T(colors))); | |
| 81 uint8_t data[] = { | |
| 82 0, 0, 0, 0, 0, | |
| 83 0, 1, 1, 1, 0, | |
| 84 0, 1, 2, 1, 0, | |
| 85 0, 1, 1, 1, 0, | |
| 86 0, 0, 0, 0, 0 | |
| 87 }; | |
| 88 SkImageInfo info = SkImageInfo::Make(5, 5, kIndex_8_SkColorType, kPremul_SkA
lphaType); | |
| 89 return SkImage::NewRasterCopy(info, data, 5, colorTable); | |
| 90 } | |
| 91 static SkData* create_image_data(SkImageInfo* info) { | 65 static SkData* create_image_data(SkImageInfo* info) { |
| 92 *info = SkImageInfo::MakeN32(20, 20, kOpaque_SkAlphaType); | 66 *info = SkImageInfo::MakeN32(20, 20, kOpaque_SkAlphaType); |
| 93 const size_t rowBytes = info->minRowBytes(); | 67 const size_t rowBytes = info->minRowBytes(); |
| 94 SkAutoTUnref<SkData> data(SkData::NewUninitialized(rowBytes * info->height()
)); | 68 SkAutoTUnref<SkData> data(SkData::NewUninitialized(rowBytes * info->height()
)); |
| 95 { | 69 { |
| 96 SkBitmap bm; | 70 SkBitmap bm; |
| 97 bm.installPixels(*info, data->writable_data(), rowBytes); | 71 bm.installPixels(*info, data->writable_data(), rowBytes); |
| 98 SkCanvas canvas(bm); | 72 SkCanvas canvas(bm); |
| 99 draw_image_test_pattern(&canvas); | 73 draw_image_test_pattern(&canvas); |
| 100 } | 74 } |
| (...skipping 649 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 750 // write pixels call violated the contract with refImg and refImg is now und
efined. | 724 // write pixels call violated the contract with refImg and refImg is now und
efined. |
| 751 check_image_color(reporter, refImg, expected1); | 725 check_image_color(reporter, refImg, expected1); |
| 752 #endif | 726 #endif |
| 753 check_image_color(reporter, cpyImg, expected0); | 727 check_image_color(reporter, cpyImg, expected0); |
| 754 | 728 |
| 755 // Now exercise the release proc | 729 // Now exercise the release proc |
| 756 REPORTER_ASSERT(reporter, 0 == releaseChecker.fReleaseCount); | 730 REPORTER_ASSERT(reporter, 0 == releaseChecker.fReleaseCount); |
| 757 refImg.reset(nullptr); // force a release of the image | 731 refImg.reset(nullptr); // force a release of the image |
| 758 REPORTER_ASSERT(reporter, 1 == releaseChecker.fReleaseCount); | 732 REPORTER_ASSERT(reporter, 1 == releaseChecker.fReleaseCount); |
| 759 } | 733 } |
| 760 | |
| 761 static void check_images_same(skiatest::Reporter* reporter, const SkImage* a, co
nst SkImage* b) { | |
| 762 if (a->width() != b->width() || a->height() != b->height()) { | |
| 763 ERRORF(reporter, "Images must have the same size"); | |
| 764 return; | |
| 765 } | |
| 766 if (a->isOpaque() != b->isOpaque()) { | |
| 767 ERRORF(reporter, "Images must have the same opaquness"); | |
| 768 return; | |
| 769 } | |
| 770 | |
| 771 SkImageInfo info = SkImageInfo::MakeN32Premul(a->width(), a->height()); | |
| 772 SkAutoPixmapStorage apm; | |
| 773 SkAutoPixmapStorage bpm; | |
| 774 | |
| 775 apm.alloc(info); | |
| 776 bpm.alloc(info); | |
| 777 | |
| 778 if (!a->readPixels(apm, 0, 0)) { | |
| 779 ERRORF(reporter, "Could not read image a's pixels"); | |
| 780 return; | |
| 781 } | |
| 782 if (!b->readPixels(bpm, 0, 0)) { | |
| 783 ERRORF(reporter, "Could not read image b's pixels"); | |
| 784 return; | |
| 785 } | |
| 786 | |
| 787 for (auto y = 0; y < info.height(); ++y) { | |
| 788 for (auto x = 0; x < info.width(); ++x) { | |
| 789 uint32_t pixelA = *apm.addr32(x, y); | |
| 790 uint32_t pixelB = *bpm.addr32(x, y); | |
| 791 if (pixelA != pixelB) { | |
| 792 ERRORF(reporter, "Expected image pixels to be the same. At %d,%d
0x%08x != 0x%08x", | |
| 793 x, y, pixelA, pixelB); | |
| 794 return; | |
| 795 } | |
| 796 } | |
| 797 } | |
| 798 } | |
| 799 | |
| 800 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(NewTextureFromPixmap, reporter, context) { | |
| 801 for (auto create : {&create_image | |
| 802 #if 0 // read pixels failing for non RT formats (565 not a RT on some desktop GL
s). | |
| 803 , &create_image_565 | |
| 804 #endif | 734 #endif |
| 805 , &create_image_ct | |
| 806 }) { | |
| 807 SkAutoTUnref<SkImage> image((*create)()); | |
| 808 if (!image) { | |
| 809 ERRORF(reporter, "Could not create image"); | |
| 810 return; | |
| 811 } | |
| 812 | |
| 813 SkPixmap pixmap; | |
| 814 if (!image->peekPixels(&pixmap)) { | |
| 815 ERRORF(reporter, "peek failed"); | |
| 816 } else { | |
| 817 SkAutoTUnref<SkImage> texImage(SkImage::NewTextureFromPixmap(context
, pixmap, | |
| 818 SkBudge
ted::kNo)); | |
| 819 if (!texImage) { | |
| 820 ERRORF(reporter, "NewTextureFromPixmap failed."); | |
| 821 } else { | |
| 822 check_images_same(reporter, image, texImage); | |
| 823 } | |
| 824 } | |
| 825 } | |
| 826 } | |
| 827 | |
| 828 #endif | |
| OLD | NEW |