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

Side by Side Diff: tests/DeferredCanvasTest.cpp

Issue 355193006: stop calling SkCanvas::getDevice (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 5 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
OLDNEW
1 /* 1 /*
2 * Copyright 2012 Google Inc. 2 * Copyright 2012 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 "../src/image/SkImagePriv.h" 8 #include "../src/image/SkImagePriv.h"
9 #include "../src/image/SkSurface_Base.h" 9 #include "../src/image/SkSurface_Base.h"
10 #include "SkBitmap.h" 10 #include "SkBitmap.h"
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 SkBitmap bitmap; 42 SkBitmap bitmap;
43 bitmap.installPixels(SkImageInfo::MakeN32Premul(1, 1), &pixel, 4); 43 bitmap.installPixels(SkImageInfo::MakeN32Premul(1, 1), &pixel, 4);
44 SkCanvas canvas(bitmap); 44 SkCanvas canvas(bitmap);
45 45
46 SkPaint paint; 46 SkPaint paint;
47 paint.setXfermodeMode(SkXfermode::kSrc_Mode); 47 paint.setXfermodeMode(SkXfermode::kSrc_Mode);
48 surface->draw(&canvas, -SkIntToScalar(x), -SkIntToScalar(y), &paint); 48 surface->draw(&canvas, -SkIntToScalar(x), -SkIntToScalar(y), &paint);
49 return pixel; 49 return pixel;
50 } 50 }
51 51
52 static void TestDeferredCanvasBitmapAccess(skiatest::Reporter* reporter) {
53 SkBitmap store;
54
55 SkAutoTUnref<SkSurface> surface(createSurface(0xFFFFFFFF));
56 SkAutoTUnref<SkDeferredCanvas> canvas(SkDeferredCanvas::Create(surface.get() ));
57
58 canvas->clear(0x00000000);
59
60 // verify that the clear() was deferred
61 REPORTER_ASSERT(reporter, 0xFFFFFFFF == read_pixel(surface, 0, 0));
62
63 SkBitmap accessed = canvas->getDevice()->accessBitmap(false);
64
65 // verify that clear was executed
66 REPORTER_ASSERT(reporter, 0 == read_pixel(surface, 0, 0));
67 }
68
69 class MockSurface : public SkSurface_Base { 52 class MockSurface : public SkSurface_Base {
70 public: 53 public:
71 MockSurface(int width, int height) : SkSurface_Base(width, height) { 54 MockSurface(int width, int height) : SkSurface_Base(width, height) {
72 clearCounts(); 55 clearCounts();
73 fBitmap.allocN32Pixels(width, height); 56 fBitmap.allocN32Pixels(width, height);
74 } 57 }
75 58
76 virtual SkCanvas* onNewCanvas() SK_OVERRIDE { 59 virtual SkCanvas* onNewCanvas() SK_OVERRIDE {
77 return SkNEW_ARGS(SkCanvas, (fBitmap)); 60 return SkNEW_ARGS(SkCanvas, (fBitmap));
78 } 61 }
(...skipping 595 matching lines...) Expand 10 before | Expand all | Expand 10 after
674 { 657 {
675 SkAutoTUnref<SkDeferredCanvas> canvas(SkDeferredCanvas::Create(surface.g et())); 658 SkAutoTUnref<SkDeferredCanvas> canvas(SkDeferredCanvas::Create(surface.g et()));
676 canvas->setBitmapSizeThreshold(40001); 659 canvas->setBitmapSizeThreshold(40001);
677 canvas->drawBitmap(sourceImage, 0, 0, NULL); 660 canvas->drawBitmap(sourceImage, 0, 0, NULL);
678 size_t newBytesAllocated = canvas->storageAllocatedForRecording(); 661 size_t newBytesAllocated = canvas->storageAllocatedForRecording();
679 REPORTER_ASSERT(reporter, newBytesAllocated > 0); 662 REPORTER_ASSERT(reporter, newBytesAllocated > 0);
680 } 663 }
681 } 664 }
682 665
683 666
684 typedef void* PixelPtr; 667 typedef const void* PixelPtr;
685 // Returns an opaque pointer which, either points to a GrTexture or RAM pixel 668 // Returns an opaque pointer which, either points to a GrTexture or RAM pixel
686 // buffer. Used to test pointer equality do determine whether a surface points 669 // buffer. Used to test pointer equality do determine whether a surface points
687 // to the same pixel data storage as before. 670 // to the same pixel data storage as before.
robertphillips 2014/06/30 13:36:20 get_surface_pixelptr ?
reed1 2014/06/30 14:33:12 Done.
688 static PixelPtr getSurfacePixelPtr(SkSurface* surface, bool useGpu) { 671 static PixelPtr getSurfacePixelPtr(SkSurface* surface, bool useGpu) {
689 return useGpu ? surface->getCanvas()->getDevice()->accessBitmap(false).getTe xture() : 672 if (useGpu) {
690 surface->getCanvas()->getDevice()->accessBitmap(false).getPixels(); 673 return surface->getCanvas()->internal_private_accessTopLayerRenderTarget ()->asTexture();
674 } else {
675 return surface->peekPixels(NULL, NULL);
676 }
691 } 677 }
692 678
693 static void TestDeferredCanvasSurface(skiatest::Reporter* reporter, GrContextFac tory* factory) { 679 static void TestDeferredCanvasSurface(skiatest::Reporter* reporter, GrContextFac tory* factory) {
694 SkImageInfo imageSpec = SkImageInfo::MakeN32Premul(10, 10); 680 SkImageInfo imageSpec = SkImageInfo::MakeN32Premul(10, 10);
695 SkSurface* surface; 681 SkSurface* surface;
696 bool useGpu = NULL != factory; 682 bool useGpu = NULL != factory;
697 #if SK_SUPPORT_GPU 683 #if SK_SUPPORT_GPU
698 if (useGpu) { 684 if (useGpu) {
699 GrContext* context = factory->get(GrContextFactory::kNative_GLContextTyp e); 685 GrContext* context = factory->get(GrContextFactory::kNative_GLContextTyp e);
700 if (NULL == context) { 686 if (NULL == context) {
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
814 // After spawning a compatible canvas: 800 // After spawning a compatible canvas:
815 // 1) Verify that secondary canvas is usable and does not report to the noti fication client. 801 // 1) Verify that secondary canvas is usable and does not report to the noti fication client.
816 surface->getCanvas()->drawRect(rect, paint); 802 surface->getCanvas()->drawRect(rect, paint);
817 REPORTER_ASSERT(reporter, notificationCounter.fStorageAllocatedChangedCount == 0); 803 REPORTER_ASSERT(reporter, notificationCounter.fStorageAllocatedChangedCount == 0);
818 // 2) Verify that original canvas is usable and still reports to the notific ation client. 804 // 2) Verify that original canvas is usable and still reports to the notific ation client.
819 canvas->drawRect(rect, paint); 805 canvas->drawRect(rect, paint);
820 REPORTER_ASSERT(reporter, notificationCounter.fStorageAllocatedChangedCount == 1); 806 REPORTER_ASSERT(reporter, notificationCounter.fStorageAllocatedChangedCount == 1);
821 } 807 }
822 808
823 DEF_TEST(DeferredCanvas_CPU, reporter) { 809 DEF_TEST(DeferredCanvas_CPU, reporter) {
824 TestDeferredCanvasBitmapAccess(reporter);
825 TestDeferredCanvasFlush(reporter); 810 TestDeferredCanvasFlush(reporter);
826 TestDeferredCanvasSilentFlush(reporter); 811 TestDeferredCanvasSilentFlush(reporter);
827 TestDeferredCanvasFreshFrame(reporter); 812 TestDeferredCanvasFreshFrame(reporter);
828 TestDeferredCanvasMemoryLimit(reporter); 813 TestDeferredCanvasMemoryLimit(reporter);
829 TestDeferredCanvasBitmapCaching(reporter); 814 TestDeferredCanvasBitmapCaching(reporter);
830 TestDeferredCanvasSkip(reporter); 815 TestDeferredCanvasSkip(reporter);
831 TestDeferredCanvasBitmapShaderNoLeak(reporter); 816 TestDeferredCanvasBitmapShaderNoLeak(reporter);
832 TestDeferredCanvasBitmapSizeThreshold(reporter); 817 TestDeferredCanvasBitmapSizeThreshold(reporter);
833 TestDeferredCanvasCreateCompatibleDevice(reporter); 818 TestDeferredCanvasCreateCompatibleDevice(reporter);
834 TestDeferredCanvasWritePixelsToSurface(reporter); 819 TestDeferredCanvasWritePixelsToSurface(reporter);
835 TestDeferredCanvasSurface(reporter, NULL); 820 TestDeferredCanvasSurface(reporter, NULL);
836 TestDeferredCanvasSetSurface(reporter, NULL); 821 TestDeferredCanvasSetSurface(reporter, NULL);
837 } 822 }
838 823
839 DEF_GPUTEST(DeferredCanvas_GPU, reporter, factory) { 824 DEF_GPUTEST(DeferredCanvas_GPU, reporter, factory) {
840 if (factory != NULL) { 825 if (factory != NULL) {
841 TestDeferredCanvasSurface(reporter, factory); 826 TestDeferredCanvasSurface(reporter, factory);
842 TestDeferredCanvasSetSurface(reporter, factory); 827 TestDeferredCanvasSetSurface(reporter, factory);
843 } 828 }
844 } 829 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698