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 SkBitmap& device, const SkPaint& paint, | 594 virtual bool validContext(const ContextRec& rec, SkMatrix* totalInverse) con
st SK_OVERRIDE { |
595 const SkMatrix& matrix, SkMatrix* totalInverse = N
ULL) const | 595 if (!this->INHERITED::validContext(rec, totalInverse)) { |
596 SK_OVERRIDE | |
597 { | |
598 if (!this->INHERITED::validContext(device, paint, matrix, totalInverse))
{ | |
599 return false; | 596 return false; |
600 } | 597 } |
601 if (fProxy) { | 598 if (fProxy) { |
602 return fProxy->validContext(device, paint, matrix); | 599 return fProxy->validContext(rec); |
603 } | 600 } |
604 return true; | 601 return true; |
605 } | 602 } |
606 | 603 |
607 virtual SkShader::Context* createContext(const SkBitmap& device, | 604 virtual SkShader::Context* createContext(const ContextRec& rec, void* storag
e) const SK_OVERRIDE |
608 const SkPaint& paint, | |
609 const SkMatrix& matrix, | |
610 void* storage) const SK_OVERRIDE | |
611 { | 605 { |
612 if (!this->validContext(device, paint, matrix)) { | 606 if (!this->validContext(rec, NULL)) { |
613 return NULL; | 607 return NULL; |
614 } | 608 } |
615 | 609 |
616 SkShader::Context* proxyContext; | 610 SkShader::Context* proxyContext; |
617 if (fProxy) { | 611 if (fProxy) { |
618 char* proxyContextStorage = (char*) storage + sizeof(Sk3DShaderConte
xt); | 612 char* proxyContextStorage = (char*) storage + sizeof(Sk3DShaderConte
xt); |
619 proxyContext = fProxy->createContext(device, paint, matrix, proxyCon
textStorage); | 613 proxyContext = fProxy->createContext(rec, proxyContextStorage); |
620 SkASSERT(proxyContext); | 614 SkASSERT(proxyContext); |
621 } else { | 615 } else { |
622 proxyContext = NULL; | 616 proxyContext = NULL; |
623 } | 617 } |
624 return SkNEW_PLACEMENT_ARGS(storage, Sk3DShaderContext, (*this, device,
paint, matrix, | 618 return SkNEW_PLACEMENT_ARGS(storage, Sk3DShaderContext, (*this, rec, pro
xyContext)); |
625 proxyContext)); | |
626 } | 619 } |
627 | 620 |
628 class Sk3DShaderContext : public SkShader::Context { | 621 class Sk3DShaderContext : public SkShader::Context { |
629 public: | 622 public: |
630 // Calls proxyContext's destructor but will NOT free its memory. | 623 // Calls proxyContext's destructor but will NOT free its memory. |
631 Sk3DShaderContext(const Sk3DShader& shader, const SkBitmap& device, cons
t SkPaint& paint, | 624 Sk3DShaderContext(const Sk3DShader& shader, const ContextRec& rec, |
632 const SkMatrix& matrix, SkShader::Context* proxyContex
t) | 625 SkShader::Context* proxyContext) |
633 : INHERITED(shader, device, paint, matrix) | 626 : INHERITED(shader, rec) |
634 , fMask(NULL) | 627 , fMask(NULL) |
635 , fProxyContext(proxyContext) | 628 , fProxyContext(proxyContext) |
636 { | 629 { |
637 if (!fProxyContext) { | 630 if (!fProxyContext) { |
638 fPMColor = SkPreMultiplyColor(paint.getColor()); | 631 fPMColor = SkPreMultiplyColor(rec.fPaint->getColor()); |
639 } | 632 } |
640 } | 633 } |
641 | 634 |
642 virtual ~Sk3DShaderContext() { | 635 virtual ~Sk3DShaderContext() { |
643 if (fProxyContext) { | 636 if (fProxyContext) { |
644 fProxyContext->~Context(); | 637 fProxyContext->~Context(); |
645 } | 638 } |
646 } | 639 } |
647 | 640 |
648 void setMask(const SkMask* mask) { fMask = mask; } | 641 void setMask(const SkMask* mask) { fMask = mask; } |
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
947 paint.writable()->setShader(shader)->unref(); | 940 paint.writable()->setShader(shader)->unref(); |
948 // blitters should ignore the presence/absence of a filter, since | 941 // blitters should ignore the presence/absence of a filter, since |
949 // if there is one, the shader will take care of it. | 942 // if there is one, the shader will take care of it. |
950 } | 943 } |
951 | 944 |
952 /* | 945 /* |
953 * We create a SkShader::Context object, and store it on the blitter. | 946 * We create a SkShader::Context object, and store it on the blitter. |
954 */ | 947 */ |
955 SkShader::Context* shaderContext; | 948 SkShader::Context* shaderContext; |
956 if (shader) { | 949 if (shader) { |
| 950 SkShader::ContextRec rec(device, *paint, matrix); |
957 // Try to create the ShaderContext | 951 // Try to create the ShaderContext |
958 void* storage = allocator->reserveT<SkShader::Context>(shader->contextSi
ze()); | 952 void* storage = allocator->reserveT<SkShader::Context>(shader->contextSi
ze()); |
959 shaderContext = shader->createContext(device, *paint, matrix, storage); | 953 shaderContext = shader->createContext(rec, storage); |
960 if (!shaderContext) { | 954 if (!shaderContext) { |
961 allocator->freeLast(); | 955 allocator->freeLast(); |
962 blitter = allocator->createT<SkNullBlitter>(); | 956 blitter = allocator->createT<SkNullBlitter>(); |
963 return blitter; | 957 return blitter; |
964 } | 958 } |
965 SkASSERT(shaderContext); | 959 SkASSERT(shaderContext); |
966 SkASSERT((void*) shaderContext == storage); | 960 SkASSERT((void*) shaderContext == storage); |
967 } else { | 961 } else { |
968 shaderContext = NULL; | 962 shaderContext = NULL; |
969 } | 963 } |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1033 fShader->ref(); | 1027 fShader->ref(); |
1034 fShaderFlags = fShaderContext->getFlags(); | 1028 fShaderFlags = fShaderContext->getFlags(); |
1035 } | 1029 } |
1036 | 1030 |
1037 SkShaderBlitter::~SkShaderBlitter() { | 1031 SkShaderBlitter::~SkShaderBlitter() { |
1038 fShader->unref(); | 1032 fShader->unref(); |
1039 } | 1033 } |
1040 | 1034 |
1041 bool SkShaderBlitter::resetShaderContext(const SkBitmap& device, const SkPaint&
paint, | 1035 bool SkShaderBlitter::resetShaderContext(const SkBitmap& device, const SkPaint&
paint, |
1042 const SkMatrix& matrix) { | 1036 const SkMatrix& matrix) { |
1043 if (!fShader->validContext(device, paint, matrix)) { | 1037 SkShader::ContextRec rec(device, paint, matrix); |
| 1038 if (!fShader->validContext(rec)) { |
1044 return false; | 1039 return false; |
1045 } | 1040 } |
1046 | 1041 |
1047 // Only destroy the old context if we have a new one. We need to ensure to h
ave a | 1042 // Only destroy the old context if we have a new one. We need to ensure to h
ave a |
1048 // live context in fShaderContext because the storage is owned by an SkSmall
Allocator | 1043 // live context in fShaderContext because the storage is owned by an SkSmall
Allocator |
1049 // outside of this class. | 1044 // outside of this class. |
1050 // The new context will be of the same size as the old one because we use th
e same | 1045 // The new context will be of the same size as the old one because we use th
e same |
1051 // shader to create it. It is therefore safe to re-use the storage. | 1046 // shader to create it. It is therefore safe to re-use the storage. |
1052 fShaderContext->~Context(); | 1047 fShaderContext->~Context(); |
1053 fShaderContext = fShader->createContext(device, paint, matrix, (void*)fShade
rContext); | 1048 fShaderContext = fShader->createContext(rec, (void*)fShaderContext); |
1054 SkASSERT(fShaderContext); | 1049 SkASSERT(fShaderContext); |
1055 | 1050 |
1056 return true; | 1051 return true; |
1057 } | 1052 } |
OLD | NEW |