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

Side by Side Diff: tests/ImageTest.cpp

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