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