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

Side by Side Diff: tests/DeferredCanvasTest.cpp

Issue 1145893007: Fixing leaky handling of SkImage in SkDeferredCanvas. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: reed feedback Created 5 years, 6 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
« src/pipe/SkGPipeWrite.cpp ('K') | « src/utils/SkDeferredCanvas.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 2012 Google Inc. 2 * Copyright 2012 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 "../src/image/SkImagePriv.h" 8 #include "../src/image/SkImagePriv.h"
9 #include "../src/image/SkSurface_Base.h" 9 #include "../src/image/SkSurface_Base.h"
10 #include "SkBitmap.h" 10 #include "SkBitmap.h"
(...skipping 671 matching lines...) Expand 10 before | Expand all | Expand 10 after
682 // 1 over : should still store the image 682 // 1 over : should still store the image
683 { 683 {
684 SkAutoTUnref<SkDeferredCanvas> canvas(SkDeferredCanvas::Create(surface.g et())); 684 SkAutoTUnref<SkDeferredCanvas> canvas(SkDeferredCanvas::Create(surface.g et()));
685 canvas->setBitmapSizeThreshold(40001); 685 canvas->setBitmapSizeThreshold(40001);
686 canvas->drawBitmap(sourceImage, 0, 0, NULL); 686 canvas->drawBitmap(sourceImage, 0, 0, NULL);
687 size_t newBytesAllocated = canvas->storageAllocatedForRecording(); 687 size_t newBytesAllocated = canvas->storageAllocatedForRecording();
688 REPORTER_ASSERT(reporter, newBytesAllocated > 0); 688 REPORTER_ASSERT(reporter, newBytesAllocated > 0);
689 } 689 }
690 } 690 }
691 691
692 static void TestDeferredCanvasImageFreeAfterFlush(skiatest::Reporter* reporter) {
693 SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterN32Premul(100, 100));
694 SkAutoTUnref<SkSurface> sourceSurface(SkSurface::NewRasterN32Premul(100, 100 ));
695 SkAutoTUnref<SkImage> sourceImage(sourceSurface->newImageSnapshot());
696 SkAutoTUnref<SkDeferredCanvas> canvas(SkDeferredCanvas::Create(surface.get() ));
697
698 canvas->drawImage(sourceImage, 0, 0, NULL);
699
700 size_t newBytesAllocated = canvas->storageAllocatedForRecording();
701 REPORTER_ASSERT(reporter, newBytesAllocated > 0);
702
703 canvas->flush();
704
705 newBytesAllocated = canvas->storageAllocatedForRecording();
706 REPORTER_ASSERT(reporter, newBytesAllocated == 0);
707 }
692 708
693 typedef const void* PixelPtr; 709 typedef const void* PixelPtr;
694 // Returns an opaque pointer which, either points to a GrTexture or RAM pixel 710 // Returns an opaque pointer which, either points to a GrTexture or RAM pixel
695 // buffer. Used to test pointer equality do determine whether a surface points 711 // buffer. Used to test pointer equality do determine whether a surface points
696 // to the same pixel data storage as before. 712 // to the same pixel data storage as before.
697 static PixelPtr get_surface_ptr(SkSurface* surface, bool useGpu) { 713 static PixelPtr get_surface_ptr(SkSurface* surface, bool useGpu) {
698 #if SK_SUPPORT_GPU 714 #if SK_SUPPORT_GPU
699 if (useGpu) { 715 if (useGpu) {
700 return surface->getCanvas()->internal_private_accessTopLayerRenderTarget ()->asTexture(); 716 return surface->getCanvas()->internal_private_accessTopLayerRenderTarget ()->asTexture();
701 } else 717 } else
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
923 939
924 DEF_TEST(DeferredCanvas_CPU, reporter) { 940 DEF_TEST(DeferredCanvas_CPU, reporter) {
925 TestDeferredCanvasFlush(reporter); 941 TestDeferredCanvasFlush(reporter);
926 TestDeferredCanvasSilentFlush(reporter); 942 TestDeferredCanvasSilentFlush(reporter);
927 TestDeferredCanvasFreshFrame(reporter); 943 TestDeferredCanvasFreshFrame(reporter);
928 TestDeferredCanvasMemoryLimit(reporter); 944 TestDeferredCanvasMemoryLimit(reporter);
929 TestDeferredCanvasBitmapCaching(reporter); 945 TestDeferredCanvasBitmapCaching(reporter);
930 TestDeferredCanvasSkip(reporter); 946 TestDeferredCanvasSkip(reporter);
931 TestDeferredCanvasBitmapShaderNoLeak(reporter); 947 TestDeferredCanvasBitmapShaderNoLeak(reporter);
932 TestDeferredCanvasBitmapSizeThreshold(reporter); 948 TestDeferredCanvasBitmapSizeThreshold(reporter);
949 TestDeferredCanvasImageFreeAfterFlush(reporter);
933 TestDeferredCanvasCreateCompatibleDevice(reporter); 950 TestDeferredCanvasCreateCompatibleDevice(reporter);
934 TestDeferredCanvasWritePixelsToSurface(reporter); 951 TestDeferredCanvasWritePixelsToSurface(reporter);
935 TestDeferredCanvasGetCanvasSize(reporter); 952 TestDeferredCanvasGetCanvasSize(reporter);
936 TestDeferredCanvasSurface(reporter, NULL); 953 TestDeferredCanvasSurface(reporter, NULL);
937 TestDeferredCanvasSetSurface(reporter, NULL); 954 TestDeferredCanvasSetSurface(reporter, NULL);
938 } 955 }
939 956
940 DEF_GPUTEST(DeferredCanvas_GPU, reporter, factory) { 957 DEF_GPUTEST(DeferredCanvas_GPU, reporter, factory) {
941 if (factory != NULL) { 958 if (factory != NULL) {
942 TestDeferredCanvasSurface(reporter, factory); 959 TestDeferredCanvasSurface(reporter, factory);
943 TestDeferredCanvasSetSurface(reporter, factory); 960 TestDeferredCanvasSetSurface(reporter, factory);
944 } 961 }
945 } 962 }
OLDNEW
« src/pipe/SkGPipeWrite.cpp ('K') | « src/utils/SkDeferredCanvas.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698