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

Side by Side Diff: tests/SurfaceTest.cpp

Issue 1658823002: Remove deferred clear from SkGpuDevice (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fix ptr->bool warning on windows Created 4 years, 10 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 | « tests/ResourceCacheTest.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 <functional>
8 #include "SkCanvas.h" 9 #include "SkCanvas.h"
9 #include "SkData.h" 10 #include "SkData.h"
10 #include "SkDevice.h" 11 #include "SkDevice.h"
11 #include "SkImage_Base.h" 12 #include "SkImage_Base.h"
12 #include "SkPath.h" 13 #include "SkPath.h"
13 #include "SkRRect.h" 14 #include "SkRRect.h"
14 #include "SkSurface.h" 15 #include "SkSurface.h"
15 #include "SkUtils.h" 16 #include "SkUtils.h"
16 #include "Test.h" 17 #include "Test.h"
17 18
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 #if SK_SUPPORT_GPU 76 #if SK_SUPPORT_GPU
76 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceEmpty_Gpu, reporter, context) { 77 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceEmpty_Gpu, reporter, context) {
77 const SkImageInfo info = SkImageInfo::Make(0, 0, kN32_SkColorType, kPremul_S kAlphaType); 78 const SkImageInfo info = SkImageInfo::Make(0, 0, kN32_SkColorType, kPremul_S kAlphaType);
78 REPORTER_ASSERT(reporter, nullptr == 79 REPORTER_ASSERT(reporter, nullptr ==
79 SkSurface::NewRenderTarget(context, SkSurface::kNo_Budgeted, info, 0, nullptr)); 80 SkSurface::NewRenderTarget(context, SkSurface::kNo_Budgeted, info, 0, nullptr));
80 } 81 }
81 #endif 82 #endif
82 83
83 #if SK_SUPPORT_GPU 84 #if SK_SUPPORT_GPU
84 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceWrappedTexture, reporter, context) { 85 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceWrappedTexture, reporter, context) {
85 const GrGpu* gpu = context->getGpu(); 86 GrGpu* gpu = context->getGpu();
86 if (!gpu) { 87 if (!gpu) {
87 return; 88 return;
88 } 89 }
89 90
90 // Test the wrapped factory for SkSurface by creating a backend texture and then wrap it in 91 // Test the wrapped factory for SkSurface by creating a backend texture and then wrap it in
91 // a SkSurface. 92 // a SkSurface.
92 static const int kW = 100; 93 static const int kW = 100;
93 static const int kH = 100; 94 static const int kH = 100;
94 static const uint32_t kOrigColor = 0xFFAABBCC; 95 static const uint32_t kOrigColor = 0xFFAABBCC;
95 SkAutoTArray<uint32_t> pixels(kW * kH); 96 SkAutoTArray<uint32_t> pixels(kW * kH);
(...skipping 599 matching lines...) Expand 10 before | Expand all | Expand 10 after
695 // specify a larger rowbytes 696 // specify a larger rowbytes
696 SkAutoTUnref<SkSurface> surf1(SkSurface::NewRaster(info, 500, nullptr)); 697 SkAutoTUnref<SkSurface> surf1(SkSurface::NewRaster(info, 500, nullptr));
697 check_rowbytes_remain_consistent(surf1, reporter); 698 check_rowbytes_remain_consistent(surf1, reporter);
698 699
699 // Try some illegal rowByte values 700 // Try some illegal rowByte values
700 SkSurface* s = SkSurface::NewRaster(info, 396, nullptr); // needs to be a t least 400 701 SkSurface* s = SkSurface::NewRaster(info, 396, nullptr); // needs to be a t least 400
701 REPORTER_ASSERT(reporter, nullptr == s); 702 REPORTER_ASSERT(reporter, nullptr == s);
702 s = SkSurface::NewRaster(info, 1 << 30, nullptr); // allocation to large 703 s = SkSurface::NewRaster(info, 1 << 30, nullptr); // allocation to large
703 REPORTER_ASSERT(reporter, nullptr == s); 704 REPORTER_ASSERT(reporter, nullptr == s);
704 } 705 }
706
707 #if SK_SUPPORT_GPU
708
709 void test_surface_clear(skiatest::Reporter* reporter, SkSurface* surface,
710 std::function<GrSurface*(SkSurface*)> grSurfaceGetter,
711 uint32_t expectedValue) {
712 if (!surface) {
713 ERRORF(reporter, "Could not create GPU SkSurface.");
714 return;
715 }
716 int w = surface->width();
717 int h = surface->height();
718 SkAutoTDeleteArray<uint32_t> pixels(new uint32_t[w * h]);
719 memset(pixels.get(), ~expectedValue, sizeof(uint32_t) * w * h);
720
721 SkAutoTUnref<GrSurface> grSurface(SkSafeRef(grSurfaceGetter(surface)));
722 if (!grSurface) {
723 ERRORF(reporter, "Could access render target of GPU SkSurface.");
724 return;
725 }
726 SkASSERT(surface->unique());
727 surface->unref();
728 grSurface->readPixels(0, 0, w, h, kRGBA_8888_GrPixelConfig, pixels.get());
729 for (int y = 0; y < h; ++y) {
730 for (int x = 0; x < w; ++x) {
731 uint32_t pixel = pixels.get()[y * w + x];
732 if (pixel != expectedValue) {
733 SkString msg;
734 if (expectedValue) {
735 msg = "SkSurface should have left render target unmodified";
736 } else {
737 msg = "SkSurface should have cleared the render target";
738 }
739 ERRORF(reporter,
740 "%s but read 0x%08x (instead of 0x%08x) at %x,%d", msg.c_ str(), pixel,
741 expectedValue, x, y);
742 return;
743 }
744 }
745 }
746 }
747
748 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceClear_Gpu, reporter, context) {
749 std::function<GrSurface*(SkSurface*)> grSurfaceGetters[] = {
750 [] (SkSurface* s){ return s->getCanvas()->internal_private_accessTopLaye rRenderTarget();},
751 [] (SkSurface* s){
752 SkBaseDevice* d =
753 s->getCanvas()->getDevice_just_for_deprecated_compatibility_test ing();
754 return d->accessRenderTarget(); },
755 [] (SkSurface* s){ SkImage* i = s->newImageSnapshot();
756 return i->getTexture(); },
757 [] (SkSurface* s){ SkImage* i = s->newImageSnapshot();
758 return as_IB(i)->peekTexture(); },
759 };
760 for (auto grSurfaceGetter : grSurfaceGetters) {
761 for (auto& surface_func : {&create_gpu_surface, &create_gpu_scratch_surf ace}) {
762 SkSurface* surface(surface_func(context, kPremul_SkAlphaType, nullpt r));
763 test_surface_clear(reporter, surface, grSurfaceGetter, 0x0);
764 }
765 // Wrapped RTs are *not* supposed to clear (to allow client to partially update a surface).
766 static const int kWidth = 10;
767 static const int kHeight = 10;
768 SkAutoTDeleteArray<uint32_t> pixels(new uint32_t[kWidth * kHeight]);
769 memset(pixels.get(), 0xAB, sizeof(uint32_t) * kWidth * kHeight);
770
771 GrBackendObject textureObject =
772 context->getGpu()->createTestingOnlyBackendTexture(pixels.get(), kWidth, kHeight,
773 kRGBA_8888_Gr PixelConfig);
774
775 GrBackendTextureDesc desc;
776 desc.fConfig = kRGBA_8888_GrPixelConfig;
777 desc.fWidth = kWidth;
778 desc.fHeight = kHeight;
779 desc.fFlags = kRenderTarget_GrBackendTextureFlag;
780 desc.fTextureHandle = textureObject;
781
782 SkSurface* surface = SkSurface::NewFromBackendTexture(context, desc, nul lptr);
783 test_surface_clear(reporter, surface, grSurfaceGetter, 0xABABABAB);
784 context->getGpu()->deleteTestingOnlyBackendTexture(textureObject);
785 }
786 }
787 #endif
OLDNEW
« no previous file with comments | « tests/ResourceCacheTest.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698