Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
| 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 "SkPDFShader.h" | 10 #include "SkPDFShader.h" |
| (...skipping 584 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 595 SkAutoTDelete<State> shaderState(inState); | 595 SkAutoTDelete<State> shaderState(inState); |
| 596 if (shaderState.get()->fType == SkShader::kNone_GradientType && | 596 if (shaderState.get()->fType == SkShader::kNone_GradientType && |
| 597 shaderState.get()->fImage.isNull()) { | 597 shaderState.get()->fImage.isNull()) { |
| 598 // TODO(vandebo) This drops SKComposeShader on the floor. We could | 598 // TODO(vandebo) This drops SKComposeShader on the floor. We could |
| 599 // handle compose shader by pulling things up to a layer, drawing with | 599 // handle compose shader by pulling things up to a layer, drawing with |
| 600 // the first shader, applying the xfer mode and drawing again with the | 600 // the first shader, applying the xfer mode and drawing again with the |
| 601 // second shader, then applying the layer to the original drawing. | 601 // second shader, then applying the layer to the original drawing. |
| 602 return NULL; | 602 return NULL; |
| 603 } | 603 } |
| 604 | 604 |
| 605 SkPDFShader::CanonicalShadersMutex().assertHeld(); | |
|
mtklein
2014/06/20 17:40:54
Seems redundant? Just let CanonicalShaders() do i
hal.canary
2014/06/20 17:49:07
Done.
| |
| 605 ShaderCanonicalEntry entry(NULL, shaderState.get()); | 606 ShaderCanonicalEntry entry(NULL, shaderState.get()); |
| 606 int index = CanonicalShaders().find(entry); | 607 int index = CanonicalShaders().find(entry); |
| 607 if (index >= 0) { | 608 if (index >= 0) { |
| 608 result = CanonicalShaders()[index].fPDFShader; | 609 result = CanonicalShaders()[index].fPDFShader; |
| 609 result->ref(); | 610 result->ref(); |
| 610 return result; | 611 return result; |
| 611 } | 612 } |
| 612 | 613 |
| 613 bool valid = false; | 614 bool valid = false; |
| 614 // The PDFShader takes ownership of the shaderSate. | 615 // The PDFShader takes ownership of the shaderSate. |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 628 SkNEW_ARGS(SkPDFFunctionShader, (shaderState.detach())); | 629 SkNEW_ARGS(SkPDFFunctionShader, (shaderState.detach())); |
| 629 valid = functionShader->isValid(); | 630 valid = functionShader->isValid(); |
| 630 result = functionShader; | 631 result = functionShader; |
| 631 } | 632 } |
| 632 } | 633 } |
| 633 if (!valid) { | 634 if (!valid) { |
| 634 delete result; | 635 delete result; |
| 635 return NULL; | 636 return NULL; |
| 636 } | 637 } |
| 637 entry.fPDFShader = result; | 638 entry.fPDFShader = result; |
| 639 SkPDFShader::CanonicalShadersMutex().assertHeld(); | |
|
mtklein
2014/06/20 17:40:56
Ditto.
hal.canary
2014/06/20 17:49:06
Done.
| |
| 638 CanonicalShaders().push(entry); | 640 CanonicalShaders().push(entry); |
| 639 return result; // return the reference that came from new. | 641 return result; // return the reference that came from new. |
| 640 } | 642 } |
| 641 | 643 |
| 642 // static | 644 // static |
| 643 void SkPDFShader::RemoveShader(SkPDFObject* shader) { | 645 void SkPDFShader::RemoveShader(SkPDFObject* shader) { |
| 644 SkAutoMutexAcquire lock(CanonicalShadersMutex()); | 646 SkAutoMutexAcquire lock(CanonicalShadersMutex()); |
| 645 ShaderCanonicalEntry entry(shader, NULL); | 647 ShaderCanonicalEntry entry(shader, NULL); |
| 646 int index = CanonicalShaders().find(entry); | 648 int index = CanonicalShaders().find(entry); |
| 647 SkASSERT(index >= 0); | 649 SkASSERT(index >= 0); |
| 648 CanonicalShaders().removeShuffle(index); | 650 CanonicalShaders().removeShuffle(index); |
| 649 } | 651 } |
| 650 | 652 |
| 651 // static | 653 // static |
| 652 SkPDFObject* SkPDFShader::GetPDFShader(const SkShader& shader, | 654 SkPDFObject* SkPDFShader::GetPDFShader(const SkShader& shader, |
| 653 const SkMatrix& matrix, | 655 const SkMatrix& matrix, |
| 654 const SkIRect& surfaceBBox) { | 656 const SkIRect& surfaceBBox) { |
| 655 SkAutoMutexAcquire lock(CanonicalShadersMutex()); | 657 SkAutoMutexAcquire lock(CanonicalShadersMutex()); |
| 656 return GetPDFShaderByState( | 658 return GetPDFShaderByState( |
| 657 SkNEW_ARGS(State, (shader, matrix, surfaceBBox))); | 659 SkNEW_ARGS(State, (shader, matrix, surfaceBBox))); |
| 658 } | 660 } |
| 659 | 661 |
| 660 // static | 662 // static |
| 661 SkTDArray<SkPDFShader::ShaderCanonicalEntry>& SkPDFShader::CanonicalShaders() { | 663 SkTDArray<SkPDFShader::ShaderCanonicalEntry>& SkPDFShader::CanonicalShaders() { |
| 664 SkPDFShader::CanonicalShadersMutex().assertHeld(); | |
| 662 // This initialization is only thread safe with gcc. | 665 // This initialization is only thread safe with gcc. |
| 663 static SkTDArray<ShaderCanonicalEntry> gCanonicalShaders; | 666 static SkTDArray<ShaderCanonicalEntry> gCanonicalShaders; |
| 664 return gCanonicalShaders; | 667 return gCanonicalShaders; |
| 665 } | 668 } |
| 666 | 669 |
| 667 // static | 670 // static |
| 668 SkBaseMutex& SkPDFShader::CanonicalShadersMutex() { | 671 SkBaseMutex& SkPDFShader::CanonicalShadersMutex() { |
| 669 // This initialization is only thread safe with gcc or when | 672 // This initialization is only thread safe with gcc or when |
|
mtklein
2014/06/20 17:40:56
Again, misleading. Let's just delete all these "i
hal.canary
2014/06/20 17:49:06
Done.
| |
| 670 // POD-style mutex initialization is used. | 673 // POD-style mutex initialization is used. |
| 671 SK_DECLARE_STATIC_MUTEX(gCanonicalShadersMutex); | 674 SK_DECLARE_STATIC_MUTEX(gCanonicalShadersMutex); |
| 672 return gCanonicalShadersMutex; | 675 return gCanonicalShadersMutex; |
| 673 } | 676 } |
| 674 | 677 |
| 675 // static | 678 // static |
| 676 SkPDFObject* SkPDFFunctionShader::RangeObject() { | 679 SkPDFObject* SkPDFFunctionShader::RangeObject() { |
| 677 // This initialization is only thread safe with gcc. | 680 SkPDFShader::CanonicalShadersMutex().assertHeld(); |
| 678 static SkPDFArray* range = NULL; | 681 static SkPDFArray* range = NULL; |
| 679 // This method is only used with CanonicalShadersMutex, so it's safe to | 682 // This method is only used with CanonicalShadersMutex, so it's safe to |
| 680 // populate domain. | 683 // populate domain. |
| 681 if (range == NULL) { | 684 if (range == NULL) { |
| 682 range = new SkPDFArray; | 685 range = new SkPDFArray; |
| 683 range->reserve(6); | 686 range->reserve(6); |
| 684 range->appendInt(0); | 687 range->appendInt(0); |
| 685 range->appendInt(1); | 688 range->appendInt(1); |
| 686 range->appendInt(0); | 689 range->appendInt(0); |
| 687 range->appendInt(1); | 690 range->appendInt(1); |
| (...skipping 651 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1339 return false; | 1342 return false; |
| 1340 } | 1343 } |
| 1341 | 1344 |
| 1342 void SkPDFShader::State::AllocateGradientInfoStorage() { | 1345 void SkPDFShader::State::AllocateGradientInfoStorage() { |
| 1343 fColorData.set(sk_malloc_throw( | 1346 fColorData.set(sk_malloc_throw( |
| 1344 fInfo.fColorCount * (sizeof(SkColor) + sizeof(SkScalar)))); | 1347 fInfo.fColorCount * (sizeof(SkColor) + sizeof(SkScalar)))); |
| 1345 fInfo.fColors = reinterpret_cast<SkColor*>(fColorData.get()); | 1348 fInfo.fColors = reinterpret_cast<SkColor*>(fColorData.get()); |
| 1346 fInfo.fColorOffsets = | 1349 fInfo.fColorOffsets = |
| 1347 reinterpret_cast<SkScalar*>(fInfo.fColors + fInfo.fColorCount); | 1350 reinterpret_cast<SkScalar*>(fInfo.fColors + fInfo.fColorCount); |
| 1348 } | 1351 } |
| OLD | NEW |