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

Side by Side Diff: tests/SurfaceTest.cpp

Issue 1121813002: new image from backend desc (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: set samplecount to 0 (for now) Created 5 years, 7 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/SkSurface_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 2013 Google Inc. 2 * Copyright 2013 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 "SkCanvas.h" 8 #include "SkCanvas.h"
9 #include "SkData.h" 9 #include "SkData.h"
10 #include "SkImageEncoder.h" 10 #include "SkImageEncoder.h"
(...skipping 599 matching lines...) Expand 10 before | Expand all | Expand 10 after
610 TestGetTexture(reporter, kGpu_SurfaceType, context); 610 TestGetTexture(reporter, kGpu_SurfaceType, context);
611 TestGetTexture(reporter, kGpuScratch_SurfaceType, context); 611 TestGetTexture(reporter, kGpuScratch_SurfaceType, context);
612 test_empty_surface(reporter, context); 612 test_empty_surface(reporter, context);
613 test_surface_budget(reporter, context); 613 test_surface_budget(reporter, context);
614 test_wrapped_texture_surface(reporter, context); 614 test_wrapped_texture_surface(reporter, context);
615 } 615 }
616 } 616 }
617 } 617 }
618 #endif 618 #endif
619 } 619 }
620
621 #if SK_SUPPORT_GPU
622 static SkImage* make_desc_image(GrContext* ctx, int w, int h, GrBackendObject te xID, bool doCopy) {
623 GrBackendTextureDesc desc;
624 desc.fConfig = kSkia8888_GrPixelConfig;
625 // need to be a rendertarget for now...
626 desc.fFlags = kRenderTarget_GrBackendTextureFlag;
627 desc.fWidth = w;
628 desc.fHeight = h;
629 desc.fSampleCnt = 0;
630 desc.fTextureHandle = texID;
631 return doCopy ? SkImage::NewFromTextureCopy(ctx, desc) : SkImage::NewFromTex ture(ctx, desc);
632 }
633
634 static void test_image_color(skiatest::Reporter* reporter, SkImage* image, SkPMC olor expected) {
635 const SkImageInfo info = SkImageInfo::MakeN32Premul(1, 1);
636 SkPMColor pixel;
637 REPORTER_ASSERT(reporter, image->readPixels(info, &pixel, sizeof(pixel), 0, 0));
638 REPORTER_ASSERT(reporter, pixel == expected);
639 }
640
641 DEF_GPUTEST(SkImage_NewFromTexture, reporter, factory) {
642 GrContext* ctx = factory->get(GrContextFactory::kNative_GLContextType);
643 if (!ctx) {
644 REPORTER_ASSERT(reporter, false);
645 return;
646 }
647 GrTextureProvider* provider = ctx->textureProvider();
648
649 const int w = 10;
650 const int h = 10;
651 SkPMColor storage[w * h];
652 const SkPMColor expected0 = SkPreMultiplyColor(SK_ColorRED);
653 sk_memset32(storage, expected0, w * h);
654
655 GrSurfaceDesc desc;
656 desc.fFlags = kRenderTarget_GrSurfaceFlag; // needs to be a rendertarget fo r readpixels();
657 desc.fOrigin = kDefault_GrSurfaceOrigin;
658 desc.fWidth = w;
659 desc.fHeight = h;
660 desc.fConfig = kSkia8888_GrPixelConfig;
661 desc.fSampleCnt = 0;
662
663 SkAutoTUnref<GrTexture> tex(provider->createTexture(desc, false, storage, w * 4));
664 if (!tex) {
665 REPORTER_ASSERT(reporter, false);
666 return;
667 }
668
669 GrBackendObject srcTex = tex->getTextureHandle();
670 SkAutoTUnref<SkImage> refImg(make_desc_image(ctx, w, h, srcTex, false));
671 SkAutoTUnref<SkImage> cpyImg(make_desc_image(ctx, w, h, srcTex, true));
672
673 test_image_color(reporter, refImg, expected0);
674 test_image_color(reporter, cpyImg, expected0);
675
676 // Now lets jam new colors into our "external" texture, and see if the image s notice
677 const SkPMColor expected1 = SkPreMultiplyColor(SK_ColorBLUE);
678 sk_memset32(storage, expected1, w * h);
679 tex->writePixels(0, 0, w, h, kSkia8888_GrPixelConfig, storage, GrContext::kF lushWrites_PixelOp);
680
681 // We expect the ref'd image to see the new color, but cpy'd one should stil l see the old color
682 test_image_color(reporter, refImg, expected1);
683 test_image_color(reporter, cpyImg, expected0);
684 }
685 #endif
OLDNEW
« no previous file with comments | « src/image/SkSurface_Gpu.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698