| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2012 Google Inc. | 3 * Copyright 2012 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 "Test.h" | 8 #include "Test.h" |
| 9 #include "SkBitmap.h" | 9 #include "SkBitmap.h" |
| 10 #include "SkBitmapDevice.h" | 10 #include "SkBitmapDevice.h" |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 MockSurface(int width, int height) : SkSurface_Base(width, height) { | 50 MockSurface(int width, int height) : SkSurface_Base(width, height) { |
| 51 clearCounts(); | 51 clearCounts(); |
| 52 fBitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height); | 52 fBitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height); |
| 53 fBitmap.allocPixels(); | 53 fBitmap.allocPixels(); |
| 54 } | 54 } |
| 55 | 55 |
| 56 virtual SkCanvas* onNewCanvas() SK_OVERRIDE { | 56 virtual SkCanvas* onNewCanvas() SK_OVERRIDE { |
| 57 return SkNEW_ARGS(SkCanvas, (fBitmap)); | 57 return SkNEW_ARGS(SkCanvas, (fBitmap)); |
| 58 } | 58 } |
| 59 | 59 |
| 60 virtual SkSurface* onNewSurface(const SkImage::Info&) SK_OVERRIDE { | 60 virtual SkSurface* onNewSurface(const SkImageInfo&) SK_OVERRIDE { |
| 61 return NULL; | 61 return NULL; |
| 62 } | 62 } |
| 63 | 63 |
| 64 virtual SkImage* onNewImageSnapshot() SK_OVERRIDE { | 64 virtual SkImage* onNewImageSnapshot() SK_OVERRIDE { |
| 65 return SkNewImageFromBitmap(fBitmap, true); | 65 return SkNewImageFromBitmap(fBitmap, true); |
| 66 } | 66 } |
| 67 | 67 |
| 68 virtual void onCopyOnWrite(ContentChangeMode mode) SK_OVERRIDE { | 68 virtual void onCopyOnWrite(ContentChangeMode mode) SK_OVERRIDE { |
| 69 if (mode == SkSurface::kDiscard_ContentChangeMode) { | 69 if (mode == SkSurface::kDiscard_ContentChangeMode) { |
| 70 fDiscardCount++; | 70 fDiscardCount++; |
| (...skipping 614 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 685 typedef void* PixelPtr; | 685 typedef void* PixelPtr; |
| 686 // Returns an opaque pointer which, either points to a GrTexture or RAM pixel | 686 // Returns an opaque pointer which, either points to a GrTexture or RAM pixel |
| 687 // buffer. Used to test pointer equality do determine whether a surface points | 687 // buffer. Used to test pointer equality do determine whether a surface points |
| 688 // to the same pixel data storage as before. | 688 // to the same pixel data storage as before. |
| 689 static PixelPtr getSurfacePixelPtr(SkSurface* surface, bool useGpu) { | 689 static PixelPtr getSurfacePixelPtr(SkSurface* surface, bool useGpu) { |
| 690 return useGpu ? surface->getCanvas()->getDevice()->accessBitmap(false).getTe
xture() : | 690 return useGpu ? surface->getCanvas()->getDevice()->accessBitmap(false).getTe
xture() : |
| 691 surface->getCanvas()->getDevice()->accessBitmap(false).getPixels(); | 691 surface->getCanvas()->getDevice()->accessBitmap(false).getPixels(); |
| 692 } | 692 } |
| 693 | 693 |
| 694 static void TestDeferredCanvasSurface(skiatest::Reporter* reporter, GrContextFac
tory* factory) { | 694 static void TestDeferredCanvasSurface(skiatest::Reporter* reporter, GrContextFac
tory* factory) { |
| 695 SkImage::Info imageSpec = { | 695 SkImageInfo imageSpec = { |
| 696 10, // width | 696 10, // width |
| 697 10, // height | 697 10, // height |
| 698 SkImage::kPMColor_ColorType, | 698 kPMColor_SkColorType, |
| 699 kPremul_SkAlphaType | 699 kPremul_SkAlphaType |
| 700 }; | 700 }; |
| 701 SkSurface* surface; | 701 SkSurface* surface; |
| 702 bool useGpu = NULL != factory; | 702 bool useGpu = NULL != factory; |
| 703 #if SK_SUPPORT_GPU | 703 #if SK_SUPPORT_GPU |
| 704 if (useGpu) { | 704 if (useGpu) { |
| 705 GrContext* context = factory->get(GrContextFactory::kNative_GLContextTyp
e); | 705 GrContext* context = factory->get(GrContextFactory::kNative_GLContextTyp
e); |
| 706 surface = SkSurface::NewRenderTarget(context, imageSpec); | 706 surface = SkSurface::NewRenderTarget(context, imageSpec); |
| 707 } else { | 707 } else { |
| 708 surface = SkSurface::NewRaster(imageSpec); | 708 surface = SkSurface::NewRaster(imageSpec); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 752 canvas->clear(SK_ColorWHITE); | 752 canvas->clear(SK_ColorWHITE); |
| 753 canvas->flush(); | 753 canvas->flush(); |
| 754 PixelPtr pixels4 = getSurfacePixelPtr(surface, useGpu); | 754 PixelPtr pixels4 = getSurfacePixelPtr(surface, useGpu); |
| 755 canvas->drawPaint(paint); | 755 canvas->drawPaint(paint); |
| 756 canvas->flush(); | 756 canvas->flush(); |
| 757 PixelPtr pixels5 = getSurfacePixelPtr(surface, useGpu); | 757 PixelPtr pixels5 = getSurfacePixelPtr(surface, useGpu); |
| 758 REPORTER_ASSERT(reporter, pixels4 == pixels5); | 758 REPORTER_ASSERT(reporter, pixels4 == pixels5); |
| 759 } | 759 } |
| 760 | 760 |
| 761 static void TestDeferredCanvasSetSurface(skiatest::Reporter* reporter, GrContext
Factory* factory) { | 761 static void TestDeferredCanvasSetSurface(skiatest::Reporter* reporter, GrContext
Factory* factory) { |
| 762 SkImage::Info imageSpec = { | 762 SkImageInfo imageSpec = { |
| 763 10, // width | 763 10, // width |
| 764 10, // height | 764 10, // height |
| 765 SkImage::kPMColor_ColorType, | 765 kPMColor_SkColorType, |
| 766 kPremul_SkAlphaType | 766 kPremul_SkAlphaType |
| 767 }; | 767 }; |
| 768 SkSurface* surface; | 768 SkSurface* surface; |
| 769 SkSurface* alternateSurface; | 769 SkSurface* alternateSurface; |
| 770 bool useGpu = NULL != factory; | 770 bool useGpu = NULL != factory; |
| 771 #if SK_SUPPORT_GPU | 771 #if SK_SUPPORT_GPU |
| 772 if (useGpu) { | 772 if (useGpu) { |
| 773 GrContext* context = factory->get(GrContextFactory::kNative_GLContextTyp
e); | 773 GrContext* context = factory->get(GrContextFactory::kNative_GLContextTyp
e); |
| 774 surface = SkSurface::NewRenderTarget(context, imageSpec); | 774 surface = SkSurface::NewRenderTarget(context, imageSpec); |
| 775 alternateSurface = SkSurface::NewRenderTarget(context, imageSpec); | 775 alternateSurface = SkSurface::NewRenderTarget(context, imageSpec); |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 839 TestDeferredCanvasSurface(reporter, NULL); | 839 TestDeferredCanvasSurface(reporter, NULL); |
| 840 TestDeferredCanvasSetSurface(reporter, NULL); | 840 TestDeferredCanvasSetSurface(reporter, NULL); |
| 841 if (NULL != factory) { | 841 if (NULL != factory) { |
| 842 TestDeferredCanvasSurface(reporter, factory); | 842 TestDeferredCanvasSurface(reporter, factory); |
| 843 TestDeferredCanvasSetSurface(reporter, factory); | 843 TestDeferredCanvasSetSurface(reporter, factory); |
| 844 } | 844 } |
| 845 } | 845 } |
| 846 | 846 |
| 847 #include "TestClassDef.h" | 847 #include "TestClassDef.h" |
| 848 DEFINE_GPUTESTCLASS("DeferredCanvas", TestDeferredCanvasClass, TestDeferredCanva
s) | 848 DEFINE_GPUTESTCLASS("DeferredCanvas", TestDeferredCanvasClass, TestDeferredCanva
s) |
| OLD | NEW |