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

Side by Side Diff: tests/ImageTest.cpp

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

Powered by Google App Engine
This is Rietveld 408576698