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 426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
437 SkTDArray<SkPDFObject*> fResources; | 437 SkTDArray<SkPDFObject*> fResources; |
438 SkAutoTDelete<const SkPDFShader::State> fState; | 438 SkAutoTDelete<const SkPDFShader::State> fState; |
439 | 439 |
440 SkPDFStream* makePSFunction(const SkString& psCode, SkPDFArray* domain); | 440 SkPDFStream* makePSFunction(const SkString& psCode, SkPDFArray* domain); |
441 }; | 441 }; |
442 | 442 |
443 class SkPDFImageShader : public SkPDFStream, public SkPDFShader { | 443 class SkPDFImageShader : public SkPDFStream, public SkPDFShader { |
444 public: | 444 public: |
445 explicit SkPDFImageShader(SkPDFShader::State* state); | 445 explicit SkPDFImageShader(SkPDFShader::State* state); |
446 virtual ~SkPDFImageShader() { | 446 virtual ~SkPDFImageShader() { |
447 RemoveShader(this); | 447 if (isValid()) { |
448 fResources.unrefAll(); | 448 RemoveShader(this); |
449 fResources.unrefAll(); | |
vandebo (ex-Chrome)
2013/07/23 17:29:00
If it isn't valid, fResources should be empty, but
edisonn
2013/07/23 17:35:39
Done.
| |
450 } | |
449 } | 451 } |
450 | 452 |
451 virtual bool isValid() { return size() > 0; } | 453 virtual bool isValid() { return size() > 0; } |
452 | 454 |
453 void getResources(const SkTSet<SkPDFObject*>& knownResourceObjects, | 455 void getResources(const SkTSet<SkPDFObject*>& knownResourceObjects, |
454 SkTSet<SkPDFObject*>* newResourceObjects) { | 456 SkTSet<SkPDFObject*>* newResourceObjects) { |
455 GetResourcesHelper(&fResources.toArray(), | 457 GetResourcesHelper(&fResources.toArray(), |
456 knownResourceObjects, | 458 knownResourceObjects, |
457 newResourceObjects); | 459 newResourceObjects); |
458 } | 460 } |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
504 new SkPDFImageShader(shaderState.detach()); | 506 new SkPDFImageShader(shaderState.detach()); |
505 valid = imageShader->isValid(); | 507 valid = imageShader->isValid(); |
506 result = imageShader; | 508 result = imageShader; |
507 } else { | 509 } else { |
508 SkPDFFunctionShader* functionShader = | 510 SkPDFFunctionShader* functionShader = |
509 new SkPDFFunctionShader(shaderState.detach()); | 511 new SkPDFFunctionShader(shaderState.detach()); |
510 valid = functionShader->isValid(); | 512 valid = functionShader->isValid(); |
511 result = functionShader; | 513 result = functionShader; |
512 } | 514 } |
513 if (!valid) { | 515 if (!valid) { |
516 // Release the lock, otherwise we end up calling RemoveShader that | |
vandebo (ex-Chrome)
2013/07/23 17:29:00
With the isValid() check in the destructor, you do
edisonn
2013/07/23 17:35:39
true for image shader, but I am not 100% for funct
vandebo (ex-Chrome)
2013/07/23 17:47:33
All the early exits are before fResources is popul
edisonn
2013/07/23 17:54:13
done (function shader already has the valid check
| |
517 // locks again, and we end up with a freeze. | |
518 lock.release(); | |
514 delete result; | 519 delete result; |
515 return NULL; | 520 return NULL; |
516 } | 521 } |
517 entry.fPDFShader = result; | 522 entry.fPDFShader = result; |
518 CanonicalShaders().push(entry); | 523 CanonicalShaders().push(entry); |
519 return result; // return the reference that came from new. | 524 return result; // return the reference that came from new. |
520 } | 525 } |
521 | 526 |
522 // static | 527 // static |
523 SkTDArray<SkPDFShader::ShaderCanonicalEntry>& SkPDFShader::CanonicalShaders() { | 528 SkTDArray<SkPDFShader::ShaderCanonicalEntry>& SkPDFShader::CanonicalShaders() { |
(...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
955 fPixelGeneration = fImage.getGenerationID(); | 960 fPixelGeneration = fImage.getGenerationID(); |
956 } else { | 961 } else { |
957 fColorData.set(sk_malloc_throw( | 962 fColorData.set(sk_malloc_throw( |
958 fInfo.fColorCount * (sizeof(SkColor) + sizeof(SkScalar)))); | 963 fInfo.fColorCount * (sizeof(SkColor) + sizeof(SkScalar)))); |
959 fInfo.fColors = reinterpret_cast<SkColor*>(fColorData.get()); | 964 fInfo.fColors = reinterpret_cast<SkColor*>(fColorData.get()); |
960 fInfo.fColorOffsets = | 965 fInfo.fColorOffsets = |
961 reinterpret_cast<SkScalar*>(fInfo.fColors + fInfo.fColorCount); | 966 reinterpret_cast<SkScalar*>(fInfo.fColors + fInfo.fColorCount); |
962 shader.asAGradient(&fInfo); | 967 shader.asAGradient(&fInfo); |
963 } | 968 } |
964 } | 969 } |
OLD | NEW |