Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(800)

Side by Side Diff: src/pdf/SkPDFShader.cpp

Issue 870333002: Simplify reference management in SkPDF (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: make Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/pdf/SkPDFShader.h ('k') | src/pdf/SkPDFTypes.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 492 matching lines...) Expand 10 before | Expand all | Expand 10 after
503 State(const State& other); 503 State(const State& other);
504 State operator=(const State& rhs); 504 State operator=(const State& rhs);
505 void AllocateGradientInfoStorage(); 505 void AllocateGradientInfoStorage();
506 }; 506 };
507 507
508 //////////////////////////////////////////////////////////////////////////////// 508 ////////////////////////////////////////////////////////////////////////////////
509 509
510 SkPDFFunctionShader::SkPDFFunctionShader(SkPDFShader::State* state) 510 SkPDFFunctionShader::SkPDFFunctionShader(SkPDFShader::State* state)
511 : SkPDFDict("Pattern"), fShaderState(state) {} 511 : SkPDFDict("Pattern"), fShaderState(state) {}
512 512
513 void SkPDFFunctionShader::getResources(const SkTSet<SkPDFObject*>& known,
514 SkTSet<SkPDFObject*>* newr) {
515 GetResourcesHelper(&fResources, known, newr);
516 }
517
518 SkPDFFunctionShader::~SkPDFFunctionShader() { 513 SkPDFFunctionShader::~SkPDFFunctionShader() {
519 SkAutoMutexAcquire lock(SkPDFCanon::GetShaderMutex()); 514 SkAutoMutexAcquire lock(SkPDFCanon::GetShaderMutex());
520 SkPDFCanon::GetCanon().removeFunctionShader(this); 515 SkPDFCanon::GetCanon().removeFunctionShader(this);
521 lock.release(); 516 lock.release();
522 fResources.unrefAll(); 517 fResources.unrefAll();
523 } 518 }
524 519
525 bool SkPDFFunctionShader::equals(const SkPDFShader::State& state) const { 520 bool SkPDFFunctionShader::equals(const SkPDFShader::State& state) const {
526 return state == *fShaderState; 521 return state == *fShaderState;
527 } 522 }
528 523
529 //////////////////////////////////////////////////////////////////////////////// 524 ////////////////////////////////////////////////////////////////////////////////
530 525
531 SkPDFAlphaFunctionShader::SkPDFAlphaFunctionShader(SkPDFShader::State* state) 526 SkPDFAlphaFunctionShader::SkPDFAlphaFunctionShader(SkPDFShader::State* state)
532 : fShaderState(state) {} 527 : fShaderState(state) {}
533 528
534 bool SkPDFAlphaFunctionShader::equals(const SkPDFShader::State& state) const { 529 bool SkPDFAlphaFunctionShader::equals(const SkPDFShader::State& state) const {
535 return state == *fShaderState; 530 return state == *fShaderState;
536 } 531 }
537 532
538 SkPDFAlphaFunctionShader::~SkPDFAlphaFunctionShader() { 533 SkPDFAlphaFunctionShader::~SkPDFAlphaFunctionShader() {
539 SkAutoMutexAcquire lock(SkPDFCanon::GetShaderMutex()); 534 SkAutoMutexAcquire lock(SkPDFCanon::GetShaderMutex());
540 SkPDFCanon::GetCanon().removeAlphaShader(this); 535 SkPDFCanon::GetCanon().removeAlphaShader(this);
541 } 536 }
542 537
543 void SkPDFAlphaFunctionShader::getResources(const SkTSet<SkPDFObject*>& known,
544 SkTSet<SkPDFObject*>* newr) {
545 fResourceDict->getReferencedResources(known, newr, true);
546 }
547
548 //////////////////////////////////////////////////////////////////////////////// 538 ////////////////////////////////////////////////////////////////////////////////
549 539
550 SkPDFImageShader::SkPDFImageShader(SkPDFShader::State* state) 540 SkPDFImageShader::SkPDFImageShader(SkPDFShader::State* state)
551 : fShaderState(state) {} 541 : fShaderState(state) {}
552 542
553 bool SkPDFImageShader::equals(const SkPDFShader::State& state) const { 543 bool SkPDFImageShader::equals(const SkPDFShader::State& state) const {
554 return state == *fShaderState; 544 return state == *fShaderState;
555 } 545 }
556 546
557 SkPDFImageShader::~SkPDFImageShader() { 547 SkPDFImageShader::~SkPDFImageShader() {
558 SkAutoMutexAcquire lock(SkPDFCanon::GetShaderMutex()); 548 SkAutoMutexAcquire lock(SkPDFCanon::GetShaderMutex());
559 SkPDFCanon::GetCanon().removeImageShader(this); 549 SkPDFCanon::GetCanon().removeImageShader(this);
560 lock.release(); 550 lock.release();
561 fResources.unrefAll(); 551 fResources.unrefAll();
562 } 552 }
563 553
564 void SkPDFImageShader::getResources(const SkTSet<SkPDFObject*>& known,
565 SkTSet<SkPDFObject*>* newr) {
566 GetResourcesHelper(&fResources.toArray(), known, newr);
567 }
568
569 //////////////////////////////////////////////////////////////////////////////// 554 ////////////////////////////////////////////////////////////////////////////////
570 555
571 static SkPDFObject* get_pdf_shader_by_state( 556 static SkPDFObject* get_pdf_shader_by_state(
572 SkAutoTDelete<SkPDFShader::State>* autoState) { 557 SkAutoTDelete<SkPDFShader::State>* autoState) {
573 const SkPDFShader::State& state = **autoState; 558 const SkPDFShader::State& state = **autoState;
574 if (state.fType == SkShader::kNone_GradientType && state.fImage.isNull()) { 559 if (state.fType == SkShader::kNone_GradientType && state.fImage.isNull()) {
575 // TODO(vandebo) This drops SKComposeShader on the floor. We could 560 // TODO(vandebo) This drops SKComposeShader on the floor. We could
576 // handle compose shader by pulling things up to a layer, drawing with 561 // handle compose shader by pulling things up to a layer, drawing with
577 // the first shader, applying the xfer mode and drawing again with the 562 // the first shader, applying the xfer mode and drawing again with the
578 // second shader, then applying the layer to the original drawing. 563 // second shader, then applying the layer to the original drawing.
(...skipping 543 matching lines...) Expand 10 before | Expand all | Expand 10 after
1122 } 1107 }
1123 } 1108 }
1124 1109
1125 // Put the canvas into the pattern stream (fContent). 1110 // Put the canvas into the pattern stream (fContent).
1126 SkAutoTDelete<SkStream> content(pattern.content()); 1111 SkAutoTDelete<SkStream> content(pattern.content());
1127 1112
1128 SkPDFImageShader* imageShader = 1113 SkPDFImageShader* imageShader =
1129 SkNEW_ARGS(SkPDFImageShader, (autoState->detach())); 1114 SkNEW_ARGS(SkPDFImageShader, (autoState->detach()));
1130 imageShader->setData(content.get()); 1115 imageShader->setData(content.get());
1131 1116
1132 SkPDFResourceDict* resourceDict = pattern.getResourceDict();
1133 resourceDict->getReferencedResources(imageShader->fResources,
1134 &imageShader->fResources, false);
1135
1136 populate_tiling_pattern_dict(imageShader, patternBBox, 1117 populate_tiling_pattern_dict(imageShader, patternBBox,
1137 pattern.getResourceDict(), finalMatrix); 1118 pattern.getResourceDict(), finalMatrix);
1138 1119
1139 imageShader->fShaderState->fImage.unlockPixels(); 1120 imageShader->fShaderState->fImage.unlockPixels();
1140 1121
1141 SkPDFCanon::GetCanon().addImageShader(imageShader); 1122 SkPDFCanon::GetCanon().addImageShader(imageShader);
1142 return imageShader; 1123 return imageShader;
1143 } 1124 }
1144 1125
1145 bool SkPDFShader::State::operator==(const SkPDFShader::State& b) const { 1126 bool SkPDFShader::State::operator==(const SkPDFShader::State& b) const {
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
1325 return false; 1306 return false;
1326 } 1307 }
1327 1308
1328 void SkPDFShader::State::AllocateGradientInfoStorage() { 1309 void SkPDFShader::State::AllocateGradientInfoStorage() {
1329 fColorData.set(sk_malloc_throw( 1310 fColorData.set(sk_malloc_throw(
1330 fInfo.fColorCount * (sizeof(SkColor) + sizeof(SkScalar)))); 1311 fInfo.fColorCount * (sizeof(SkColor) + sizeof(SkScalar))));
1331 fInfo.fColors = reinterpret_cast<SkColor*>(fColorData.get()); 1312 fInfo.fColors = reinterpret_cast<SkColor*>(fColorData.get());
1332 fInfo.fColorOffsets = 1313 fInfo.fColorOffsets =
1333 reinterpret_cast<SkScalar*>(fInfo.fColors + fInfo.fColorCount); 1314 reinterpret_cast<SkScalar*>(fInfo.fColors + fInfo.fColorCount);
1334 } 1315 }
OLDNEW
« no previous file with comments | « src/pdf/SkPDFShader.h ('k') | src/pdf/SkPDFTypes.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698