| OLD | NEW |
| 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 674 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 SkImageInfo imageSpec = { | 695 SkImageInfo imageSpec = SkImageInfo::MakeN32Premul(10, 10); |
| 696 10, // width | |
| 697 10, // height | |
| 698 kPMColor_SkColorType, | |
| 699 kPremul_SkAlphaType | |
| 700 }; | |
| 701 SkSurface* surface; | 696 SkSurface* surface; |
| 702 bool useGpu = NULL != factory; | 697 bool useGpu = NULL != factory; |
| 703 #if SK_SUPPORT_GPU | 698 #if SK_SUPPORT_GPU |
| 704 if (useGpu) { | 699 if (useGpu) { |
| 705 GrContext* context = factory->get(GrContextFactory::kNative_GLContextTyp
e); | 700 GrContext* context = factory->get(GrContextFactory::kNative_GLContextTyp
e); |
| 706 if (NULL == context) { | 701 if (NULL == context) { |
| 707 return; | 702 return; |
| 708 } | 703 } |
| 709 | 704 |
| 710 surface = SkSurface::NewRenderTarget(context, imageSpec); | 705 surface = SkSurface::NewRenderTarget(context, imageSpec); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 756 canvas->clear(SK_ColorWHITE); | 751 canvas->clear(SK_ColorWHITE); |
| 757 canvas->flush(); | 752 canvas->flush(); |
| 758 PixelPtr pixels4 = getSurfacePixelPtr(surface, useGpu); | 753 PixelPtr pixels4 = getSurfacePixelPtr(surface, useGpu); |
| 759 canvas->drawPaint(paint); | 754 canvas->drawPaint(paint); |
| 760 canvas->flush(); | 755 canvas->flush(); |
| 761 PixelPtr pixels5 = getSurfacePixelPtr(surface, useGpu); | 756 PixelPtr pixels5 = getSurfacePixelPtr(surface, useGpu); |
| 762 REPORTER_ASSERT(reporter, pixels4 == pixels5); | 757 REPORTER_ASSERT(reporter, pixels4 == pixels5); |
| 763 } | 758 } |
| 764 | 759 |
| 765 static void TestDeferredCanvasSetSurface(skiatest::Reporter* reporter, GrContext
Factory* factory) { | 760 static void TestDeferredCanvasSetSurface(skiatest::Reporter* reporter, GrContext
Factory* factory) { |
| 766 SkImageInfo imageSpec = { | 761 SkImageInfo imageSpec = SkImageInfo::MakeN32Premul(10, 10); |
| 767 10, // width | |
| 768 10, // height | |
| 769 kPMColor_SkColorType, | |
| 770 kPremul_SkAlphaType | |
| 771 }; | |
| 772 SkSurface* surface; | 762 SkSurface* surface; |
| 773 SkSurface* alternateSurface; | 763 SkSurface* alternateSurface; |
| 774 bool useGpu = NULL != factory; | 764 bool useGpu = NULL != factory; |
| 775 #if SK_SUPPORT_GPU | 765 #if SK_SUPPORT_GPU |
| 776 if (useGpu) { | 766 if (useGpu) { |
| 777 GrContext* context = factory->get(GrContextFactory::kNative_GLContextTyp
e); | 767 GrContext* context = factory->get(GrContextFactory::kNative_GLContextTyp
e); |
| 778 if (NULL == context) { | 768 if (NULL == context) { |
| 779 return; | 769 return; |
| 780 } | 770 } |
| 781 surface = SkSurface::NewRenderTarget(context, imageSpec); | 771 surface = SkSurface::NewRenderTarget(context, imageSpec); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 842 TestDeferredCanvasBitmapSizeThreshold(reporter); | 832 TestDeferredCanvasBitmapSizeThreshold(reporter); |
| 843 TestDeferredCanvasCreateCompatibleDevice(reporter); | 833 TestDeferredCanvasCreateCompatibleDevice(reporter); |
| 844 TestDeferredCanvasWritePixelsToSurface(reporter); | 834 TestDeferredCanvasWritePixelsToSurface(reporter); |
| 845 TestDeferredCanvasSurface(reporter, NULL); | 835 TestDeferredCanvasSurface(reporter, NULL); |
| 846 TestDeferredCanvasSetSurface(reporter, NULL); | 836 TestDeferredCanvasSetSurface(reporter, NULL); |
| 847 if (NULL != factory) { | 837 if (NULL != factory) { |
| 848 TestDeferredCanvasSurface(reporter, factory); | 838 TestDeferredCanvasSurface(reporter, factory); |
| 849 TestDeferredCanvasSetSurface(reporter, factory); | 839 TestDeferredCanvasSetSurface(reporter, factory); |
| 850 } | 840 } |
| 851 } | 841 } |
| OLD | NEW |