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 470 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
481 return state == *fShaderState; | 481 return state == *fShaderState; |
482 } | 482 } |
483 | 483 |
484 SkPDFImageShader::~SkPDFImageShader() {} | 484 SkPDFImageShader::~SkPDFImageShader() {} |
485 | 485 |
486 //////////////////////////////////////////////////////////////////////////////// | 486 //////////////////////////////////////////////////////////////////////////////// |
487 | 487 |
488 static SkPDFObject* get_pdf_shader_by_state( | 488 static SkPDFObject* get_pdf_shader_by_state( |
489 SkPDFDocument* doc, | 489 SkPDFDocument* doc, |
490 SkScalar dpi, | 490 SkScalar dpi, |
491 SkAutoTDelete<SkPDFShader::State>* autoState) { | 491 std::unique_ptr<SkPDFShader::State>* autoState) { |
492 const SkPDFShader::State& state = **autoState; | 492 const SkPDFShader::State& state = **autoState; |
493 SkPDFCanon* canon = doc->canon(); | 493 SkPDFCanon* canon = doc->canon(); |
494 if (state.fType == SkShader::kNone_GradientType && state.fImage.isNull()) { | 494 if (state.fType == SkShader::kNone_GradientType && state.fImage.isNull()) { |
495 // TODO(vandebo) This drops SKComposeShader on the floor. We could | 495 // TODO(vandebo) This drops SKComposeShader on the floor. We could |
496 // handle compose shader by pulling things up to a layer, drawing with | 496 // handle compose shader by pulling things up to a layer, drawing with |
497 // the first shader, applying the xfer mode and drawing again with the | 497 // the first shader, applying the xfer mode and drawing again with the |
498 // second shader, then applying the layer to the original drawing. | 498 // second shader, then applying the layer to the original drawing. |
499 return nullptr; | 499 return nullptr; |
500 } else if (state.fType == SkShader::kNone_GradientType) { | 500 } else if (state.fType == SkShader::kNone_GradientType) { |
501 SkPDFObject* shader = canon->findImageShader(state); | 501 SkPDFObject* shader = canon->findImageShader(state); |
(...skipping 10 matching lines...) Expand all Loading... |
512 } | 512 } |
513 } | 513 } |
514 | 514 |
515 // static | 515 // static |
516 SkPDFObject* SkPDFShader::GetPDFShader(SkPDFDocument* doc, | 516 SkPDFObject* SkPDFShader::GetPDFShader(SkPDFDocument* doc, |
517 SkScalar dpi, | 517 SkScalar dpi, |
518 SkShader* shader, | 518 SkShader* shader, |
519 const SkMatrix& matrix, | 519 const SkMatrix& matrix, |
520 const SkIRect& surfaceBBox, | 520 const SkIRect& surfaceBBox, |
521 SkScalar rasterScale) { | 521 SkScalar rasterScale) { |
522 SkAutoTDelete<SkPDFShader::State> state(new State(shader, matrix, surfaceBBo
x, rasterScale)); | 522 std::unique_ptr<SkPDFShader::State> state(new State(shader, matrix, surfaceB
Box, rasterScale)); |
523 return get_pdf_shader_by_state(doc, dpi, &state); | 523 return get_pdf_shader_by_state(doc, dpi, &state); |
524 } | 524 } |
525 | 525 |
526 static sk_sp<SkPDFDict> get_gradient_resource_dict( | 526 static sk_sp<SkPDFDict> get_gradient_resource_dict( |
527 SkPDFObject* functionShader, | 527 SkPDFObject* functionShader, |
528 SkPDFObject* gState) { | 528 SkPDFObject* gState) { |
529 SkTDArray<SkPDFObject*> patterns; | 529 SkTDArray<SkPDFObject*> patterns; |
530 if (functionShader) { | 530 if (functionShader) { |
531 patterns.push(functionShader); | 531 patterns.push(functionShader); |
532 } | 532 } |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
578 | 578 |
579 /** | 579 /** |
580 * Creates a ExtGState with the SMask set to the luminosityShader in | 580 * Creates a ExtGState with the SMask set to the luminosityShader in |
581 * luminosity mode. The shader pattern extends to the bbox. | 581 * luminosity mode. The shader pattern extends to the bbox. |
582 */ | 582 */ |
583 static sk_sp<SkPDFObject> create_smask_graphic_state( | 583 static sk_sp<SkPDFObject> create_smask_graphic_state( |
584 SkPDFDocument* doc, SkScalar dpi, const SkPDFShader::State& state) { | 584 SkPDFDocument* doc, SkScalar dpi, const SkPDFShader::State& state) { |
585 SkRect bbox; | 585 SkRect bbox; |
586 bbox.set(state.fBBox); | 586 bbox.set(state.fBBox); |
587 | 587 |
588 SkAutoTDelete<SkPDFShader::State> alphaToLuminosityState( | 588 std::unique_ptr<SkPDFShader::State> alphaToLuminosityState( |
589 state.CreateAlphaToLuminosityState()); | 589 state.CreateAlphaToLuminosityState()); |
590 sk_sp<SkPDFObject> luminosityShader( | 590 sk_sp<SkPDFObject> luminosityShader( |
591 get_pdf_shader_by_state(doc, dpi, &alphaToLuminosityState)); | 591 get_pdf_shader_by_state(doc, dpi, &alphaToLuminosityState)); |
592 | 592 |
593 SkAutoTDelete<SkStream> alphaStream(create_pattern_fill_content(-1, bbox)); | 593 std::unique_ptr<SkStream> alphaStream(create_pattern_fill_content(-1, bbox))
; |
594 | 594 |
595 auto resources = | 595 auto resources = |
596 get_gradient_resource_dict(luminosityShader.get(), nullptr); | 596 get_gradient_resource_dict(luminosityShader.get(), nullptr); |
597 | 597 |
598 sk_sp<SkPDFFormXObject> alphaMask( | 598 sk_sp<SkPDFFormXObject> alphaMask( |
599 new SkPDFFormXObject(alphaStream.get(), bbox, resources.get())); | 599 new SkPDFFormXObject(alphaStream.get(), bbox, resources.get())); |
600 | 600 |
601 return SkPDFGraphicState::GetSMaskGraphicState( | 601 return SkPDFGraphicState::GetSMaskGraphicState( |
602 alphaMask.get(), false, | 602 alphaMask.get(), false, |
603 SkPDFGraphicState::kLuminosity_SMaskMode, doc->canon()); | 603 SkPDFGraphicState::kLuminosity_SMaskMode, doc->canon()); |
604 } | 604 } |
605 | 605 |
606 SkPDFAlphaFunctionShader* SkPDFAlphaFunctionShader::Create( | 606 SkPDFAlphaFunctionShader* SkPDFAlphaFunctionShader::Create( |
607 SkPDFDocument* doc, | 607 SkPDFDocument* doc, |
608 SkScalar dpi, | 608 SkScalar dpi, |
609 SkAutoTDelete<SkPDFShader::State>* autoState) { | 609 std::unique_ptr<SkPDFShader::State>* autoState) { |
610 const SkPDFShader::State& state = **autoState; | 610 const SkPDFShader::State& state = **autoState; |
611 SkRect bbox; | 611 SkRect bbox; |
612 bbox.set(state.fBBox); | 612 bbox.set(state.fBBox); |
613 | 613 |
614 SkAutoTDelete<SkPDFShader::State> opaqueState(state.CreateOpaqueState()); | 614 std::unique_ptr<SkPDFShader::State> opaqueState(state.CreateOpaqueState()); |
615 | 615 |
616 sk_sp<SkPDFObject> colorShader( | 616 sk_sp<SkPDFObject> colorShader( |
617 get_pdf_shader_by_state(doc, dpi, &opaqueState)); | 617 get_pdf_shader_by_state(doc, dpi, &opaqueState)); |
618 if (!colorShader) { | 618 if (!colorShader) { |
619 return nullptr; | 619 return nullptr; |
620 } | 620 } |
621 | 621 |
622 // Create resource dict with alpha graphics state as G0 and | 622 // Create resource dict with alpha graphics state as G0 and |
623 // pattern shader as P0, then write content stream. | 623 // pattern shader as P0, then write content stream. |
624 auto alphaGs = create_smask_graphic_state(doc, dpi, state); | 624 auto alphaGs = create_smask_graphic_state(doc, dpi, state); |
625 | 625 |
626 SkPDFAlphaFunctionShader* alphaFunctionShader = | 626 SkPDFAlphaFunctionShader* alphaFunctionShader = |
627 new SkPDFAlphaFunctionShader(autoState->release()); | 627 new SkPDFAlphaFunctionShader(autoState->release()); |
628 | 628 |
629 auto resourceDict = | 629 auto resourceDict = |
630 get_gradient_resource_dict(colorShader.get(), alphaGs.get()); | 630 get_gradient_resource_dict(colorShader.get(), alphaGs.get()); |
631 | 631 |
632 SkAutoTDelete<SkStream> colorStream( | 632 std::unique_ptr<SkStream> colorStream( |
633 create_pattern_fill_content(0, bbox)); | 633 create_pattern_fill_content(0, bbox)); |
634 alphaFunctionShader->setData(colorStream.get()); | 634 alphaFunctionShader->setData(colorStream.get()); |
635 | 635 |
636 populate_tiling_pattern_dict(alphaFunctionShader, bbox, resourceDict.get(), | 636 populate_tiling_pattern_dict(alphaFunctionShader, bbox, resourceDict.get(), |
637 SkMatrix::I()); | 637 SkMatrix::I()); |
638 doc->canon()->addAlphaShader(alphaFunctionShader); | 638 doc->canon()->addAlphaShader(alphaFunctionShader); |
639 return alphaFunctionShader; | 639 return alphaFunctionShader; |
640 } | 640 } |
641 | 641 |
642 // Finds affine and persp such that in = affine * persp. | 642 // Finds affine and persp such that in = affine * persp. |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
694 SkPDFArray* domain, | 694 SkPDFArray* domain, |
695 sk_sp<SkPDFObject> range) { | 695 sk_sp<SkPDFObject> range) { |
696 auto result = sk_make_sp<SkPDFStream>(psCode.get()); | 696 auto result = sk_make_sp<SkPDFStream>(psCode.get()); |
697 result->insertInt("FunctionType", 4); | 697 result->insertInt("FunctionType", 4); |
698 result->insertObject("Domain", sk_ref_sp(domain)); | 698 result->insertObject("Domain", sk_ref_sp(domain)); |
699 result->insertObject("Range", std::move(range)); | 699 result->insertObject("Range", std::move(range)); |
700 return result; | 700 return result; |
701 } | 701 } |
702 | 702 |
703 SkPDFFunctionShader* SkPDFFunctionShader::Create( | 703 SkPDFFunctionShader* SkPDFFunctionShader::Create( |
704 SkPDFCanon* canon, SkAutoTDelete<SkPDFShader::State>* autoState) { | 704 SkPDFCanon* canon, std::unique_ptr<SkPDFShader::State>* autoState) { |
705 const SkPDFShader::State& state = **autoState; | 705 const SkPDFShader::State& state = **autoState; |
706 | 706 |
707 void (*codeFunction)(const SkShader::GradientInfo& info, | 707 void (*codeFunction)(const SkShader::GradientInfo& info, |
708 const SkMatrix& perspectiveRemover, | 708 const SkMatrix& perspectiveRemover, |
709 SkDynamicMemoryWStream* function) = nullptr; | 709 SkDynamicMemoryWStream* function) = nullptr; |
710 SkPoint transformPoints[2]; | 710 SkPoint transformPoints[2]; |
711 | 711 |
712 // Depending on the type of the gradient, we want to transform the | 712 // Depending on the type of the gradient, we want to transform the |
713 // coordinate space in different ways. | 713 // coordinate space in different ways. |
714 const SkShader::GradientInfo* info = &state.fInfo; | 714 const SkShader::GradientInfo* info = &state.fInfo; |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
819 SkPDFUtils::MatrixToArray(finalMatrix)); | 819 SkPDFUtils::MatrixToArray(finalMatrix)); |
820 pdfFunctionShader->insertObject("Shading", std::move(pdfShader)); | 820 pdfFunctionShader->insertObject("Shading", std::move(pdfShader)); |
821 | 821 |
822 canon->addFunctionShader(pdfFunctionShader.get()); | 822 canon->addFunctionShader(pdfFunctionShader.get()); |
823 return pdfFunctionShader.release(); | 823 return pdfFunctionShader.release(); |
824 } | 824 } |
825 | 825 |
826 SkPDFImageShader* SkPDFImageShader::Create( | 826 SkPDFImageShader* SkPDFImageShader::Create( |
827 SkPDFDocument* doc, | 827 SkPDFDocument* doc, |
828 SkScalar dpi, | 828 SkScalar dpi, |
829 SkAutoTDelete<SkPDFShader::State>* autoState) { | 829 std::unique_ptr<SkPDFShader::State>* autoState) { |
830 const SkPDFShader::State& state = **autoState; | 830 const SkPDFShader::State& state = **autoState; |
831 | 831 |
832 state.fImage.lockPixels(); | 832 state.fImage.lockPixels(); |
833 | 833 |
834 // The image shader pattern cell will be drawn into a separate device | 834 // The image shader pattern cell will be drawn into a separate device |
835 // in pattern cell space (no scaling on the bitmap, though there may be | 835 // in pattern cell space (no scaling on the bitmap, though there may be |
836 // translations so that all content is in the device, coordinates > 0). | 836 // translations so that all content is in the device, coordinates > 0). |
837 | 837 |
838 // Map clip bounds to shader space to ensure the device is large enough | 838 // Map clip bounds to shader space to ensure the device is large enough |
839 // to handle fake clamping. | 839 // to handle fake clamping. |
(...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1227 return false; | 1227 return false; |
1228 } | 1228 } |
1229 | 1229 |
1230 void SkPDFShader::State::AllocateGradientInfoStorage() { | 1230 void SkPDFShader::State::AllocateGradientInfoStorage() { |
1231 fColorData.set(sk_malloc_throw( | 1231 fColorData.set(sk_malloc_throw( |
1232 fInfo.fColorCount * (sizeof(SkColor) + sizeof(SkScalar)))); | 1232 fInfo.fColorCount * (sizeof(SkColor) + sizeof(SkScalar)))); |
1233 fInfo.fColors = reinterpret_cast<SkColor*>(fColorData.get()); | 1233 fInfo.fColors = reinterpret_cast<SkColor*>(fColorData.get()); |
1234 fInfo.fColorOffsets = | 1234 fInfo.fColorOffsets = |
1235 reinterpret_cast<SkScalar*>(fInfo.fColors + fInfo.fColorCount); | 1235 reinterpret_cast<SkScalar*>(fInfo.fColors + fInfo.fColorCount); |
1236 } | 1236 } |
OLD | NEW |