| 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 846 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 857 paint.writable()->setShader(shader)->unref(); | 857 paint.writable()->setShader(shader)->unref(); |
| 858 // blitters should ignore the presence/absence of a filter, since | 858 // blitters should ignore the presence/absence of a filter, since |
| 859 // if there is one, the shader will take care of it. | 859 // if there is one, the shader will take care of it. |
| 860 } | 860 } |
| 861 | 861 |
| 862 /* | 862 /* |
| 863 * We create a SkShader::Context object, and store it on the blitter. | 863 * We create a SkShader::Context object, and store it on the blitter. |
| 864 */ | 864 */ |
| 865 SkShader::Context* shaderContext = NULL; | 865 SkShader::Context* shaderContext = NULL; |
| 866 if (shader) { | 866 if (shader) { |
| 867 SkShader::ContextRec rec(device, *paint, matrix); | 867 SkShader::ContextRec rec(*paint, matrix, NULL); |
| 868 size_t contextSize = shader->contextSize(); | 868 size_t contextSize = shader->contextSize(); |
| 869 if (contextSize) { | 869 if (contextSize) { |
| 870 // Try to create the ShaderContext | 870 // Try to create the ShaderContext |
| 871 void* storage = allocator->reserveT<SkShader::Context>(contextSize); | 871 void* storage = allocator->reserveT<SkShader::Context>(contextSize); |
| 872 shaderContext = shader->createContext(rec, storage); | 872 shaderContext = shader->createContext(rec, storage); |
| 873 if (!shaderContext) { | 873 if (!shaderContext) { |
| 874 allocator->freeLast(); | 874 allocator->freeLast(); |
| 875 return allocator->createT<SkNullBlitter>(); | 875 return allocator->createT<SkNullBlitter>(); |
| 876 } | 876 } |
| 877 SkASSERT(shaderContext); | 877 SkASSERT(shaderContext); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 923 // innerBlitter was allocated by allocator, which will delete it. | 923 // innerBlitter was allocated by allocator, which will delete it. |
| 924 // We know shaderContext or its proxies is of type Sk3DShaderContext, so
we need to | 924 // We know shaderContext or its proxies is of type Sk3DShaderContext, so
we need to |
| 925 // wrapper the blitter to notify it when we see an emboss mask. | 925 // wrapper the blitter to notify it when we see an emboss mask. |
| 926 blitter = allocator->createT<Sk3DBlitter>(innerBlitter, shaderContext); | 926 blitter = allocator->createT<Sk3DBlitter>(innerBlitter, shaderContext); |
| 927 } | 927 } |
| 928 return blitter; | 928 return blitter; |
| 929 } | 929 } |
| 930 | 930 |
| 931 /////////////////////////////////////////////////////////////////////////////// | 931 /////////////////////////////////////////////////////////////////////////////// |
| 932 | 932 |
| 933 class SkTransparentShaderContext : public SkShader::Context { | 933 class SkZeroShaderContext : public SkShader::Context { |
| 934 public: | 934 public: |
| 935 SkTransparentShaderContext(const SkShader& shader, const SkShader::ContextRe
c& rec) | 935 SkZeroShaderContext(const SkShader& shader, const SkShader::ContextRec& rec) |
| 936 // Override rec with the identity matrix, so it is guaranteed to be inve
rtible. | 936 // Override rec with the identity matrix, so it is guaranteed to be inve
rtible. |
| 937 : INHERITED(shader, SkShader::ContextRec(*rec.fDevice, *rec.fPaint, SkMa
trix::I())) {} | 937 : INHERITED(shader, SkShader::ContextRec(*rec.fPaint, SkMatrix::I(), NUL
L)) {} |
| 938 | 938 |
| 939 void shadeSpan(int x, int y, SkPMColor colors[], int count) override { | 939 void shadeSpan(int x, int y, SkPMColor colors[], int count) override { |
| 940 sk_bzero(colors, count * sizeof(SkPMColor)); | 940 sk_bzero(colors, count * sizeof(SkPMColor)); |
| 941 } | 941 } |
| 942 | 942 |
| 943 private: | 943 private: |
| 944 typedef SkShader::Context INHERITED; | 944 typedef SkShader::Context INHERITED; |
| 945 }; | 945 }; |
| 946 | 946 |
| 947 SkShaderBlitter::SkShaderBlitter(const SkBitmap& device, const SkPaint& paint, | 947 SkShaderBlitter::SkShaderBlitter(const SkBitmap& device, const SkPaint& paint, |
| (...skipping 16 matching lines...) Expand all Loading... |
| 964 // Only destroy the old context if we have a new one. We need to ensure to h
ave a | 964 // Only destroy the old context if we have a new one. We need to ensure to h
ave a |
| 965 // live context in fShaderContext because the storage is owned by an SkSmall
Allocator | 965 // live context in fShaderContext because the storage is owned by an SkSmall
Allocator |
| 966 // outside of this class. | 966 // outside of this class. |
| 967 // The new context will be of the same size as the old one because we use th
e same | 967 // The new context will be of the same size as the old one because we use th
e same |
| 968 // shader to create it. It is therefore safe to re-use the storage. | 968 // shader to create it. It is therefore safe to re-use the storage. |
| 969 fShaderContext->~Context(); | 969 fShaderContext->~Context(); |
| 970 SkShader::Context* ctx = fShader->createContext(rec, (void*)fShaderContext); | 970 SkShader::Context* ctx = fShader->createContext(rec, (void*)fShaderContext); |
| 971 if (NULL == ctx) { | 971 if (NULL == ctx) { |
| 972 // Need a valid context in fShaderContext's storage, so we can later (or
our caller) call | 972 // Need a valid context in fShaderContext's storage, so we can later (or
our caller) call |
| 973 // the in-place destructor. | 973 // the in-place destructor. |
| 974 SkNEW_PLACEMENT_ARGS(fShaderContext, SkTransparentShaderContext, (*fShad
er, rec)); | 974 SkNEW_PLACEMENT_ARGS(fShaderContext, SkZeroShaderContext, (*fShader, rec
)); |
| 975 return false; | 975 return false; |
| 976 } | 976 } |
| 977 return true; | 977 return true; |
| 978 } | 978 } |
| OLD | NEW |