| OLD | NEW | 
|---|
| 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 121 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 132     EXPECT_COPY_ON_WRITE(drawTextOnPath(testText.c_str(), testText.size(), testP
     ath, NULL, \ | 132     EXPECT_COPY_ON_WRITE(drawTextOnPath(testText.c_str(), testText.size(), testP
     ath, NULL, \ | 
| 133         testPaint)) | 133         testPaint)) | 
| 134 } | 134 } | 
| 135 | 135 | 
| 136 static void TestSurfaceWritableAfterSnapshotRelease(skiatest::Reporter* reporter
     , | 136 static void TestSurfaceWritableAfterSnapshotRelease(skiatest::Reporter* reporter
     , | 
| 137                                                     SurfaceType surfaceType, | 137                                                     SurfaceType surfaceType, | 
| 138                                                     GrContext* context) { | 138                                                     GrContext* context) { | 
| 139     // This test succeeds by not triggering an assertion. | 139     // This test succeeds by not triggering an assertion. | 
| 140     // The test verifies that the surface remains writable (usable) after | 140     // The test verifies that the surface remains writable (usable) 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     SkAutoTUnref<SkSurface> surface(createSurface(surfaceType, context)); | 
| 143     SkAutoTUnref<SkSurface> aur_surface(surface); |  | 
| 144     SkCanvas* canvas = surface->getCanvas(); | 143     SkCanvas* canvas = surface->getCanvas(); | 
| 145     canvas->clear(1); | 144     canvas->clear(1); | 
| 146     surface->newImageSnapshot()->unref();  // Create and destroy SkImage | 145     surface->newImageSnapshot()->unref();  // Create and destroy SkImage | 
| 147     canvas->clear(2); | 146     canvas->clear(2);  // Must not assert internally | 
| 148 } | 147 } | 
| 149 | 148 | 
| 150 #if SK_SUPPORT_GPU | 149 #if SK_SUPPORT_GPU | 
|  | 150 static void Test_crbug263329(skiatest::Reporter* reporter, | 
|  | 151                              GrContext* context) { | 
|  | 152     // This is a regression test for crbug.com/263329 | 
|  | 153     // Bug was caused by onCopyOnWrite releasing the old surface texture | 
|  | 154     // back to the scratch texture pool even though the texture is used | 
|  | 155     // by and active SkImage_Gpu. | 
|  | 156     SkAutoTUnref<SkSurface> surface1(createSurface(kGpu_SurfaceType, context)); | 
|  | 157     SkAutoTUnref<SkSurface> surface2(createSurface(kGpu_SurfaceType, context)); | 
|  | 158     SkCanvas* canvas1 = surface1->getCanvas(); | 
|  | 159     SkCanvas* canvas2 = surface2->getCanvas(); | 
|  | 160     canvas1->clear(1); | 
|  | 161     SkAutoTUnref<SkImage> image1(surface1->newImageSnapshot()); | 
|  | 162     // Trigger copy on write, new backing is a scratch texture | 
|  | 163     canvas1->clear(2); | 
|  | 164     SkAutoTUnref<SkImage> image2(surface1->newImageSnapshot()); | 
|  | 165     // Trigger copy on write, old backing should not be returned to scratch | 
|  | 166     // pool because it is held by image2 | 
|  | 167     canvas1->clear(3); | 
|  | 168 | 
|  | 169     canvas2->clear(4); | 
|  | 170     SkAutoTUnref<SkImage> image3(surface2->newImageSnapshot()); | 
|  | 171     // Trigger copy on write on surface2. The new backing store should not | 
|  | 172     // be recycling a texture that is held by an existing image. | 
|  | 173     canvas2->clear(5); | 
|  | 174     SkAutoTUnref<SkImage> image4(surface2->newImageSnapshot()); | 
|  | 175     REPORTER_ASSERT(reporter, image4->getTexture() != image3->getTexture()); | 
|  | 176     // The following assertion checks crbug.com/263329 | 
|  | 177     REPORTER_ASSERT(reporter, image4->getTexture() != image2->getTexture()); | 
|  | 178     REPORTER_ASSERT(reporter, image4->getTexture() != image1->getTexture()); | 
|  | 179     REPORTER_ASSERT(reporter, image3->getTexture() != image2->getTexture()); | 
|  | 180     REPORTER_ASSERT(reporter, image3->getTexture() != image1->getTexture()); | 
|  | 181     REPORTER_ASSERT(reporter, image2->getTexture() != image1->getTexture()); | 
|  | 182 } | 
|  | 183 | 
| 151 static void TestGetTexture(skiatest::Reporter* reporter, | 184 static void TestGetTexture(skiatest::Reporter* reporter, | 
| 152                                  SurfaceType surfaceType, | 185                                  SurfaceType surfaceType, | 
| 153                                  GrContext* context) { | 186                                  GrContext* context) { | 
| 154     SkAutoTUnref<SkSurface> surface(createSurface(surfaceType, context)); | 187     SkAutoTUnref<SkSurface> surface(createSurface(surfaceType, context)); | 
| 155     SkAutoTUnref<SkImage> image(surface->newImageSnapshot()); | 188     SkAutoTUnref<SkImage> image(surface->newImageSnapshot()); | 
| 156     GrTexture* texture = image->getTexture(); | 189     GrTexture* texture = image->getTexture(); | 
| 157     if (surfaceType == kGpu_SurfaceType) { | 190     if (surfaceType == kGpu_SurfaceType) { | 
| 158         REPORTER_ASSERT(reporter, NULL != texture); | 191         REPORTER_ASSERT(reporter, NULL != texture); | 
| 159         REPORTER_ASSERT(reporter, 0 != texture->getTextureHandle()); | 192         REPORTER_ASSERT(reporter, 0 != texture->getTextureHandle()); | 
| 160     } else { | 193     } else { | 
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 202     TestSurfaceCopyOnWrite(reporter, kPicture_SurfaceType, NULL); | 235     TestSurfaceCopyOnWrite(reporter, kPicture_SurfaceType, NULL); | 
| 203     TestSurfaceWritableAfterSnapshotRelease(reporter, kRaster_SurfaceType, NULL)
     ; | 236     TestSurfaceWritableAfterSnapshotRelease(reporter, kRaster_SurfaceType, NULL)
     ; | 
| 204     TestSurfaceWritableAfterSnapshotRelease(reporter, kPicture_SurfaceType, NULL
     ); | 237     TestSurfaceWritableAfterSnapshotRelease(reporter, kPicture_SurfaceType, NULL
     ); | 
| 205     TestSurfaceNoCanvas(reporter, kRaster_SurfaceType, NULL, SkSurface::kDiscard
     _ContentChangeMode); | 238     TestSurfaceNoCanvas(reporter, kRaster_SurfaceType, NULL, SkSurface::kDiscard
     _ContentChangeMode); | 
| 206     TestSurfaceNoCanvas(reporter, kRaster_SurfaceType, NULL, SkSurface::kRetain_
     ContentChangeMode); | 239     TestSurfaceNoCanvas(reporter, kRaster_SurfaceType, NULL, SkSurface::kRetain_
     ContentChangeMode); | 
| 207 #if SK_SUPPORT_GPU | 240 #if SK_SUPPORT_GPU | 
| 208     TestGetTexture(reporter, kRaster_SurfaceType, NULL); | 241     TestGetTexture(reporter, kRaster_SurfaceType, NULL); | 
| 209     TestGetTexture(reporter, kPicture_SurfaceType, NULL); | 242     TestGetTexture(reporter, kPicture_SurfaceType, NULL); | 
| 210     if (NULL != factory) { | 243     if (NULL != factory) { | 
| 211         GrContext* context = factory->get(GrContextFactory::kNative_GLContextTyp
     e); | 244         GrContext* context = factory->get(GrContextFactory::kNative_GLContextTyp
     e); | 
|  | 245         Test_crbug263329(reporter, context); | 
| 212         TestSurfaceCopyOnWrite(reporter, kGpu_SurfaceType, context); | 246         TestSurfaceCopyOnWrite(reporter, kGpu_SurfaceType, context); | 
| 213         TestSurfaceWritableAfterSnapshotRelease(reporter, kGpu_SurfaceType, cont
     ext); | 247         TestSurfaceWritableAfterSnapshotRelease(reporter, kGpu_SurfaceType, cont
     ext); | 
| 214         TestSurfaceNoCanvas(reporter, kGpu_SurfaceType, context, SkSurface::kDis
     card_ContentChangeMode); | 248         TestSurfaceNoCanvas(reporter, kGpu_SurfaceType, context, SkSurface::kDis
     card_ContentChangeMode); | 
| 215         TestSurfaceNoCanvas(reporter, kGpu_SurfaceType, context, SkSurface::kRet
     ain_ContentChangeMode); | 249         TestSurfaceNoCanvas(reporter, kGpu_SurfaceType, context, SkSurface::kRet
     ain_ContentChangeMode); | 
| 216         TestGetTexture(reporter, kGpu_SurfaceType, context); | 250         TestGetTexture(reporter, kGpu_SurfaceType, context); | 
| 217     } | 251     } | 
| 218 #endif | 252 #endif | 
| 219 } | 253 } | 
| 220 | 254 | 
| 221 #include "TestClassDef.h" | 255 #include "TestClassDef.h" | 
| 222 DEFINE_GPUTESTCLASS("Surface", SurfaceTestClass, TestSurface) | 256 DEFINE_GPUTESTCLASS("Surface", SurfaceTestClass, TestSurface) | 
| OLD | NEW | 
|---|