| 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" |
| 11 #include "SkColorFilter.h" | 11 #include "SkColorFilter.h" |
| 12 #include "SkReadBuffer.h" | 12 #include "SkReadBuffer.h" |
| 13 #include "SkWriteBuffer.h" | 13 #include "SkWriteBuffer.h" |
| 14 #include "SkMask.h" | 14 #include "SkMask.h" |
| 15 #include "SkMaskFilter.h" | 15 #include "SkMaskFilter.h" |
| 16 #include "SkString.h" | 16 #include "SkString.h" |
| 17 #include "SkTLazy.h" | 17 #include "SkTLazy.h" |
| 18 #include "SkUtils.h" | 18 #include "SkUtils.h" |
| 19 #include "SkXfermode.h" | 19 #include "SkXfermode.h" |
| 20 #include "SkXfermodeInterpretation.h" | 20 #include "SkXfermodeInterpretation.h" |
| 21 | 21 |
| 22 // define this for testing srgb blits | 22 // define this for testing srgb blits |
| 23 //#define SK_SUPPORT_SRGB_RASTER | 23 //#define SK_FORCE_PM4f_FOR_L32_BLITS |
| 24 | |
| 25 #ifdef SK_SUPPORT_SRGB_RASTER | |
| 26 #define ALLOW_SRGB true | |
| 27 #else | |
| 28 #define ALLOW_SRGB false | |
| 29 #endif | |
| 30 | 24 |
| 31 SkBlitter::~SkBlitter() {} | 25 SkBlitter::~SkBlitter() {} |
| 32 | 26 |
| 33 bool SkBlitter::isNullBlitter() const { return false; } | 27 bool SkBlitter::isNullBlitter() const { return false; } |
| 34 | 28 |
| 35 bool SkBlitter::resetShaderContext(const SkShader::ContextRec&) { | 29 bool SkBlitter::resetShaderContext(const SkShader::ContextRec&) { |
| 36 return true; | 30 return true; |
| 37 } | 31 } |
| 38 | 32 |
| 39 SkShader::Context* SkBlitter::getShaderContext() const { | 33 SkShader::Context* SkBlitter::getShaderContext() const { |
| (...skipping 866 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 906 } else { | 900 } else { |
| 907 blitter = allocator->createT<SkA8_Blitter>(device, *paint); | 901 blitter = allocator->createT<SkA8_Blitter>(device, *paint); |
| 908 } | 902 } |
| 909 break; | 903 break; |
| 910 | 904 |
| 911 case kRGB_565_SkColorType: | 905 case kRGB_565_SkColorType: |
| 912 blitter = SkBlitter_ChooseD565(device, *paint, shaderContext, alloca
tor); | 906 blitter = SkBlitter_ChooseD565(device, *paint, shaderContext, alloca
tor); |
| 913 break; | 907 break; |
| 914 | 908 |
| 915 case kN32_SkColorType: | 909 case kN32_SkColorType: |
| 916 if (shader) { | 910 #ifdef SK_FORCE_PM4f_FOR_L32_BLITS |
| 917 if (shaderContext->supports4f() && ALLOW_SRGB) { | 911 if (true) |
| 918 blitter = allocator->createT<SkARGB32_Shader4f_Blitter>( | 912 #else |
| 919 device, *paint
, shaderContext); | 913 if (device.info().isSRGB()) |
| 914 #endif |
| 915 { |
| 916 blitter = SkBlitter_ARGB32_Create(device, *paint, shaderContext,
allocator); |
| 917 } else { |
| 918 if (shader) { |
| 919 blitter = allocator->createT<SkARGB32_Shader_Blitter>( |
| 920 device, *paint, shaderContext); |
| 921 } else if (paint->getColor() == SK_ColorBLACK) { |
| 922 blitter = allocator->createT<SkARGB32_Black_Blitter>(device,
*paint); |
| 923 } else if (paint->getAlpha() == 0xFF) { |
| 924 blitter = allocator->createT<SkARGB32_Opaque_Blitter>(device
, *paint); |
| 920 } else { | 925 } else { |
| 921 blitter = allocator->createT<SkARGB32_Shader_Blitter>( | 926 blitter = allocator->createT<SkARGB32_Blitter>(device, *pain
t); |
| 922 device, *paint, shaderContext); | |
| 923 } | 927 } |
| 924 } else if (paint->getColor() == SK_ColorBLACK) { | |
| 925 blitter = allocator->createT<SkARGB32_Black_Blitter>(device, *pa
int); | |
| 926 } else if (paint->getAlpha() == 0xFF) { | |
| 927 blitter = allocator->createT<SkARGB32_Opaque_Blitter>(device, *p
aint); | |
| 928 } else { | |
| 929 blitter = allocator->createT<SkARGB32_Blitter>(device, *paint); | |
| 930 } | 928 } |
| 931 break; | 929 break; |
| 932 | 930 |
| 931 case kRGBA_F16_SkColorType: |
| 932 // kU16_SkColorType: |
| 933 blitter = SkBlitter_ARGB64_Create(device, *paint, shaderContext, all
ocator); |
| 934 break; |
| 935 |
| 933 default: | 936 default: |
| 934 SkDEBUGFAIL("unsupported device config"); | 937 SkDEBUGFAIL("unsupported device config"); |
| 935 blitter = allocator->createT<SkNullBlitter>(); | 938 blitter = allocator->createT<SkNullBlitter>(); |
| 936 break; | 939 break; |
| 937 } | 940 } |
| 938 | 941 |
| 939 if (shader3D) { | 942 if (shader3D) { |
| 940 SkBlitter* innerBlitter = blitter; | 943 SkBlitter* innerBlitter = blitter; |
| 941 // innerBlitter was allocated by allocator, which will delete it. | 944 // innerBlitter was allocated by allocator, which will delete it. |
| 942 // We know shaderContext or its proxies is of type Sk3DShaderContext, so
we need to | 945 // We know shaderContext or its proxies is of type Sk3DShaderContext, so
we need to |
| (...skipping 22 matching lines...) Expand all Loading... |
| 965 SkShaderBlitter::SkShaderBlitter(const SkPixmap& device, const SkPaint& paint, | 968 SkShaderBlitter::SkShaderBlitter(const SkPixmap& device, const SkPaint& paint, |
| 966 SkShader::Context* shaderContext) | 969 SkShader::Context* shaderContext) |
| 967 : INHERITED(device) | 970 : INHERITED(device) |
| 968 , fShader(paint.getShader()) | 971 , fShader(paint.getShader()) |
| 969 , fShaderContext(shaderContext) { | 972 , fShaderContext(shaderContext) { |
| 970 SkASSERT(fShader); | 973 SkASSERT(fShader); |
| 971 SkASSERT(fShaderContext); | 974 SkASSERT(fShaderContext); |
| 972 | 975 |
| 973 fShader->ref(); | 976 fShader->ref(); |
| 974 fShaderFlags = fShaderContext->getFlags(); | 977 fShaderFlags = fShaderContext->getFlags(); |
| 978 fConstInY = SkToBool(fShaderFlags & SkShader::kConstInY32_Flag); |
| 975 } | 979 } |
| 976 | 980 |
| 977 SkShaderBlitter::~SkShaderBlitter() { | 981 SkShaderBlitter::~SkShaderBlitter() { |
| 978 fShader->unref(); | 982 fShader->unref(); |
| 979 } | 983 } |
| 980 | 984 |
| 981 bool SkShaderBlitter::resetShaderContext(const SkShader::ContextRec& rec) { | 985 bool SkShaderBlitter::resetShaderContext(const SkShader::ContextRec& rec) { |
| 982 // Only destroy the old context if we have a new one. We need to ensure to h
ave a | 986 // Only destroy the old context if we have a new one. We need to ensure to h
ave a |
| 983 // live context in fShaderContext because the storage is owned by an SkSmall
Allocator | 987 // live context in fShaderContext because the storage is owned by an SkSmall
Allocator |
| 984 // outside of this class. | 988 // outside of this class. |
| 985 // The new context will be of the same size as the old one because we use th
e same | 989 // The new context will be of the same size as the old one because we use th
e same |
| 986 // shader to create it. It is therefore safe to re-use the storage. | 990 // shader to create it. It is therefore safe to re-use the storage. |
| 987 fShaderContext->~Context(); | 991 fShaderContext->~Context(); |
| 988 SkShader::Context* ctx = fShader->createContext(rec, (void*)fShaderContext); | 992 SkShader::Context* ctx = fShader->createContext(rec, (void*)fShaderContext); |
| 989 if (nullptr == ctx) { | 993 if (nullptr == ctx) { |
| 990 // Need a valid context in fShaderContext's storage, so we can later (or
our caller) call | 994 // Need a valid context in fShaderContext's storage, so we can later (or
our caller) call |
| 991 // the in-place destructor. | 995 // the in-place destructor. |
| 992 new (fShaderContext) SkZeroShaderContext(*fShader, rec); | 996 new (fShaderContext) SkZeroShaderContext(*fShader, rec); |
| 993 return false; | 997 return false; |
| 994 } | 998 } |
| 995 return true; | 999 return true; |
| 996 } | 1000 } |
| OLD | NEW |