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

Side by Side Diff: tests/SurfaceTest.cpp

Issue 1166993002: Towards removing getTexture() from SkImage (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: rebase 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
« 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 * 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 "SkDevice.h" 10 #include "SkDevice.h"
11 #include "SkImageEncoder.h" 11 #include "SkImageEncoder.h"
12 #include "SkImage_Base.h"
12 #include "SkRRect.h" 13 #include "SkRRect.h"
13 #include "SkSurface.h" 14 #include "SkSurface.h"
14 #include "SkUtils.h" 15 #include "SkUtils.h"
15 #include "Test.h" 16 #include "Test.h"
16 17
17 #if SK_SUPPORT_GPU 18 #if SK_SUPPORT_GPU
18 #include "GrContextFactory.h" 19 #include "GrContextFactory.h"
19 #else 20 #else
20 class GrContextFactory; 21 class GrContextFactory;
21 class GrContext; 22 class GrContext;
(...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after
521 // Trigger copy on write, old backing should not be returned to scratch 522 // Trigger copy on write, old backing should not be returned to scratch
522 // pool because it is held by image2 523 // pool because it is held by image2
523 canvas1->clear(3); 524 canvas1->clear(3);
524 525
525 canvas2->clear(4); 526 canvas2->clear(4);
526 SkAutoTUnref<SkImage> image3(surface2->newImageSnapshot()); 527 SkAutoTUnref<SkImage> image3(surface2->newImageSnapshot());
527 // Trigger copy on write on surface2. The new backing store should not 528 // Trigger copy on write on surface2. The new backing store should not
528 // be recycling a texture that is held by an existing image. 529 // be recycling a texture that is held by an existing image.
529 canvas2->clear(5); 530 canvas2->clear(5);
530 SkAutoTUnref<SkImage> image4(surface2->newImageSnapshot()); 531 SkAutoTUnref<SkImage> image4(surface2->newImageSnapshot());
531 REPORTER_ASSERT(reporter, image4->getTexture() != image3->getTexture()); 532 REPORTER_ASSERT(reporter, as_IB(image4)->getTexture() != as_IB(image3)->getT exture());
532 // The following assertion checks crbug.com/263329 533 // The following assertion checks crbug.com/263329
533 REPORTER_ASSERT(reporter, image4->getTexture() != image2->getTexture()); 534 REPORTER_ASSERT(reporter, as_IB(image4)->getTexture() != as_IB(image2)->getT exture());
534 REPORTER_ASSERT(reporter, image4->getTexture() != image1->getTexture()); 535 REPORTER_ASSERT(reporter, as_IB(image4)->getTexture() != as_IB(image1)->getT exture());
535 REPORTER_ASSERT(reporter, image3->getTexture() != image2->getTexture()); 536 REPORTER_ASSERT(reporter, as_IB(image3)->getTexture() != as_IB(image2)->getT exture());
536 REPORTER_ASSERT(reporter, image3->getTexture() != image1->getTexture()); 537 REPORTER_ASSERT(reporter, as_IB(image3)->getTexture() != as_IB(image1)->getT exture());
537 REPORTER_ASSERT(reporter, image2->getTexture() != image1->getTexture()); 538 REPORTER_ASSERT(reporter, as_IB(image2)->getTexture() != as_IB(image1)->getT exture());
538 } 539 }
539 540
540 static void TestGetTexture(skiatest::Reporter* reporter, 541 static void TestGetTexture(skiatest::Reporter* reporter,
541 SurfaceType surfaceType, 542 SurfaceType surfaceType,
542 GrContext* context) { 543 GrContext* context) {
543 SkAutoTUnref<SkSurface> surface(createSurface(surfaceType, context)); 544 SkAutoTUnref<SkSurface> surface(createSurface(surfaceType, context));
544 SkAutoTUnref<SkImage> image(surface->newImageSnapshot()); 545 SkAutoTUnref<SkImage> image(surface->newImageSnapshot());
545 GrTexture* texture = image->getTexture(); 546 GrTexture* texture = as_IB(image)->getTexture();
546 if (surfaceType == kGpu_SurfaceType || surfaceType == kGpuScratch_SurfaceTyp e) { 547 if (surfaceType == kGpu_SurfaceType || surfaceType == kGpuScratch_SurfaceTyp e) {
547 REPORTER_ASSERT(reporter, texture); 548 REPORTER_ASSERT(reporter, texture);
548 REPORTER_ASSERT(reporter, 0 != texture->getTextureHandle()); 549 REPORTER_ASSERT(reporter, 0 != texture->getTextureHandle());
549 } else { 550 } else {
550 REPORTER_ASSERT(reporter, NULL == texture); 551 REPORTER_ASSERT(reporter, NULL == texture);
551 } 552 }
552 surface->notifyContentWillChange(SkSurface::kDiscard_ContentChangeMode); 553 surface->notifyContentWillChange(SkSurface::kDiscard_ContentChangeMode);
553 REPORTER_ASSERT(reporter, image->getTexture() == texture); 554 REPORTER_ASSERT(reporter, as_IB(image)->getTexture() == texture);
554 } 555 }
555 556
556 #include "GrGpuResourcePriv.h" 557 #include "GrGpuResourcePriv.h"
557 #include "SkGpuDevice.h" 558 #include "SkGpuDevice.h"
558 #include "SkImage_Gpu.h" 559 #include "SkImage_Gpu.h"
559 #include "SkSurface_Gpu.h" 560 #include "SkSurface_Gpu.h"
560 561
561 SkSurface::Budgeted is_budgeted(SkSurface* surf) { 562 SkSurface::Budgeted is_budgeted(SkSurface* surf) {
562 return ((SkSurface_Gpu*)surf)->getDevice()->accessRenderTarget()->resourcePr iv().isBudgeted() ? 563 return ((SkSurface_Gpu*)surf)->getDevice()->accessRenderTarget()->resourcePr iv().isBudgeted() ?
563 SkSurface::kYes_Budgeted : SkSurface::kNo_Budgeted; 564 SkSurface::kYes_Budgeted : SkSurface::kNo_Budgeted;
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
736 // Now lets jam new colors into our "external" texture, and see if the image s notice 737 // Now lets jam new colors into our "external" texture, and see if the image s notice
737 const SkPMColor expected1 = SkPreMultiplyColor(SK_ColorBLUE); 738 const SkPMColor expected1 = SkPreMultiplyColor(SK_ColorBLUE);
738 sk_memset32(storage, expected1, w * h); 739 sk_memset32(storage, expected1, w * h);
739 tex->writePixels(0, 0, w, h, kSkia8888_GrPixelConfig, storage, GrContext::kF lushWrites_PixelOp); 740 tex->writePixels(0, 0, w, h, kSkia8888_GrPixelConfig, storage, GrContext::kF lushWrites_PixelOp);
740 741
741 // We expect the ref'd image to see the new color, but cpy'd one should stil l see the old color 742 // We expect the ref'd image to see the new color, but cpy'd one should stil l see the old color
742 test_image_color(reporter, refImg, expected1); 743 test_image_color(reporter, refImg, expected1);
743 test_image_color(reporter, cpyImg, expected0); 744 test_image_color(reporter, cpyImg, expected0);
744 } 745 }
745 #endif 746 #endif
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