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

Side by Side Diff: tests/SurfaceTest.cpp

Issue 14063015: Adding optimization to avoid image copy in SkSurface copy on write when content is discardable (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 7 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « 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 /* 2 /*
3 * Copyright 2013 Google Inc. 3 * Copyright 2013 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 #include "SkCanvas.h" 8 #include "SkCanvas.h"
9 #include "SkRRect.h" 9 #include "SkRRect.h"
10 #include "SkSurface.h" 10 #include "SkSurface.h"
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 // acquiring and releasing a snapshot without triggering a copy on write. 141 // acquiring and releasing a snapshot without triggering a copy on write.
142 SkSurface* surface = createSurface(surfaceType, context); 142 SkSurface* surface = createSurface(surfaceType, context);
143 SkAutoTUnref<SkSurface> aur_surface(surface); 143 SkAutoTUnref<SkSurface> aur_surface(surface);
144 SkCanvas* canvas = surface->getCanvas(); 144 SkCanvas* canvas = surface->getCanvas();
145 canvas->clear(1); 145 canvas->clear(1);
146 surface->newImageSnapshot()->unref(); // Create and destroy SkImage 146 surface->newImageSnapshot()->unref(); // Create and destroy SkImage
147 canvas->clear(2); 147 canvas->clear(2);
148 } 148 }
149 static void TestSurfaceNoCanvas(skiatest::Reporter* reporter, 149 static void TestSurfaceNoCanvas(skiatest::Reporter* reporter,
150 SurfaceType surfaceType, 150 SurfaceType surfaceType,
151 GrContext* context) { 151 GrContext* context,
152 SkSurface::ContentChangeMode mode) {
152 // Verifies the robustness of SkSurface for handling use cases where calls 153 // Verifies the robustness of SkSurface for handling use cases where calls
153 // are made before a canvas is created. 154 // are made before a canvas is created.
154 { 155 {
155 // Test passes by not asserting 156 // Test passes by not asserting
156 SkSurface* surface = createSurface(surfaceType, context); 157 SkSurface* surface = createSurface(surfaceType, context);
157 SkAutoTUnref<SkSurface> aur_surface(surface); 158 SkAutoTUnref<SkSurface> aur_surface(surface);
158 surface->notifyContentChanged(); 159 surface->notifyContentWillChange(mode);
159 surface->validate(); 160 surface->validate();
160 } 161 }
161 { 162 {
162 SkSurface* surface = createSurface(surfaceType, context); 163 SkSurface* surface = createSurface(surfaceType, context);
163 SkAutoTUnref<SkSurface> aur_surface(surface); 164 SkAutoTUnref<SkSurface> aur_surface(surface);
164 SkImage* image1 = surface->newImageSnapshot(); 165 SkImage* image1 = surface->newImageSnapshot();
165 SkAutoTUnref<SkImage> aur_image1(image1); 166 SkAutoTUnref<SkImage> aur_image1(image1);
166 image1->validate(); 167 image1->validate();
167 surface->validate(); 168 surface->validate();
168 surface->notifyContentChanged(); 169 surface->notifyContentWillChange(mode);
169 image1->validate(); 170 image1->validate();
170 surface->validate(); 171 surface->validate();
171 SkImage* image2 = surface->newImageSnapshot(); 172 SkImage* image2 = surface->newImageSnapshot();
172 SkAutoTUnref<SkImage> aur_image2(image2); 173 SkAutoTUnref<SkImage> aur_image2(image2);
173 image2->validate(); 174 image2->validate();
174 surface->validate(); 175 surface->validate();
175 REPORTER_ASSERT(reporter, image1 != image2); 176 REPORTER_ASSERT(reporter, image1 != image2);
176 } 177 }
177 178
178 } 179 }
179 180
180 static void TestSurface(skiatest::Reporter* reporter, GrContextFactory* factory) { 181 static void TestSurface(skiatest::Reporter* reporter, GrContextFactory* factory) {
181 TestSurfaceCopyOnWrite(reporter, kRaster_SurfaceType, NULL); 182 TestSurfaceCopyOnWrite(reporter, kRaster_SurfaceType, NULL);
182 TestSurfaceCopyOnWrite(reporter, kPicture_SurfaceType, NULL); 183 TestSurfaceCopyOnWrite(reporter, kPicture_SurfaceType, NULL);
183 TestSurfaceWritableAfterSnapshotRelease(reporter, kRaster_SurfaceType, NULL) ; 184 TestSurfaceWritableAfterSnapshotRelease(reporter, kRaster_SurfaceType, NULL) ;
184 TestSurfaceWritableAfterSnapshotRelease(reporter, kPicture_SurfaceType, NULL ); 185 TestSurfaceWritableAfterSnapshotRelease(reporter, kPicture_SurfaceType, NULL );
185 TestSurfaceNoCanvas(reporter, kRaster_SurfaceType, NULL); 186 TestSurfaceNoCanvas(reporter, kRaster_SurfaceType, NULL, SkSurface::kDiscard _ContentChangeMode);
187 TestSurfaceNoCanvas(reporter, kRaster_SurfaceType, NULL, SkSurface::kRetain_ ContentChangeMode);
186 #if SK_SUPPORT_GPU 188 #if SK_SUPPORT_GPU
187 if (NULL != factory) { 189 if (NULL != factory) {
188 GrContext* context = factory->get(GrContextFactory::kNative_GLContextTyp e); 190 GrContext* context = factory->get(GrContextFactory::kNative_GLContextTyp e);
189 TestSurfaceCopyOnWrite(reporter, kGpu_SurfaceType, context); 191 TestSurfaceCopyOnWrite(reporter, kGpu_SurfaceType, context);
190 TestSurfaceWritableAfterSnapshotRelease(reporter, kGpu_SurfaceType, cont ext); 192 TestSurfaceWritableAfterSnapshotRelease(reporter, kGpu_SurfaceType, cont ext);
191 TestSurfaceNoCanvas(reporter, kGpu_SurfaceType, context); 193 TestSurfaceNoCanvas(reporter, kGpu_SurfaceType, context, SkSurface::kDis card_ContentChangeMode);
194 TestSurfaceNoCanvas(reporter, kGpu_SurfaceType, context, SkSurface::kRet ain_ContentChangeMode);
192 } 195 }
193 #endif 196 #endif
194 } 197 }
195 198
196 #include "TestClassDef.h" 199 #include "TestClassDef.h"
197 DEFINE_GPUTESTCLASS("Surface", SurfaceTestClass, TestSurface) 200 DEFINE_GPUTESTCLASS("Surface", SurfaceTestClass, TestSurface)
OLDNEW
« no previous file with comments | « src/utils/SkDeferredCanvas.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698