OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2006 The Android Open Source Project | 2 * Copyright 2006 The Android Open Source Project |
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 "SkBlitter.h" | 8 #include "SkBlitter.h" |
9 #include "SkAntiRun.h" | 9 #include "SkAntiRun.h" |
10 #include "SkColor.h" | 10 #include "SkColor.h" |
(...skipping 771 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
782 private: | 782 private: |
783 // Both pointers are unowned. They will be deleted by SkSmallAllocator. | 783 // Both pointers are unowned. They will be deleted by SkSmallAllocator. |
784 SkBlitter* fProxy; | 784 SkBlitter* fProxy; |
785 SkShader::Context* fShaderContext; | 785 SkShader::Context* fShaderContext; |
786 }; | 786 }; |
787 | 787 |
788 /////////////////////////////////////////////////////////////////////////////// | 788 /////////////////////////////////////////////////////////////////////////////// |
789 | 789 |
790 #include "SkCoreBlitters.h" | 790 #include "SkCoreBlitters.h" |
791 | 791 |
| 792 SkShader::ContextRec::DstType SkBlitter::PreferredShaderDest(const SkImageInfo&
dstInfo) { |
| 793 #ifdef SK_FORCE_PM4f_FOR_L32_BLITS |
| 794 return SkShader::ContextRec::kPM4f_DstType; |
| 795 #else |
| 796 return (dstInfo.isSRGB() || dstInfo.colorType() == kRGBA_F16_SkColorType) |
| 797 ? SkShader::ContextRec::kPM4f_DstType |
| 798 : SkShader::ContextRec::kPMColor_DstType; |
| 799 #endif |
| 800 } |
| 801 |
792 SkBlitter* SkBlitter::Choose(const SkPixmap& device, | 802 SkBlitter* SkBlitter::Choose(const SkPixmap& device, |
793 const SkMatrix& matrix, | 803 const SkMatrix& matrix, |
794 const SkPaint& origPaint, | 804 const SkPaint& origPaint, |
795 SkTBlitterAllocator* allocator, | 805 SkTBlitterAllocator* allocator, |
796 bool drawCoverage) { | 806 bool drawCoverage) { |
797 SkASSERT(allocator != nullptr); | 807 SkASSERT(allocator != nullptr); |
798 | 808 |
799 // which check, in case we're being called by a client with a dummy device | 809 // which check, in case we're being called by a client with a dummy device |
800 // (e.g. they have a bounder that always aborts the draw) | 810 // (e.g. they have a bounder that always aborts the draw) |
801 if (kUnknown_SkColorType == device.colorType() || | 811 if (kUnknown_SkColorType == device.colorType() || |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
868 paint.writable()->setShader(shader)->unref(); | 878 paint.writable()->setShader(shader)->unref(); |
869 // blitters should ignore the presence/absence of a filter, since | 879 // blitters should ignore the presence/absence of a filter, since |
870 // if there is one, the shader will take care of it. | 880 // if there is one, the shader will take care of it. |
871 } | 881 } |
872 | 882 |
873 /* | 883 /* |
874 * We create a SkShader::Context object, and store it on the blitter. | 884 * We create a SkShader::Context object, and store it on the blitter. |
875 */ | 885 */ |
876 SkShader::Context* shaderContext = nullptr; | 886 SkShader::Context* shaderContext = nullptr; |
877 if (shader) { | 887 if (shader) { |
878 SkShader::ContextRec rec(*paint, matrix, nullptr); | 888 const SkShader::ContextRec rec(*paint, matrix, nullptr, |
| 889 PreferredShaderDest(device.info())); |
879 size_t contextSize = shader->contextSize(rec); | 890 size_t contextSize = shader->contextSize(rec); |
880 if (contextSize) { | 891 if (contextSize) { |
881 // Try to create the ShaderContext | 892 // Try to create the ShaderContext |
882 void* storage = allocator->reserveT<SkShader::Context>(contextSize); | 893 void* storage = allocator->reserveT<SkShader::Context>(contextSize); |
883 shaderContext = shader->createContext(rec, storage); | 894 shaderContext = shader->createContext(rec, storage); |
884 if (!shaderContext) { | 895 if (!shaderContext) { |
885 allocator->freeLast(); | 896 allocator->freeLast(); |
886 return allocator->createT<SkNullBlitter>(); | 897 return allocator->createT<SkNullBlitter>(); |
887 } | 898 } |
888 SkASSERT(shaderContext); | 899 SkASSERT(shaderContext); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
954 } | 965 } |
955 return blitter; | 966 return blitter; |
956 } | 967 } |
957 | 968 |
958 /////////////////////////////////////////////////////////////////////////////// | 969 /////////////////////////////////////////////////////////////////////////////// |
959 | 970 |
960 class SkZeroShaderContext : public SkShader::Context { | 971 class SkZeroShaderContext : public SkShader::Context { |
961 public: | 972 public: |
962 SkZeroShaderContext(const SkShader& shader, const SkShader::ContextRec& rec) | 973 SkZeroShaderContext(const SkShader& shader, const SkShader::ContextRec& rec) |
963 // Override rec with the identity matrix, so it is guaranteed to be inve
rtible. | 974 // Override rec with the identity matrix, so it is guaranteed to be inve
rtible. |
964 : INHERITED(shader, SkShader::ContextRec(*rec.fPaint, SkMatrix::I(), nul
lptr)) {} | 975 : INHERITED(shader, SkShader::ContextRec(*rec.fPaint, SkMatrix::I(), nul
lptr, |
| 976 rec.fPreferredDstType)) {} |
965 | 977 |
966 void shadeSpan(int x, int y, SkPMColor colors[], int count) override { | 978 void shadeSpan(int x, int y, SkPMColor colors[], int count) override { |
967 sk_bzero(colors, count * sizeof(SkPMColor)); | 979 sk_bzero(colors, count * sizeof(SkPMColor)); |
968 } | 980 } |
969 | 981 |
970 private: | 982 private: |
971 typedef SkShader::Context INHERITED; | 983 typedef SkShader::Context INHERITED; |
972 }; | 984 }; |
973 | 985 |
974 SkShaderBlitter::SkShaderBlitter(const SkPixmap& device, const SkPaint& paint, | 986 SkShaderBlitter::SkShaderBlitter(const SkPixmap& device, const SkPaint& paint, |
(...skipping 22 matching lines...) Expand all Loading... |
997 fShaderContext->~Context(); | 1009 fShaderContext->~Context(); |
998 SkShader::Context* ctx = fShader->createContext(rec, (void*)fShaderContext); | 1010 SkShader::Context* ctx = fShader->createContext(rec, (void*)fShaderContext); |
999 if (nullptr == ctx) { | 1011 if (nullptr == ctx) { |
1000 // Need a valid context in fShaderContext's storage, so we can later (or
our caller) call | 1012 // Need a valid context in fShaderContext's storage, so we can later (or
our caller) call |
1001 // the in-place destructor. | 1013 // the in-place destructor. |
1002 new (fShaderContext) SkZeroShaderContext(*fShader, rec); | 1014 new (fShaderContext) SkZeroShaderContext(*fShader, rec); |
1003 return false; | 1015 return false; |
1004 } | 1016 } |
1005 return true; | 1017 return true; |
1006 } | 1018 } |
OLD | NEW |