OLD | NEW |
---|---|
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2006 The Android Open Source Project | 3 * Copyright 2006 The Android Open Source Project |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 | 9 |
10 #include "SkBlitter.h" | 10 #include "SkBlitter.h" |
(...skipping 573 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
584 } | 584 } |
585 | 585 |
586 virtual size_t contextSize() const SK_OVERRIDE { | 586 virtual size_t contextSize() const SK_OVERRIDE { |
587 size_t size = sizeof(Sk3DShaderContext); | 587 size_t size = sizeof(Sk3DShaderContext); |
588 if (fProxy) { | 588 if (fProxy) { |
589 size += fProxy->contextSize(); | 589 size += fProxy->contextSize(); |
590 } | 590 } |
591 return size; | 591 return size; |
592 } | 592 } |
593 | 593 |
594 virtual bool validContext(const ContextRec& rec, SkMatrix* totalInverse) con st SK_OVERRIDE { | 594 virtual Context* onCreateContext(const ContextRec& rec, void* storage) const SK_OVERRIDE { |
595 if (!this->INHERITED::validContext(rec, totalInverse)) { | 595 SkShader::Context* proxyContext = NULL; |
596 return false; | |
597 } | |
598 if (fProxy) { | |
599 return fProxy->validContext(rec); | |
600 } | |
601 return true; | |
602 } | |
603 | |
604 virtual SkShader::Context* createContext(const ContextRec& rec, void* storag e) const SK_OVERRIDE | |
605 { | |
606 if (!this->validContext(rec, NULL)) { | |
607 return NULL; | |
608 } | |
609 | |
610 SkShader::Context* proxyContext; | |
611 if (fProxy) { | 596 if (fProxy) { |
612 char* proxyContextStorage = (char*) storage + sizeof(Sk3DShaderConte xt); | 597 char* proxyContextStorage = (char*) storage + sizeof(Sk3DShaderConte xt); |
613 proxyContext = fProxy->createContext(rec, proxyContextStorage); | 598 proxyContext = fProxy->createContext(rec, proxyContextStorage); |
614 SkASSERT(proxyContext); | 599 if (!proxyContext) { |
615 } else { | 600 return NULL; |
616 proxyContext = NULL; | 601 } |
617 } | 602 } |
618 return SkNEW_PLACEMENT_ARGS(storage, Sk3DShaderContext, (*this, rec, pro xyContext)); | 603 return SkNEW_PLACEMENT_ARGS(storage, Sk3DShaderContext, (*this, rec, pro xyContext)); |
619 } | 604 } |
620 | 605 |
621 class Sk3DShaderContext : public SkShader::Context { | 606 class Sk3DShaderContext : public SkShader::Context { |
622 public: | 607 public: |
623 // Calls proxyContext's destructor but will NOT free its memory. | 608 // Calls proxyContext's destructor but will NOT free its memory. |
624 Sk3DShaderContext(const Sk3DShader& shader, const ContextRec& rec, | 609 Sk3DShaderContext(const Sk3DShader& shader, const ContextRec& rec, |
625 SkShader::Context* proxyContext) | 610 SkShader::Context* proxyContext) |
626 : INHERITED(shader, rec) | 611 : INHERITED(shader, rec) |
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1009 return blitter; | 994 return blitter; |
1010 } | 995 } |
1011 | 996 |
1012 /////////////////////////////////////////////////////////////////////////////// | 997 /////////////////////////////////////////////////////////////////////////////// |
1013 | 998 |
1014 const uint16_t gMask_0F0F = 0xF0F; | 999 const uint16_t gMask_0F0F = 0xF0F; |
1015 const uint32_t gMask_00FF00FF = 0xFF00FF; | 1000 const uint32_t gMask_00FF00FF = 0xFF00FF; |
1016 | 1001 |
1017 /////////////////////////////////////////////////////////////////////////////// | 1002 /////////////////////////////////////////////////////////////////////////////// |
1018 | 1003 |
1004 class SkTransparentShaderContext : public SkShader::Context { | |
1005 public: | |
1006 SkTransparentShaderContext(const SkShader& shader, const SkShader::ContextRe c& rec) | |
1007 : INHERITED(shader, rec) {} | |
1008 | |
1009 virtual void shadeSpan(int x, int y, SkPMColor colors[], int count) SK_OVERR IDE { | |
1010 sk_bzero(colors, count * sizeof(SkPMColor)); | |
1011 } | |
1012 | |
1013 private: | |
1014 typedef SkShader::Context INHERITED; | |
1015 }; | |
1016 | |
1019 SkShaderBlitter::SkShaderBlitter(const SkBitmap& device, const SkPaint& paint, | 1017 SkShaderBlitter::SkShaderBlitter(const SkBitmap& device, const SkPaint& paint, |
1020 SkShader::Context* shaderContext) | 1018 SkShader::Context* shaderContext) |
1021 : INHERITED(device) | 1019 : INHERITED(device) |
1022 , fShader(paint.getShader()) | 1020 , fShader(paint.getShader()) |
1023 , fShaderContext(shaderContext) { | 1021 , fShaderContext(shaderContext) { |
1024 SkASSERT(fShader); | 1022 SkASSERT(fShader); |
1025 SkASSERT(fShaderContext); | 1023 SkASSERT(fShaderContext); |
1026 | 1024 |
1027 fShader->ref(); | 1025 fShader->ref(); |
1028 fShaderFlags = fShaderContext->getFlags(); | 1026 fShaderFlags = fShaderContext->getFlags(); |
1029 } | 1027 } |
1030 | 1028 |
1031 SkShaderBlitter::~SkShaderBlitter() { | 1029 SkShaderBlitter::~SkShaderBlitter() { |
1032 fShader->unref(); | 1030 fShader->unref(); |
1033 } | 1031 } |
1034 | 1032 |
1035 bool SkShaderBlitter::resetShaderContext(const SkBitmap& device, const SkPaint& paint, | 1033 bool SkShaderBlitter::resetShaderContext(const SkBitmap& device, const SkPaint& paint, |
1036 const SkMatrix& matrix) { | 1034 const SkMatrix& matrix) { |
1037 SkShader::ContextRec rec(device, paint, matrix); | 1035 SkShader::ContextRec rec(device, paint, matrix); |
1038 if (!fShader->validContext(rec)) { | |
1039 return false; | |
1040 } | |
1041 | 1036 |
1042 // Only destroy the old context if we have a new one. We need to ensure to h ave a | 1037 // Only destroy the old context if we have a new one. We need to ensure to h ave a |
1043 // live context in fShaderContext because the storage is owned by an SkSmall Allocator | 1038 // live context in fShaderContext because the storage is owned by an SkSmall Allocator |
1044 // outside of this class. | 1039 // outside of this class. |
1045 // The new context will be of the same size as the old one because we use th e same | 1040 // The new context will be of the same size as the old one because we use th e same |
1046 // shader to create it. It is therefore safe to re-use the storage. | 1041 // shader to create it. It is therefore safe to re-use the storage. |
1047 fShaderContext->~Context(); | 1042 fShaderContext->~Context(); |
1048 fShaderContext = fShader->createContext(rec, (void*)fShaderContext); | 1043 SkShader::Context* ctx = fShader->createContext(rec, (void*)fShaderContext); |
1049 SkASSERT(fShaderContext); | 1044 if (NULL == ctx) { |
1050 | 1045 // Need a valid context in fShaderContext's storage, so we can later (or our caller) call |
1051 return true; | 1046 // the in-place destructor. |
1047 SkNEW_PLACEMENT_ARGS(fShaderContext, SkTransparentShaderContext, (*fShad er, rec)); | |
scroggo
2014/05/05 16:02:47
Can't this just be an SkShader::Context? It seems
| |
1048 } | |
1049 return ctx != NULL; | |
1052 } | 1050 } |
OLD | NEW |