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

Side by Side Diff: tests/ImageTest.cpp

Issue 1738513002: start on pre-upload data (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: stuff 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 "DMGpuSupport.h" 9 #include "DMGpuSupport.h"
10 10
(...skipping 719 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. 730 // write pixels call violated the contract with refImg and refImg is now und efined.
731 check_image_color(reporter, refImg, expected1); 731 check_image_color(reporter, refImg, expected1);
732 #endif 732 #endif
733 check_image_color(reporter, cpyImg, expected0); 733 check_image_color(reporter, cpyImg, expected0);
734 734
735 // Now exercise the release proc 735 // Now exercise the release proc
736 REPORTER_ASSERT(reporter, 0 == releaseChecker.fReleaseCount); 736 REPORTER_ASSERT(reporter, 0 == releaseChecker.fReleaseCount);
737 refImg.reset(nullptr); // force a release of the image 737 refImg.reset(nullptr); // force a release of the image
738 REPORTER_ASSERT(reporter, 1 == releaseChecker.fReleaseCount); 738 REPORTER_ASSERT(reporter, 1 == releaseChecker.fReleaseCount);
739 } 739 }
740
741 static void check_images_same(skiatest::Reporter* reporter, const SkImage* a, co nst SkImage* b) {
742 if (a->width() != b->width() || a->height() != b->height()) {
743 ERRORF(reporter, "Images must have the same size");
744 return;
745 }
746 if (a->isOpaque() != b->isOpaque()) {
747 ERRORF(reporter, "Images must have the same opaquness");
748 return;
749 }
750
751 SkImageInfo info = SkImageInfo::MakeN32Premul(a->width(), a->height());
752 SkAutoPixmapStorage apm;
753 SkAutoPixmapStorage bpm;
754
755 apm.alloc(info);
756 bpm.alloc(info);
757
758 if (!a->readPixels(apm, 0, 0)) {
759 ERRORF(reporter, "Could not read image a's pixels");
760 return;
761 }
762 if (!b->readPixels(bpm, 0, 0)) {
763 ERRORF(reporter, "Could not read image b's pixels");
764 return;
765 }
766
767 for (auto y = 0; y < info.height(); ++y) {
768 for (auto x = 0; x < info.width(); ++x) {
769 uint32_t pixelA = *apm.addr32(x, y);
770 uint32_t pixelB = *bpm.addr32(x, y);
771 if (pixelA != pixelB) {
772 ERRORF(reporter, "Expected image pixels to be the same. At %d,%d 0x%08x != 0x%08x",
773 x, y, pixelA, pixelB);
774 return;
775 }
776 }
777 }
778 }
779
780 DEF_GPUTEST_FOR_NATIVE_CONTEXT(ImageTextureData, reporter, context, glContext) {
781 SkAutoTUnref<GrContextThreadSafeProxy> proxy(context->threadSafeProxy());
782
783 GrContextFactory otherFactory;
784 GrContextFactory::ContextInfo otherContextInfo =
785 otherFactory.getContextInfo(GrContextFactory::kNative_GLContextType);
786
787 glContext->makeCurrent();
788 REPORTER_ASSERT(reporter, proxy);
789
790 std::function<SkImage *()> imageFactories[] = {
791 create_image,
792 create_codec_image,
793 create_data_image,
794 // Create an image from a picture.
795 create_picture_image,
796 // Create a texture image.
797 [context] { return create_gpu_image(context); },
798 // Create a texture image in a another GrContext.
799 [glContext, otherContextInfo] {
800 otherContextInfo.fGLContext->makeCurrent();
801 SkImage *otherContextImage = create_gpu_image(otherContextInfo.fGrCo ntext);
802 glContext->makeCurrent();
803 return otherContextImage;
804 }
805 };
806
807
808 for (auto imageFactory : imageFactories) {
809 SkAutoTUnref<SkImage> image(imageFactory());
810 int allocCnt = 0;
811 auto allocator = [&allocCnt] (size_t size, const SkImage*) {
812 ++allocCnt;
813 return sk_malloc_throw(size);
814 };
815 SkImageTextureData* td = image->newImageTextureData(*proxy, allocator);
816
817 REPORTER_ASSERT_MESSAGE(reporter, SkToBool(td) != SkToBool(as_IB(image)- >peekTexture()),
818 "Texture backed images should not succeed, other s should.");
819 if (td) {
820 REPORTER_ASSERT_MESSAGE(reporter, 1 == allocCnt,
821 "Should have made a single allocation.");
822 for (auto budgeted : { SkBudgeted::kNo, SkBudgeted::kYes }) {
823 SkAutoTUnref<SkImage> newImage(td->newImage(context, budgeted));
824 REPORTER_ASSERT(reporter, SkToBool(newImage));
825 if (newImage) {
826 check_images_same(reporter, image, newImage);
827 }
828 // The other context should be able to create images from textur e data created by
829 // the original context.
830 SkAutoTUnref<SkImage> image1(td->newImage(otherContextInfo.fGrCo ntext, budgeted));
831 REPORTER_ASSERT(reporter, !image1);
832 glContext->makeCurrent();
833 }
834 sk_free(td);
835 }
836 }
837 }
740 #endif 838 #endif
839
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