| OLD | NEW | 
|    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 437 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  448     GrTexture* texture = image->getTexture(); |  448     GrTexture* texture = image->getTexture(); | 
|  449     if (surfaceType == kGpu_SurfaceType || surfaceType == kGpuScratch_SurfaceTyp
     e) { |  449     if (surfaceType == kGpu_SurfaceType || surfaceType == kGpuScratch_SurfaceTyp
     e) { | 
|  450         REPORTER_ASSERT(reporter, texture); |  450         REPORTER_ASSERT(reporter, texture); | 
|  451         REPORTER_ASSERT(reporter, 0 != texture->getTextureHandle()); |  451         REPORTER_ASSERT(reporter, 0 != texture->getTextureHandle()); | 
|  452     } else { |  452     } else { | 
|  453         REPORTER_ASSERT(reporter, NULL == texture); |  453         REPORTER_ASSERT(reporter, NULL == texture); | 
|  454     } |  454     } | 
|  455     surface->notifyContentWillChange(SkSurface::kDiscard_ContentChangeMode); |  455     surface->notifyContentWillChange(SkSurface::kDiscard_ContentChangeMode); | 
|  456     REPORTER_ASSERT(reporter, image->getTexture() == texture); |  456     REPORTER_ASSERT(reporter, image->getTexture() == texture); | 
|  457 } |  457 } | 
 |  458  | 
 |  459 #include "GrGpuResourceCacheAccess.h" | 
 |  460 #include "SkGpuDevice.h" | 
 |  461 #include "SkImage_Gpu.h" | 
 |  462 #include "SkSurface_Gpu.h" | 
 |  463  | 
 |  464 SkSurface::Budgeted is_budgeted(SkSurface* surf) { | 
 |  465     return ((SkSurface_Gpu*)surf)->getDevice()->accessRenderTarget()->cacheAcces
     s().isBudgeted() ? | 
 |  466         SkSurface::kYes_Budgeted : SkSurface::kNo_Budgeted; | 
 |  467 } | 
 |  468  | 
 |  469 SkSurface::Budgeted is_budgeted(SkImage* image) { | 
 |  470     return ((SkImage_Gpu*)image)->getTexture()->cacheAccess().isBudgeted() ? | 
 |  471         SkSurface::kYes_Budgeted : SkSurface::kNo_Budgeted; | 
 |  472 } | 
 |  473  | 
 |  474 static void test_surface_budget(skiatest::Reporter* reporter, GrContext* context
     ) { | 
 |  475     SkImageInfo info = SkImageInfo::MakeN32Premul(8,8); | 
 |  476     for (int i = 0; i < 2; ++i) { | 
 |  477         SkSurface::Budgeted sbudgeted = i ? SkSurface::kYes_Budgeted : SkSurface
     ::kNo_Budgeted; | 
 |  478         for (int j = 0; j < 2; ++j) { | 
 |  479             SkSurface::Budgeted ibudgeted = j ? SkSurface::kYes_Budgeted : SkSur
     face::kNo_Budgeted; | 
 |  480             SkAutoTUnref<SkSurface> | 
 |  481                 surface(SkSurface::NewRenderTarget(context, sbudgeted, info, 0))
     ; | 
 |  482             SkASSERT(surface); | 
 |  483             REPORTER_ASSERT(reporter, sbudgeted == is_budgeted(surface)); | 
 |  484  | 
 |  485             SkImage* image = surface->newImageSnapshot(ibudgeted); | 
 |  486  | 
 |  487             // Initially the image shares a texture with the surface, and the su
     rface decides | 
 |  488             // whether it is budgeted or not. | 
 |  489             REPORTER_ASSERT(reporter, sbudgeted == is_budgeted(surface)); | 
 |  490             REPORTER_ASSERT(reporter, sbudgeted == is_budgeted(image)); | 
 |  491  | 
 |  492             // Now trigger copy-on-write | 
 |  493             surface->getCanvas()->clear(SK_ColorBLUE); | 
 |  494  | 
 |  495             // They don't share a texture anymore. They should each have made th
     eir own budget | 
 |  496             // decision. | 
 |  497             REPORTER_ASSERT(reporter, sbudgeted == is_budgeted(surface)); | 
 |  498             REPORTER_ASSERT(reporter, ibudgeted == is_budgeted(image)); | 
 |  499         } | 
 |  500     } | 
 |  501 } | 
 |  502  | 
|  458 #endif |  503 #endif | 
|  459  |  504  | 
|  460 static void TestSurfaceNoCanvas(skiatest::Reporter* reporter, |  505 static void TestSurfaceNoCanvas(skiatest::Reporter* reporter, | 
|  461                                           SurfaceType surfaceType, |  506                                           SurfaceType surfaceType, | 
|  462                                           GrContext* context, |  507                                           GrContext* context, | 
|  463                                           SkSurface::ContentChangeMode mode) { |  508                                           SkSurface::ContentChangeMode mode) { | 
|  464     // Verifies the robustness of SkSurface for handling use cases where calls |  509     // Verifies the robustness of SkSurface for handling use cases where calls | 
|  465     // are made before a canvas is created. |  510     // are made before a canvas is created. | 
|  466     { |  511     { | 
|  467         // Test passes by not asserting |  512         // Test passes by not asserting | 
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  519                 TestSurfaceCopyOnWrite(reporter, kGpuScratch_SurfaceType, contex
     t); |  564                 TestSurfaceCopyOnWrite(reporter, kGpuScratch_SurfaceType, contex
     t); | 
|  520                 TestSurfaceWritableAfterSnapshotRelease(reporter, kGpu_SurfaceTy
     pe, context); |  565                 TestSurfaceWritableAfterSnapshotRelease(reporter, kGpu_SurfaceTy
     pe, context); | 
|  521                 TestSurfaceWritableAfterSnapshotRelease(reporter, kGpuScratch_Su
     rfaceType, context); |  566                 TestSurfaceWritableAfterSnapshotRelease(reporter, kGpuScratch_Su
     rfaceType, context); | 
|  522                 TestSurfaceNoCanvas(reporter, kGpu_SurfaceType, context, SkSurfa
     ce::kDiscard_ContentChangeMode); |  567                 TestSurfaceNoCanvas(reporter, kGpu_SurfaceType, context, SkSurfa
     ce::kDiscard_ContentChangeMode); | 
|  523                 TestSurfaceNoCanvas(reporter, kGpuScratch_SurfaceType, context, 
     SkSurface::kDiscard_ContentChangeMode); |  568                 TestSurfaceNoCanvas(reporter, kGpuScratch_SurfaceType, context, 
     SkSurface::kDiscard_ContentChangeMode); | 
|  524                 TestSurfaceNoCanvas(reporter, kGpu_SurfaceType, context, SkSurfa
     ce::kRetain_ContentChangeMode); |  569                 TestSurfaceNoCanvas(reporter, kGpu_SurfaceType, context, SkSurfa
     ce::kRetain_ContentChangeMode); | 
|  525                 TestSurfaceNoCanvas(reporter, kGpuScratch_SurfaceType, context, 
     SkSurface::kRetain_ContentChangeMode); |  570                 TestSurfaceNoCanvas(reporter, kGpuScratch_SurfaceType, context, 
     SkSurface::kRetain_ContentChangeMode); | 
|  526                 TestGetTexture(reporter, kGpu_SurfaceType, context); |  571                 TestGetTexture(reporter, kGpu_SurfaceType, context); | 
|  527                 TestGetTexture(reporter, kGpuScratch_SurfaceType, context); |  572                 TestGetTexture(reporter, kGpuScratch_SurfaceType, context); | 
|  528                 test_empty_surface(reporter, context); |  573                 test_empty_surface(reporter, context); | 
 |  574                 test_surface_budget(reporter, context); | 
|  529             } |  575             } | 
|  530         } |  576         } | 
|  531     } |  577     } | 
|  532 #endif |  578 #endif | 
|  533 } |  579 } | 
| OLD | NEW |