| 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 823 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 834 return kNormal_XferInterp; | 834 return kNormal_XferInterp; |
| 835 } | 835 } |
| 836 | 836 |
| 837 SkBlitter* SkBlitter::Choose(const SkBitmap& device, | 837 SkBlitter* SkBlitter::Choose(const SkBitmap& device, |
| 838 const SkMatrix& matrix, | 838 const SkMatrix& matrix, |
| 839 const SkPaint& origPaint, | 839 const SkPaint& origPaint, |
| 840 SkTBlitterAllocator* allocator, | 840 SkTBlitterAllocator* allocator, |
| 841 bool drawCoverage) { | 841 bool drawCoverage) { |
| 842 SkASSERT(allocator != NULL); | 842 SkASSERT(allocator != NULL); |
| 843 | 843 |
| 844 SkBlitter* blitter = NULL; | |
| 845 | |
| 846 // which check, in case we're being called by a client with a dummy device | 844 // which check, in case we're being called by a client with a dummy device |
| 847 // (e.g. they have a bounder that always aborts the draw) | 845 // (e.g. they have a bounder that always aborts the draw) |
| 848 if (kUnknown_SkColorType == device.colorType() || | 846 if (kUnknown_SkColorType == device.colorType() || |
| 849 (drawCoverage && (kAlpha_8_SkColorType != device.colorType()))) { | 847 (drawCoverage && (kAlpha_8_SkColorType != device.colorType()))) { |
| 850 blitter = allocator->createT<SkNullBlitter>(); | 848 return allocator->createT<SkNullBlitter>(); |
| 851 return blitter; | |
| 852 } | 849 } |
| 853 | 850 |
| 854 SkShader* shader = origPaint.getShader(); | 851 SkShader* shader = origPaint.getShader(); |
| 855 SkColorFilter* cf = origPaint.getColorFilter(); | 852 SkColorFilter* cf = origPaint.getColorFilter(); |
| 856 SkXfermode* mode = origPaint.getXfermode(); | 853 SkXfermode* mode = origPaint.getXfermode(); |
| 857 Sk3DShader* shader3D = NULL; | 854 Sk3DShader* shader3D = NULL; |
| 858 | 855 |
| 859 SkTCopyOnFirstWrite<SkPaint> paint(origPaint); | 856 SkTCopyOnFirstWrite<SkPaint> paint(origPaint); |
| 860 | 857 |
| 861 if (origPaint.getMaskFilter() != NULL && | 858 if (origPaint.getMaskFilter() != NULL && |
| 862 origPaint.getMaskFilter()->getFormat() == SkMask::k3D_Format) { | 859 origPaint.getMaskFilter()->getFormat() == SkMask::k3D_Format) { |
| 863 shader3D = SkNEW_ARGS(Sk3DShader, (shader)); | 860 shader3D = SkNEW_ARGS(Sk3DShader, (shader)); |
| 864 // we know we haven't initialized lazyPaint yet, so just do it | 861 // we know we haven't initialized lazyPaint yet, so just do it |
| 865 paint.writable()->setShader(shader3D)->unref(); | 862 paint.writable()->setShader(shader3D)->unref(); |
| 866 shader = shader3D; | 863 shader = shader3D; |
| 867 } | 864 } |
| 868 | 865 |
| 869 if (mode) { | 866 if (mode) { |
| 870 switch (interpret_xfermode(*paint, mode, device.colorType())) { | 867 switch (interpret_xfermode(*paint, mode, device.colorType())) { |
| 871 case kSrcOver_XferInterp: | 868 case kSrcOver_XferInterp: |
| 872 mode = NULL; | 869 mode = NULL; |
| 873 paint.writable()->setXfermode(NULL); | 870 paint.writable()->setXfermode(NULL); |
| 874 break; | 871 break; |
| 875 case kSkipDrawing_XferInterp:{ | 872 case kSkipDrawing_XferInterp:{ |
| 876 blitter = allocator->createT<SkNullBlitter>(); | 873 return allocator->createT<SkNullBlitter>(); |
| 877 return blitter; | |
| 878 } | 874 } |
| 879 default: | 875 default: |
| 880 break; | 876 break; |
| 881 } | 877 } |
| 882 } | 878 } |
| 883 | 879 |
| 884 /* | 880 /* |
| 885 * If the xfermode is CLEAR, then we can completely ignore the installed | 881 * If the xfermode is CLEAR, then we can completely ignore the installed |
| 886 * color/shader/colorfilter, and just pretend we're SRC + color==0. This | 882 * color/shader/colorfilter, and just pretend we're SRC + color==0. This |
| 887 * will fall into our optimizations for SRC mode. | 883 * will fall into our optimizations for SRC mode. |
| (...skipping 26 matching lines...) Expand all Loading... |
| 914 SkASSERT(shader); | 910 SkASSERT(shader); |
| 915 shader = SkNEW_ARGS(SkFilterShader, (shader, cf)); | 911 shader = SkNEW_ARGS(SkFilterShader, (shader, cf)); |
| 916 paint.writable()->setShader(shader)->unref(); | 912 paint.writable()->setShader(shader)->unref(); |
| 917 // blitters should ignore the presence/absence of a filter, since | 913 // blitters should ignore the presence/absence of a filter, since |
| 918 // if there is one, the shader will take care of it. | 914 // if there is one, the shader will take care of it. |
| 919 } | 915 } |
| 920 | 916 |
| 921 /* | 917 /* |
| 922 * We create a SkShader::Context object, and store it on the blitter. | 918 * We create a SkShader::Context object, and store it on the blitter. |
| 923 */ | 919 */ |
| 924 SkShader::Context* shaderContext; | 920 SkShader::Context* shaderContext = NULL; |
| 925 if (shader) { | 921 if (shader) { |
| 926 SkShader::ContextRec rec(device, *paint, matrix); | 922 SkShader::ContextRec rec(device, *paint, matrix); |
| 927 // Try to create the ShaderContext | 923 size_t contextSize = shader->contextSize(); |
| 928 void* storage = allocator->reserveT<SkShader::Context>(shader->contextSi
ze()); | 924 if (contextSize) { |
| 929 shaderContext = shader->createContext(rec, storage); | 925 // Try to create the ShaderContext |
| 930 if (!shaderContext) { | 926 void* storage = allocator->reserveT<SkShader::Context>(contextSize); |
| 931 allocator->freeLast(); | 927 shaderContext = shader->createContext(rec, storage); |
| 932 blitter = allocator->createT<SkNullBlitter>(); | 928 if (!shaderContext) { |
| 933 return blitter; | 929 allocator->freeLast(); |
| 930 return allocator->createT<SkNullBlitter>(); |
| 931 } |
| 932 SkASSERT(shaderContext); |
| 933 SkASSERT((void*) shaderContext == storage); |
| 934 } else { |
| 935 return allocator->createT<SkNullBlitter>(); |
| 934 } | 936 } |
| 935 SkASSERT(shaderContext); | |
| 936 SkASSERT((void*) shaderContext == storage); | |
| 937 } else { | |
| 938 shaderContext = NULL; | |
| 939 } | 937 } |
| 940 | 938 |
| 941 | 939 SkBlitter* blitter = NULL; |
| 942 switch (device.colorType()) { | 940 switch (device.colorType()) { |
| 943 case kAlpha_8_SkColorType: | 941 case kAlpha_8_SkColorType: |
| 944 if (drawCoverage) { | 942 if (drawCoverage) { |
| 945 SkASSERT(NULL == shader); | 943 SkASSERT(NULL == shader); |
| 946 SkASSERT(NULL == paint->getXfermode()); | 944 SkASSERT(NULL == paint->getXfermode()); |
| 947 blitter = allocator->createT<SkA8_Coverage_Blitter>(device, *pai
nt); | 945 blitter = allocator->createT<SkA8_Coverage_Blitter>(device, *pai
nt); |
| 948 } else if (shader) { | 946 } else if (shader) { |
| 949 blitter = allocator->createT<SkA8_Shader_Blitter>(device, *paint
, shaderContext); | 947 blitter = allocator->createT<SkA8_Shader_Blitter>(device, *paint
, shaderContext); |
| 950 } else { | 948 } else { |
| 951 blitter = allocator->createT<SkA8_Blitter>(device, *paint); | 949 blitter = allocator->createT<SkA8_Blitter>(device, *paint); |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1026 fShaderContext->~Context(); | 1024 fShaderContext->~Context(); |
| 1027 SkShader::Context* ctx = fShader->createContext(rec, (void*)fShaderContext); | 1025 SkShader::Context* ctx = fShader->createContext(rec, (void*)fShaderContext); |
| 1028 if (NULL == ctx) { | 1026 if (NULL == ctx) { |
| 1029 // Need a valid context in fShaderContext's storage, so we can later (or
our caller) call | 1027 // Need a valid context in fShaderContext's storage, so we can later (or
our caller) call |
| 1030 // the in-place destructor. | 1028 // the in-place destructor. |
| 1031 SkNEW_PLACEMENT_ARGS(fShaderContext, SkTransparentShaderContext, (*fShad
er, rec)); | 1029 SkNEW_PLACEMENT_ARGS(fShaderContext, SkTransparentShaderContext, (*fShad
er, rec)); |
| 1032 return false; | 1030 return false; |
| 1033 } | 1031 } |
| 1034 return true; | 1032 return true; |
| 1035 } | 1033 } |
| OLD | NEW |