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 431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
442 GrContext* context) { | 442 GrContext* context) { |
443 SkAutoTUnref<SkSurface> surface(createSurface(surfaceType, context)); | 443 SkAutoTUnref<SkSurface> surface(createSurface(surfaceType, context)); |
444 SkAutoTUnref<SkImage> image(surface->newImageSnapshot()); | 444 SkAutoTUnref<SkImage> image(surface->newImageSnapshot()); |
445 GrTexture* texture = image->getTexture(); | 445 GrTexture* texture = image->getTexture(); |
446 if (surfaceType == kGpu_SurfaceType || surfaceType == kGpuScratch_SurfaceTyp
e) { | 446 if (surfaceType == kGpu_SurfaceType || surfaceType == kGpuScratch_SurfaceTyp
e) { |
447 REPORTER_ASSERT(reporter, texture); | 447 REPORTER_ASSERT(reporter, texture); |
448 REPORTER_ASSERT(reporter, 0 != texture->getTextureHandle()); | 448 REPORTER_ASSERT(reporter, 0 != texture->getTextureHandle()); |
449 } else { | 449 } else { |
450 REPORTER_ASSERT(reporter, NULL == texture); | 450 REPORTER_ASSERT(reporter, NULL == texture); |
451 } | 451 } |
452 surface->notifyContentWillChange(SkSurface::kDiscard_ContentChangeMode); | 452 surface->getCanvas()->discard(); |
453 REPORTER_ASSERT(reporter, image->getTexture() == texture); | 453 REPORTER_ASSERT(reporter, image->getTexture() == texture); |
454 } | 454 } |
455 | 455 |
456 #include "GrGpuResourcePriv.h" | 456 #include "GrGpuResourcePriv.h" |
457 #include "SkGpuDevice.h" | 457 #include "SkGpuDevice.h" |
458 #include "SkImage_Gpu.h" | 458 #include "SkImage_Gpu.h" |
459 #include "SkSurface_Gpu.h" | 459 #include "SkSurface_Gpu.h" |
460 | 460 |
461 SkSurface::Budgeted is_budgeted(SkSurface* surf) { | 461 SkSurface::Budgeted is_budgeted(SkSurface* surf) { |
462 return ((SkSurface_Gpu*)surf)->getDevice()->accessRenderTarget()->resourcePr
iv().isBudgeted() ? | 462 return static_cast<SkSurface_Gpu*>(surf)->isBackendBudgeted() ? SkSurface::k
Yes_Budgeted |
463 SkSurface::kYes_Budgeted : SkSurface::kNo_Budgeted; | 463 : SkSurface::k
No_Budgeted; |
464 } | 464 } |
465 | 465 |
466 SkSurface::Budgeted is_budgeted(SkImage* image) { | 466 SkSurface::Budgeted is_budgeted(SkImage* image) { |
467 return ((SkImage_Gpu*)image)->getTexture()->resourcePriv().isBudgeted() ? | 467 return ((SkImage_Gpu*)image)->getTexture()->resourcePriv().isBudgeted() ? |
468 SkSurface::kYes_Budgeted : SkSurface::kNo_Budgeted; | 468 SkSurface::kYes_Budgeted : SkSurface::kNo_Budgeted; |
469 } | 469 } |
470 | 470 |
471 static void test_surface_budget(skiatest::Reporter* reporter, GrContext* context
) { | 471 static void test_surface_budget(skiatest::Reporter* reporter, GrContext* context
) { |
472 SkImageInfo info = SkImageInfo::MakeN32Premul(8,8); | 472 SkImageInfo info = SkImageInfo::MakeN32Premul(8,8); |
473 for (int i = 0; i < 2; ++i) { | 473 for (int i = 0; i < 2; ++i) { |
(...skipping 19 matching lines...) Expand all Loading... |
493 // decision. | 493 // decision. |
494 REPORTER_ASSERT(reporter, sbudgeted == is_budgeted(surface)); | 494 REPORTER_ASSERT(reporter, sbudgeted == is_budgeted(surface)); |
495 REPORTER_ASSERT(reporter, ibudgeted == is_budgeted(image)); | 495 REPORTER_ASSERT(reporter, ibudgeted == is_budgeted(image)); |
496 } | 496 } |
497 } | 497 } |
498 } | 498 } |
499 | 499 |
500 #endif | 500 #endif |
501 | 501 |
502 static void TestSurfaceNoCanvas(skiatest::Reporter* reporter, | 502 static void TestSurfaceNoCanvas(skiatest::Reporter* reporter, |
503 SurfaceType surfaceType, | 503 SurfaceType surfaceType, |
504 GrContext* context, | 504 GrContext* context) { |
505 SkSurface::ContentChangeMode mode) { | |
506 // Verifies the robustness of SkSurface for handling use cases where calls | 505 // Verifies the robustness of SkSurface for handling use cases where calls |
507 // are made before a canvas is created. | 506 // are made before a canvas is created. |
508 { | 507 { |
509 // Test passes by not asserting | 508 // Test passes by not asserting |
510 SkSurface* surface = createSurface(surfaceType, context); | 509 SkSurface* surface = createSurface(surfaceType, context); |
511 SkAutoTUnref<SkSurface> aur_surface(surface); | 510 SkAutoTUnref<SkSurface> aur_surface(surface); |
512 surface->notifyContentWillChange(mode); | |
513 SkDEBUGCODE(surface->validate();) | 511 SkDEBUGCODE(surface->validate();) |
514 } | 512 } |
515 { | 513 { |
516 SkSurface* surface = createSurface(surfaceType, context); | 514 SkSurface* surface = createSurface(surfaceType, context); |
517 SkAutoTUnref<SkSurface> aur_surface(surface); | 515 SkAutoTUnref<SkSurface> aur_surface(surface); |
518 SkImage* image1 = surface->newImageSnapshot(); | 516 SkImage* image1 = surface->newImageSnapshot(); |
519 SkAutoTUnref<SkImage> aur_image1(image1); | 517 SkAutoTUnref<SkImage> aur_image1(image1); |
520 SkDEBUGCODE(image1->validate();) | 518 SkDEBUGCODE(image1->validate();) |
521 SkDEBUGCODE(surface->validate();) | 519 SkDEBUGCODE(surface->validate();) |
522 surface->notifyContentWillChange(mode); | |
523 SkDEBUGCODE(image1->validate();) | |
524 SkDEBUGCODE(surface->validate();) | |
525 SkImage* image2 = surface->newImageSnapshot(); | 520 SkImage* image2 = surface->newImageSnapshot(); |
526 SkAutoTUnref<SkImage> aur_image2(image2); | 521 SkAutoTUnref<SkImage> aur_image2(image2); |
527 SkDEBUGCODE(image2->validate();) | 522 SkDEBUGCODE(image2->validate();) |
528 SkDEBUGCODE(surface->validate();) | 523 SkDEBUGCODE(surface->validate();) |
529 REPORTER_ASSERT(reporter, image1 != image2); | 524 REPORTER_ASSERT(reporter, image1 == image2); |
530 } | 525 } |
531 | |
532 } | 526 } |
533 | 527 |
534 DEF_GPUTEST(Surface, reporter, factory) { | 528 DEF_GPUTEST(Surface, reporter, factory) { |
535 test_image(reporter); | 529 test_image(reporter); |
536 | 530 |
537 TestSurfaceCopyOnWrite(reporter, kRaster_SurfaceType, NULL); | 531 TestSurfaceCopyOnWrite(reporter, kRaster_SurfaceType, NULL); |
538 TestSurfaceWritableAfterSnapshotRelease(reporter, kRaster_SurfaceType, NULL)
; | 532 TestSurfaceWritableAfterSnapshotRelease(reporter, kRaster_SurfaceType, NULL)
; |
539 TestSurfaceNoCanvas(reporter, kRaster_SurfaceType, NULL, SkSurface::kDiscard
_ContentChangeMode); | 533 TestSurfaceNoCanvas(reporter, kRaster_SurfaceType, NULL); |
540 TestSurfaceNoCanvas(reporter, kRaster_SurfaceType, NULL, SkSurface::kRetain_
ContentChangeMode); | |
541 | 534 |
542 test_empty_image(reporter); | 535 test_empty_image(reporter); |
543 test_empty_surface(reporter, NULL); | 536 test_empty_surface(reporter, NULL); |
544 | 537 |
545 test_imagepeek(reporter, factory); | 538 test_imagepeek(reporter, factory); |
546 test_canvaspeek(reporter, factory); | 539 test_canvaspeek(reporter, factory); |
547 | 540 |
548 #if SK_SUPPORT_GPU | 541 #if SK_SUPPORT_GPU |
549 TestGetTexture(reporter, kRaster_SurfaceType, NULL); | 542 TestGetTexture(reporter, kRaster_SurfaceType, NULL); |
550 if (factory) { | 543 if (factory) { |
551 for (int i= 0; i < GrContextFactory::kGLContextTypeCnt; ++i) { | 544 for (int i= 0; i < GrContextFactory::kGLContextTypeCnt; ++i) { |
552 GrContextFactory::GLContextType glCtxType = (GrContextFactory::GLCon
textType) i; | 545 GrContextFactory::GLContextType glCtxType = (GrContextFactory::GLCon
textType) i; |
553 if (!GrContextFactory::IsRenderingGLContext(glCtxType)) { | 546 if (!GrContextFactory::IsRenderingGLContext(glCtxType)) { |
554 continue; | 547 continue; |
555 } | 548 } |
556 GrContext* context = factory->get(glCtxType); | 549 GrContext* context = factory->get(glCtxType); |
557 if (context) { | 550 if (context) { |
558 Test_crbug263329(reporter, kGpu_SurfaceType, context); | 551 Test_crbug263329(reporter, kGpu_SurfaceType, context); |
559 Test_crbug263329(reporter, kGpuScratch_SurfaceType, context); | 552 Test_crbug263329(reporter, kGpuScratch_SurfaceType, context); |
560 TestSurfaceCopyOnWrite(reporter, kGpu_SurfaceType, context); | 553 TestSurfaceCopyOnWrite(reporter, kGpu_SurfaceType, context); |
561 TestSurfaceCopyOnWrite(reporter, kGpuScratch_SurfaceType, contex
t); | 554 TestSurfaceCopyOnWrite(reporter, kGpuScratch_SurfaceType, contex
t); |
562 TestSurfaceWritableAfterSnapshotRelease(reporter, kGpu_SurfaceTy
pe, context); | 555 TestSurfaceWritableAfterSnapshotRelease(reporter, kGpu_SurfaceTy
pe, context); |
563 TestSurfaceWritableAfterSnapshotRelease(reporter, kGpuScratch_Su
rfaceType, context); | 556 TestSurfaceWritableAfterSnapshotRelease(reporter, kGpuScratch_Su
rfaceType, context); |
564 TestSurfaceNoCanvas(reporter, kGpu_SurfaceType, context, SkSurfa
ce::kDiscard_ContentChangeMode); | 557 TestSurfaceNoCanvas(reporter, kGpu_SurfaceType, context); |
565 TestSurfaceNoCanvas(reporter, kGpuScratch_SurfaceType, context,
SkSurface::kDiscard_ContentChangeMode); | 558 TestSurfaceNoCanvas(reporter, kGpuScratch_SurfaceType, context); |
566 TestSurfaceNoCanvas(reporter, kGpu_SurfaceType, context, SkSurfa
ce::kRetain_ContentChangeMode); | |
567 TestSurfaceNoCanvas(reporter, kGpuScratch_SurfaceType, context,
SkSurface::kRetain_ContentChangeMode); | |
568 TestGetTexture(reporter, kGpu_SurfaceType, context); | 559 TestGetTexture(reporter, kGpu_SurfaceType, context); |
569 TestGetTexture(reporter, kGpuScratch_SurfaceType, context); | 560 TestGetTexture(reporter, kGpuScratch_SurfaceType, context); |
570 test_empty_surface(reporter, context); | 561 test_empty_surface(reporter, context); |
571 test_surface_budget(reporter, context); | 562 test_surface_budget(reporter, context); |
572 } | 563 } |
573 } | 564 } |
574 } | 565 } |
575 #endif | 566 #endif |
576 } | 567 } |
OLD | NEW |