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

Side by Side Diff: core/fxge/skia/fx_skia_device.cpp

Issue 2546803003: re-enable skia caching (Closed)
Patch Set: remove nullptr Created 4 years 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 | « core/fxge/skia/fx_skia_device.h ('k') | fpdfsdk/fpdfformfill.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <algorithm> 5 #include <algorithm>
6 #include <utility> 6 #include <utility>
7 #include <vector> 7 #include <vector>
8 8
9 #include "core/fpdfapi/page/cpdf_meshstream.h" 9 #include "core/fpdfapi/page/cpdf_meshstream.h"
10 #include "core/fpdfapi/page/cpdf_shadingpattern.h" 10 #include "core/fpdfapi/page/cpdf_shadingpattern.h"
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 } 148 }
149 149
150 ASSERT(false); 150 ASSERT(false);
151 } 151 }
152 152
153 #endif // _SKIA_SUPPORT_PATHS_ 153 #endif // _SKIA_SUPPORT_PATHS_
154 154
155 #define SHOW_SKIA_PATH 0 // set to 1 to print the path contents 155 #define SHOW_SKIA_PATH 0 // set to 1 to print the path contents
156 #define DRAW_SKIA_CLIP 0 // set to 1 to draw a green rectangle around the clip 156 #define DRAW_SKIA_CLIP 0 // set to 1 to draw a green rectangle around the clip
157 157
158 #if SHOW_SKIA_PATH
159 void DebugShowSkiaPaint(const SkPaint& paint) {
160 if (SkPaint::kFill_Style == paint.getStyle()) {
161 printf("fill 0x%08x\n", paint.getColor());
162 } else {
163 printf("stroke 0x%08x width %g\n", paint.getColor(),
164 paint.getStrokeWidth());
165 }
166 }
167
168 void DebugShowCanvasMatrix(const SkCanvas* canvas) {
169 SkMatrix matrix = canvas->getTotalMatrix();
170 SkScalar m[9];
171 matrix.get9(m);
172 printf("matrix (%g,%g,%g) (%g,%g,%g) (%g,%g,%g)\n", m[0], m[1], m[2], m[3],
173 m[4], m[5], m[6], m[7], m[8]);
174 }
175 #endif // SHOW_SKIA_PATH
176
158 void DebugShowSkiaPath(const SkPath& path) { 177 void DebugShowSkiaPath(const SkPath& path) {
159 #if SHOW_SKIA_PATH 178 #if SHOW_SKIA_PATH
160 char buffer[4096]; 179 char buffer[4096];
161 sk_bzero(buffer, sizeof(buffer)); 180 sk_bzero(buffer, sizeof(buffer));
162 SkMemoryWStream stream(buffer, sizeof(buffer)); 181 SkMemoryWStream stream(buffer, sizeof(buffer));
163 path.dump(&stream, false, false); 182 path.dump(&stream, false, false);
164 printf("%s", buffer); 183 printf("%s", buffer);
165 #endif // SHOW_SKIA_PATH 184 #endif // SHOW_SKIA_PATH
166 } 185 }
167 186
168 void DebugShowCanvasMatrix(const SkCanvas* canvas) { 187 void DebugShowCanvasClip(const SkCanvas* canvas) {
169 #if SHOW_SKIA_PATH 188 #if SHOW_SKIA_PATH
170 SkMatrix matrix = canvas->getTotalMatrix();
171 SkScalar m[9];
172 matrix.get9(m);
173 printf("matrix (%g,%g,%g) (%g,%g,%g) (%g,%g,%g)\n", m[0], m[1], m[2], m[3],
174 m[4], m[5], m[6], m[7], m[8]);
175 #endif // SHOW_SKIA_PATH
176 }
177
178 #if SHOW_SKIA_PATH
179 void DebugShowCanvasClip(const SkCanvas* canvas) {
180 SkRect local; 189 SkRect local;
181 SkIRect device; 190 SkIRect device;
182 canvas->getClipBounds(&local); 191 canvas->getClipBounds(&local);
183 printf("local bounds %g %g %g %g\n", local.fLeft, local.fTop, local.fRight, 192 printf("local bounds %g %g %g %g\n", local.fLeft, local.fTop, local.fRight,
184 local.fBottom); 193 local.fBottom);
185 canvas->getClipDeviceBounds(&device); 194 canvas->getClipDeviceBounds(&device);
186 printf("device bounds %d %d %d %d\n", device.fLeft, device.fTop, 195 printf("device bounds %d %d %d %d\n", device.fLeft, device.fTop,
187 device.fRight, device.fBottom); 196 device.fRight, device.fBottom);
188 const SkClipStack* clipStack = canvas->getClipStack(); 197 const SkClipStack* clipStack = canvas->getClipStack();
189 clipStack->dump(); 198 clipStack->dump();
199 #endif // SHOW_SKIA_PATH
190 } 200 }
191 201
202 #if SHOW_SKIA_PATH
192 void DebugShowSkiaPaint(const SkPaint& paint) { 203 void DebugShowSkiaPaint(const SkPaint& paint) {
193 if (SkPaint::kFill_Style == paint.getStyle()) { 204 if (SkPaint::kFill_Style == paint.getStyle()) {
194 printf("fill 0x%08x\n", paint.getColor()); 205 printf("fill 0x%08x\n", paint.getColor());
195 } else { 206 } else {
196 printf("stroke 0x%08x width %g\n", paint.getColor(), 207 printf("stroke 0x%08x width %g\n", paint.getColor(),
197 paint.getStrokeWidth()); 208 paint.getStrokeWidth());
198 } 209 }
199 } 210 }
200 #endif // SHOW_SKIA_PATH 211 #endif // SHOW_SKIA_PATH
201 212
(...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after
627 skBitmap->installPixels(imageInfo, buffer, rowBytes, *ctPtr, nullptr, 638 skBitmap->installPixels(imageInfo, buffer, rowBytes, *ctPtr, nullptr,
628 nullptr); 639 nullptr);
629 *widthPtr = width; 640 *widthPtr = width;
630 *heightPtr = height; 641 *heightPtr = height;
631 return true; 642 return true;
632 } 643 }
633 #endif // _SKIA_SUPPORT_ 644 #endif // _SKIA_SUPPORT_
634 645
635 } // namespace 646 } // namespace
636 647
637 #ifdef _SKIA_SUPPORT_
638 // Encapsulate the state used for successive text and path draws so that 648 // Encapsulate the state used for successive text and path draws so that
639 // they can be combined. 649 // they can be combined.
640 class SkiaState { 650 class SkiaState {
641 public: 651 public:
642 enum class Clip { 652 enum class Clip {
643 kSave, 653 kSave,
644 kPath, 654 kPath,
645 }; 655 };
646 656
657 enum class Accumulator {
658 kNone,
659 kPath,
660 kText,
661 kOther,
662 };
663
647 // mark all cached state as uninitialized 664 // mark all cached state as uninitialized
648 SkiaState() 665 explicit SkiaState(CFX_SkiaDeviceDriver* pDriver)
649 : m_pFont(nullptr), 666 : m_pDriver(pDriver),
667 m_pFont(nullptr),
650 m_fontSize(0), 668 m_fontSize(0),
651 m_fillColor(0), 669 m_fillColor(0),
652 m_strokeColor(0), 670 m_strokeColor(0),
653 m_blendType(0), 671 m_blendType(0),
654 m_commandIndex(0), 672 m_commandIndex(0),
655 m_drawText(false), 673 m_drawIndex(INT_MAX),
656 m_drawPath(false), 674 m_clipIndex(0),
675 m_type(Accumulator::kNone),
676 m_fillFullCover(false),
657 m_fillPath(false), 677 m_fillPath(false),
658 m_groupKnockout(false), 678 m_groupKnockout(false),
659 m_debugDisable(false) {} 679 m_debugDisable(false)
680 #if SHOW_SKIA_PATH
681 ,
682 m_debugSaveCounter(0)
683 #endif
684 {
685 }
660 686
661 bool DrawPath(const CFX_PathData* pPathData, 687 bool DrawPath(const CFX_PathData* pPathData,
662 const CFX_Matrix* pMatrix, 688 const CFX_Matrix* pMatrix,
663 const CFX_GraphStateData* pDrawState, 689 const CFX_GraphStateData* pDrawState,
664 uint32_t fill_color, 690 uint32_t fill_color,
665 uint32_t stroke_color, 691 uint32_t stroke_color,
666 int fill_mode, 692 int fill_mode,
667 int blend_type, 693 int blend_type) {
668 CFX_SkiaDeviceDriver* pDriver) {
669 if (m_debugDisable) 694 if (m_debugDisable)
670 return false; 695 return false;
671 if (m_commandIndex < m_commands.count()) 696 Dump(__func__);
672 FlushCommands(pDriver); 697 int drawIndex = SkTMin(m_drawIndex, m_commands.count());
673 if (m_drawText) 698 if (Accumulator::kText == m_type || drawIndex != m_commandIndex ||
674 FlushText(pDriver); 699 (Accumulator::kPath == m_type &&
675 if (m_drawPath && 700 DrawChanged(pMatrix, pDrawState, fill_color, stroke_color, fill_mode,
676 DrawChanged(pMatrix, pDrawState, fill_color, stroke_color, fill_mode, 701 blend_type, m_pDriver->m_bGroupKnockout))) {
677 blend_type, pDriver->m_bGroupKnockout)) { 702 Flush();
678 FlushPath(pDriver);
679 } 703 }
680 if (!m_drawPath) { 704 if (Accumulator::kPath != m_type) {
681 m_skPath.reset(); 705 m_skPath.reset();
706 m_fillFullCover = !!(fill_mode & FXFILL_FULLCOVER);
682 m_fillPath = (fill_mode & 3) && fill_color; 707 m_fillPath = (fill_mode & 3) && fill_color;
683 m_skPath.setFillType((fill_mode & 3) == FXFILL_ALTERNATE 708 m_skPath.setFillType((fill_mode & 3) == FXFILL_ALTERNATE
684 ? SkPath::kEvenOdd_FillType 709 ? SkPath::kEvenOdd_FillType
685 : SkPath::kWinding_FillType); 710 : SkPath::kWinding_FillType);
686 if (pDrawState) 711 if (pDrawState)
687 m_drawState.Copy(*pDrawState); 712 m_drawState.Copy(*pDrawState);
688 m_fillColor = fill_color; 713 m_fillColor = fill_color;
689 m_strokeColor = stroke_color; 714 m_strokeColor = stroke_color;
690 m_blendType = blend_type; 715 m_blendType = blend_type;
691 m_groupKnockout = pDriver->m_bGroupKnockout; 716 m_groupKnockout = m_pDriver->m_bGroupKnockout;
692 if (pMatrix) 717 if (pMatrix)
693 m_drawMatrix = *pMatrix; 718 m_drawMatrix = *pMatrix;
719 m_drawIndex = m_commandIndex;
720 m_type = Accumulator::kPath;
694 } 721 }
695 SkPath skPath = BuildPath(pPathData); 722 SkPath skPath = BuildPath(pPathData);
696 SkPoint delta; 723 SkPoint delta;
697 if (MatrixOffset(pMatrix, &delta)) 724 if (MatrixOffset(pMatrix, &delta))
698 skPath.offset(delta.fX, delta.fY); 725 skPath.offset(delta.fX, delta.fY);
699 m_skPath.addPath(skPath); 726 m_skPath.addPath(skPath);
700 m_drawPath = true;
701 return true; 727 return true;
702 } 728 }
703 729
704 void FlushPath(CFX_SkiaDeviceDriver* pDriver) { 730 void FlushPath() {
731 Dump(__func__);
705 SkMatrix skMatrix = ToSkMatrix(m_drawMatrix); 732 SkMatrix skMatrix = ToSkMatrix(m_drawMatrix);
706 SkPaint skPaint; 733 SkPaint skPaint;
707 skPaint.setAntiAlias(true); 734 skPaint.setAntiAlias(true);
735 if (m_fillFullCover)
736 skPaint.setBlendMode(SkBlendMode::kPlus);
708 int stroke_alpha = FXARGB_A(m_strokeColor); 737 int stroke_alpha = FXARGB_A(m_strokeColor);
709 if (stroke_alpha) 738 if (stroke_alpha)
710 pDriver->PaintStroke(&skPaint, &m_drawState, skMatrix); 739 m_pDriver->PaintStroke(&skPaint, &m_drawState, skMatrix);
711 SkCanvas* skCanvas = pDriver->SkiaCanvas(); 740 SkCanvas* skCanvas = m_pDriver->SkiaCanvas();
712 skCanvas->save(); 741 skCanvas->save();
713 skCanvas->concat(skMatrix); 742 skCanvas->concat(skMatrix);
714 if (m_fillPath) { 743 if (m_fillPath) {
715 SkPath strokePath; 744 SkPath strokePath;
716 const SkPath* fillPath = &m_skPath; 745 const SkPath* fillPath = &m_skPath;
717 if (stroke_alpha) { 746 if (stroke_alpha) {
718 if (m_groupKnockout) { 747 if (m_groupKnockout) {
719 skPaint.getFillPath(m_skPath, &strokePath); 748 skPaint.getFillPath(m_skPath, &strokePath);
720 if (Op(m_skPath, strokePath, SkPathOp::kDifference_SkPathOp, 749 if (Op(m_skPath, strokePath, SkPathOp::kDifference_SkPathOp,
721 &strokePath)) { 750 &strokePath)) {
722 fillPath = &strokePath; 751 fillPath = &strokePath;
723 } 752 }
724 } 753 }
725 } 754 }
726 skPaint.setStyle(SkPaint::kFill_Style); 755 skPaint.setStyle(SkPaint::kFill_Style);
727 skPaint.setColor(m_fillColor); 756 skPaint.setColor(m_fillColor);
757 #ifdef _SKIA_SUPPORT_PATHS_
758 m_pDriver->PreMultiply();
759 #endif // _SKIA_SUPPORT_PATHS_
760 DebugShowSkiaDrawPath(skCanvas, skPaint, *fillPath);
728 skCanvas->drawPath(*fillPath, skPaint); 761 skCanvas->drawPath(*fillPath, skPaint);
729 } 762 }
730 if (stroke_alpha) { 763 if (stroke_alpha) {
731 DebugShowSkiaPath(m_skPath);
732 DebugShowCanvasMatrix(skCanvas);
733 skPaint.setStyle(SkPaint::kStroke_Style); 764 skPaint.setStyle(SkPaint::kStroke_Style);
734 skPaint.setColor(m_strokeColor); 765 skPaint.setColor(m_strokeColor);
766 #ifdef _SKIA_SUPPORT_PATHS_
767 m_pDriver->PreMultiply();
768 #endif // _SKIA_SUPPORT_PATHS_
769 DebugShowSkiaDrawPath(skCanvas, skPaint, m_skPath);
735 skCanvas->drawPath(m_skPath, skPaint); 770 skCanvas->drawPath(m_skPath, skPaint);
736 } 771 }
737 skCanvas->restore(); 772 skCanvas->restore();
738 m_drawPath = false; 773 m_drawIndex = INT_MAX;
774 m_type = Accumulator::kNone;
739 } 775 }
740 776
741 bool DrawText(int nChars, 777 bool DrawText(int nChars,
742 const FXTEXT_CHARPOS* pCharPos, 778 const FXTEXT_CHARPOS* pCharPos,
743 CFX_Font* pFont, 779 CFX_Font* pFont,
744 const CFX_Matrix* pMatrix, 780 const CFX_Matrix* pMatrix,
745 FX_FLOAT font_size, 781 FX_FLOAT font_size,
746 uint32_t color, 782 uint32_t color) {
747 CFX_SkiaDeviceDriver* pDriver) {
748 if (m_debugDisable) 783 if (m_debugDisable)
749 return false; 784 return false;
750 if (m_commandIndex < m_commands.count()) 785 Dump(__func__);
751 FlushCommands(pDriver); 786 int drawIndex = SkTMin(m_drawIndex, m_commands.count());
752 if (m_drawPath) 787 if (Accumulator::kPath == m_type || drawIndex != m_commandIndex ||
753 FlushPath(pDriver); 788 (Accumulator::kText == m_type &&
754 if (m_drawText && FontChanged(pFont, pMatrix, font_size, color)) 789 FontChanged(pFont, pMatrix, font_size, color))) {
755 FlushText(pDriver); 790 Flush();
756 if (!m_drawText) { 791 }
792 if (Accumulator::kText != m_type) {
757 m_positions.setCount(0); 793 m_positions.setCount(0);
758 m_glyphs.setCount(0); 794 m_glyphs.setCount(0);
759 m_pFont = pFont; 795 m_pFont = pFont;
760 m_fontSize = font_size; 796 m_fontSize = font_size;
761 m_fillColor = color; 797 m_fillColor = color;
762 m_drawMatrix = *pMatrix; 798 m_drawMatrix = *pMatrix;
799 m_drawIndex = m_commandIndex;
800 m_type = Accumulator::kText;
763 } 801 }
764 int count = m_positions.count(); 802 int count = m_positions.count();
765 m_positions.setCount(nChars + count); 803 m_positions.setCount(nChars + count);
766 m_glyphs.setCount(nChars + count); 804 m_glyphs.setCount(nChars + count);
767 SkScalar flip = m_fontSize < 0 ? -1 : 1; 805 SkScalar flip = m_fontSize < 0 ? -1 : 1;
806 SkScalar vFlip = flip;
807 if (pFont->IsVertical())
808 vFlip *= -1;
768 for (int index = 0; index < nChars; ++index) { 809 for (int index = 0; index < nChars; ++index) {
769 const FXTEXT_CHARPOS& cp = pCharPos[index]; 810 const FXTEXT_CHARPOS& cp = pCharPos[index];
770 m_positions[index + count] = {cp.m_OriginX * flip, cp.m_OriginY * flip}; 811 m_positions[index + count] = {cp.m_OriginX * flip, cp.m_OriginY * vFlip};
771 m_glyphs[index + count] = (uint16_t)cp.m_GlyphIndex; 812 m_glyphs[index + count] = (uint16_t)cp.m_GlyphIndex;
772 } 813 }
773 SkPoint delta; 814 SkPoint delta;
774 if (MatrixOffset(pMatrix, &delta)) { 815 if (MatrixOffset(pMatrix, &delta)) {
775 for (int index = 0; index < nChars; ++index) 816 for (int index = 0; index < nChars; ++index)
776 m_positions[index + count].offset(delta.fX * flip, -delta.fY * flip); 817 m_positions[index + count].offset(delta.fX * flip, -delta.fY * flip);
777 } 818 }
778 m_drawText = true;
779 return true; 819 return true;
780 } 820 }
781 821
782 void FlushText(CFX_SkiaDeviceDriver* pDriver) { 822 void FlushText() {
783 SkScalar flip = m_fontSize < 0 ? -1 : 1; 823 Dump(__func__);
784 SkMatrix skMatrix = ToFlippedSkMatrix(m_drawMatrix, flip);
785 SkPaint skPaint; 824 SkPaint skPaint;
786 skPaint.setAntiAlias(true); 825 skPaint.setAntiAlias(true);
787 skPaint.setColor(m_fillColor); 826 skPaint.setColor(m_fillColor);
788 if (m_pFont->GetFace()) { // exclude placeholder test fonts 827 if (m_pFont->GetFace()) { // exclude placeholder test fonts
789 sk_sp<SkTypeface> typeface(SkSafeRef(m_pFont->GetDeviceCache())); 828 sk_sp<SkTypeface> typeface(SkSafeRef(m_pFont->GetDeviceCache()));
790 skPaint.setTypeface(typeface); 829 skPaint.setTypeface(typeface);
791 } 830 }
792 skPaint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); 831 skPaint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
793 skPaint.setHinting(SkPaint::kNo_Hinting); 832 skPaint.setHinting(SkPaint::kNo_Hinting);
794 skPaint.setTextSize(SkTAbs(m_fontSize)); 833 skPaint.setTextSize(SkTAbs(m_fontSize));
795 skPaint.setSubpixelText(true); 834 skPaint.setSubpixelText(true);
796 SkCanvas* skCanvas = pDriver->SkiaCanvas(); 835 SkCanvas* skCanvas = m_pDriver->SkiaCanvas();
797 skCanvas->save(); 836 skCanvas->save();
837 SkScalar flip = m_fontSize < 0 ? -1 : 1;
838 SkMatrix skMatrix = ToFlippedSkMatrix(m_drawMatrix, flip);
798 skCanvas->concat(skMatrix); 839 skCanvas->concat(skMatrix);
840 #ifdef _SKIA_SUPPORT_PATHS_
841 m_pDriver->PreMultiply();
842 #endif // _SKIA_SUPPORT_PATHS_
799 skCanvas->drawPosText(m_glyphs.begin(), m_glyphs.count() * 2, 843 skCanvas->drawPosText(m_glyphs.begin(), m_glyphs.count() * 2,
800 m_positions.begin(), skPaint); 844 m_positions.begin(), skPaint);
801 skCanvas->restore(); 845 skCanvas->restore();
802 m_drawText = false; 846 m_drawIndex = INT_MAX;
847 m_type = Accumulator::kNone;
803 } 848 }
804 849
805 bool SetClipFill(const CFX_PathData* pPathData, 850 bool SetClipFill(const CFX_PathData* pPathData,
806 const CFX_Matrix* pMatrix, 851 const CFX_Matrix* pMatrix,
807 int fill_mode, 852 int fill_mode) {
808 CFX_SkiaDeviceDriver* pDriver) {
809 if (m_debugDisable) 853 if (m_debugDisable)
810 return false; 854 return false;
855 Dump(__func__);
811 SkPath skClipPath = BuildPath(pPathData); 856 SkPath skClipPath = BuildPath(pPathData);
812 skClipPath.setFillType((fill_mode & 3) == FXFILL_ALTERNATE 857 skClipPath.setFillType((fill_mode & 3) == FXFILL_ALTERNATE
813 ? SkPath::kEvenOdd_FillType 858 ? SkPath::kEvenOdd_FillType
814 : SkPath::kWinding_FillType); 859 : SkPath::kWinding_FillType);
815 SkMatrix skMatrix = ToSkMatrix(*pMatrix); 860 SkMatrix skMatrix = ToSkMatrix(*pMatrix);
816 skClipPath.transform(skMatrix); 861 skClipPath.transform(skMatrix);
817 return SetClip(skClipPath, pDriver); 862 return SetClip(skClipPath);
818 } 863 }
819 864
820 bool SetClip(const SkPath& skClipPath, CFX_SkiaDeviceDriver* pDriver) { 865 bool SetClip(const SkPath& skClipPath) {
866 // if a pending draw depends on clip state that is cached, flush it and draw
821 if (m_commandIndex < m_commands.count()) { 867 if (m_commandIndex < m_commands.count()) {
822 if (m_commands[m_commandIndex] == Clip::kPath && 868 if (m_commands[m_commandIndex] == Clip::kPath &&
823 m_clips[m_commandIndex] == skClipPath) { 869 m_clips[m_commandIndex] == skClipPath) {
824 ++m_commandIndex; 870 ++m_commandIndex;
825 return true; 871 return true;
826 } 872 }
827 FlushCommands(pDriver); 873 Flush();
828 } 874 }
829 Flush(pDriver); 875 while (m_clipIndex > m_commandIndex) {
830 m_commands.push(Clip::kPath); 876 do {
877 --m_clipIndex;
878 SkASSERT(m_clipIndex >= 0);
879 } while (m_commands[m_clipIndex] != Clip::kSave);
880 m_pDriver->SkiaCanvas()->restore();
881 }
882 if (m_commandIndex < m_commands.count()) {
883 m_commands[m_commandIndex] = Clip::kPath;
884 m_clips[m_commandIndex] = skClipPath;
885 } else {
886 m_commands.push(Clip::kPath);
887 m_clips.push_back(skClipPath);
888 }
831 ++m_commandIndex; 889 ++m_commandIndex;
832 m_clips.push_back(skClipPath); 890 return true;
833 return false;
834 } 891 }
835 892
836 bool SetClipStroke(const CFX_PathData* pPathData, 893 bool SetClipStroke(const CFX_PathData* pPathData,
837 const CFX_Matrix* pMatrix, 894 const CFX_Matrix* pMatrix,
838 const CFX_GraphStateData* pGraphState, 895 const CFX_GraphStateData* pGraphState) {
839 CFX_SkiaDeviceDriver* pDriver) {
840 if (m_debugDisable) 896 if (m_debugDisable)
841 return false; 897 return false;
898 Dump(__func__);
842 SkPath skPath = BuildPath(pPathData); 899 SkPath skPath = BuildPath(pPathData);
843 SkMatrix skMatrix = ToSkMatrix(*pMatrix); 900 SkMatrix skMatrix = ToSkMatrix(*pMatrix);
844 SkPaint skPaint; 901 SkPaint skPaint;
845 pDriver->PaintStroke(&skPaint, pGraphState, skMatrix); 902 m_pDriver->PaintStroke(&skPaint, pGraphState, skMatrix);
846 SkPath dst_path; 903 SkPath dst_path;
847 skPaint.getFillPath(skPath, &dst_path); 904 skPaint.getFillPath(skPath, &dst_path);
848 dst_path.transform(skMatrix); 905 dst_path.transform(skMatrix);
849 return SetClip(dst_path, pDriver); 906 return SetClip(dst_path);
850 } 907 }
851 908
852 bool MatrixOffset(const CFX_Matrix* pMatrix, SkPoint* delta) { 909 bool MatrixOffset(const CFX_Matrix* pMatrix, SkPoint* delta) {
853 CFX_Matrix identityMatrix; 910 CFX_Matrix identityMatrix;
854 if (!pMatrix) 911 if (!pMatrix)
855 pMatrix = &identityMatrix; 912 pMatrix = &identityMatrix;
856 delta->set(pMatrix->e - m_drawMatrix.e, pMatrix->f - m_drawMatrix.f); 913 delta->set(pMatrix->e - m_drawMatrix.e, pMatrix->f - m_drawMatrix.f);
857 if (!delta->fX && !delta->fY) 914 if (!delta->fX && !delta->fY)
858 return true; 915 return true;
859 SkMatrix drawMatrix = ToSkMatrix(m_drawMatrix); 916 SkMatrix drawMatrix = ToSkMatrix(m_drawMatrix);
860 if (!(drawMatrix.getType() & ~SkMatrix::kTranslate_Mask)) 917 if (!(drawMatrix.getType() & ~SkMatrix::kTranslate_Mask))
861 return true; 918 return true;
862 SkMatrix invDrawMatrix; 919 SkMatrix invDrawMatrix;
863 if (!drawMatrix.invert(&invDrawMatrix)) 920 if (!drawMatrix.invert(&invDrawMatrix))
864 return false; 921 return false;
865 SkMatrix invNewMatrix; 922 SkMatrix invNewMatrix;
866 SkMatrix newMatrix = ToSkMatrix(*pMatrix); 923 SkMatrix newMatrix = ToSkMatrix(*pMatrix);
867 if (!newMatrix.invert(&invNewMatrix)) 924 if (!newMatrix.invert(&invNewMatrix))
868 return false; 925 return false;
869 delta->set(invDrawMatrix.getTranslateX() - invNewMatrix.getTranslateX(), 926 delta->set(invDrawMatrix.getTranslateX() - invNewMatrix.getTranslateX(),
870 invDrawMatrix.getTranslateY() - invNewMatrix.getTranslateY()); 927 invDrawMatrix.getTranslateY() - invNewMatrix.getTranslateY());
871 return true; 928 return true;
872 } 929 }
873 930
874 void FlushCommands(CFX_SkiaDeviceDriver* pDriver) {
875 if (m_commandIndex == m_commands.count())
876 return;
877 if (m_commandIndex < m_commands.count())
878 pDriver->SkiaCanvas()->restore();
879 int index = m_commands.count() - 1;
880 if (m_commandIndex == index && m_commands[index] == Clip::kSave)
881 return;
882 for (; index > m_commandIndex; --index) {
883 if (m_commands[index] == Clip::kSave)
884 pDriver->SkiaCanvas()->restore();
885 }
886
887 if (m_commandIndex > 0)
888 pDriver->SkiaCanvas()->save();
889 while (index > 0 && m_commands[index] != Clip::kSave)
890 --index;
891 while (++index < m_commandIndex) {
892 SkASSERT(m_commands[index] == Clip::kPath);
893 pDriver->SkiaCanvas()->clipPath(m_clips[index], SkCanvas::kIntersect_Op,
894 true);
895 }
896 m_commands.setCount(m_commandIndex);
897 m_clips.resize_back(m_commandIndex);
898 }
899
900 // returns true if caller should apply command to skia canvas 931 // returns true if caller should apply command to skia canvas
901 bool ClipSave(CFX_SkiaDeviceDriver* pDriver) { 932 bool ClipSave() {
902 if (m_debugDisable) 933 if (m_debugDisable)
903 return false; 934 return false;
935 Dump(__func__);
904 int count = m_commands.count(); 936 int count = m_commands.count();
905 if (m_commandIndex < count) { 937 if (m_commandIndex < count - 1) {
906 if (m_commands[m_commandIndex] == Clip::kSave) { 938 if (Clip::kSave == m_commands[m_commandIndex + 1]) {
907 ++m_commandIndex; 939 ++m_commandIndex;
908 return true; 940 return true;
909 } 941 }
910 FlushCommands(pDriver); 942 Flush();
943 AdjustClip(m_commandIndex);
944 m_commands[++m_commandIndex] = Clip::kSave;
945 m_clips[m_commandIndex] = m_skEmptyPath;
946 } else {
947 AdjustClip(m_commandIndex);
948 m_commands.push(Clip::kSave);
949 m_clips.push_back(m_skEmptyPath);
950 ++m_commandIndex;
911 } 951 }
912 Flush(pDriver); 952 return true;
913 m_commands.push(Clip::kSave);
914 ++m_commandIndex;
915 m_clips.push_back(m_skEmptyPath);
916 return false;
917 } 953 }
918 954
919 bool ClipRestore(CFX_SkiaDeviceDriver* pDriver) { 955 bool ClipRestore() {
920 if (m_debugDisable) 956 if (m_debugDisable)
921 return false; 957 return false;
922 while (m_commandIndex > 0) { 958 Dump(__func__);
923 if (m_commands[--m_commandIndex] == Clip::kSave) 959 while (Clip::kSave != m_commands[--m_commandIndex]) {
924 return true; 960 SkASSERT(m_commandIndex > 0);
925 } 961 }
926 Flush(pDriver); 962 return true;
927 return false;
928 } 963 }
929 964
930 bool DrawChanged(const CFX_Matrix* pMatrix, 965 bool DrawChanged(const CFX_Matrix* pMatrix,
931 const CFX_GraphStateData* pState, 966 const CFX_GraphStateData* pState,
932 uint32_t fill_color, 967 uint32_t fill_color,
933 uint32_t stroke_color, 968 uint32_t stroke_color,
934 int fill_mode, 969 int fill_mode,
935 int blend_type, 970 int blend_type,
936 bool group_knockout) { 971 bool group_knockout) const {
937 return MatrixChanged(pMatrix, m_drawMatrix) || 972 return MatrixChanged(pMatrix, m_drawMatrix) ||
938 StateChanged(pState, m_drawState) || fill_color != m_fillColor || 973 StateChanged(pState, m_drawState) || fill_color != m_fillColor ||
939 stroke_color != m_strokeColor || 974 stroke_color != m_strokeColor ||
940 ((fill_mode & 3) == FXFILL_ALTERNATE) != 975 ((fill_mode & 3) == FXFILL_ALTERNATE) !=
941 (m_skPath.getFillType() == SkPath::kEvenOdd_FillType) || 976 (m_skPath.getFillType() == SkPath::kEvenOdd_FillType) ||
942 blend_type != m_blendType || group_knockout != m_groupKnockout; 977 blend_type != m_blendType || group_knockout != m_groupKnockout;
943 } 978 }
944 979
945 bool FontChanged(CFX_Font* pFont, 980 bool FontChanged(CFX_Font* pFont,
946 const CFX_Matrix* pMatrix, 981 const CFX_Matrix* pMatrix,
947 FX_FLOAT font_size, 982 FX_FLOAT font_size,
948 uint32_t color) { 983 uint32_t color) const {
949 return pFont != m_pFont || MatrixChanged(pMatrix, m_drawMatrix) || 984 return pFont != m_pFont || MatrixChanged(pMatrix, m_drawMatrix) ||
950 font_size != m_fontSize || color != m_fillColor; 985 font_size != m_fontSize || color != m_fillColor;
951 } 986 }
952 987
953 bool MatrixChanged(const CFX_Matrix* pMatrix, const CFX_Matrix& refMatrix) { 988 bool MatrixChanged(const CFX_Matrix* pMatrix,
989 const CFX_Matrix& refMatrix) const {
954 CFX_Matrix identityMatrix; 990 CFX_Matrix identityMatrix;
955 if (!pMatrix) 991 if (!pMatrix)
956 pMatrix = &identityMatrix; 992 pMatrix = &identityMatrix;
957 return pMatrix->a != refMatrix.a || pMatrix->b != refMatrix.b || 993 return pMatrix->a != refMatrix.a || pMatrix->b != refMatrix.b ||
958 pMatrix->c != refMatrix.c || pMatrix->d != refMatrix.d; 994 pMatrix->c != refMatrix.c || pMatrix->d != refMatrix.d;
959 } 995 }
960 996
961 bool StateChanged(const CFX_GraphStateData* pState, 997 bool StateChanged(const CFX_GraphStateData* pState,
962 const CFX_GraphStateData& refState) { 998 const CFX_GraphStateData& refState) const {
963 CFX_GraphStateData identityState; 999 CFX_GraphStateData identityState;
964 if (!pState) 1000 if (!pState)
965 pState = &identityState; 1001 pState = &identityState;
966 return pState->m_LineWidth != refState.m_LineWidth || 1002 return pState->m_LineWidth != refState.m_LineWidth ||
967 pState->m_LineCap != refState.m_LineCap || 1003 pState->m_LineCap != refState.m_LineCap ||
968 pState->m_LineJoin != refState.m_LineJoin || 1004 pState->m_LineJoin != refState.m_LineJoin ||
969 pState->m_MiterLimit != refState.m_MiterLimit || 1005 pState->m_MiterLimit != refState.m_MiterLimit ||
970 DashChanged(pState, refState); 1006 DashChanged(pState, refState);
971 } 1007 }
972 1008
973 bool DashChanged(const CFX_GraphStateData* pState, 1009 bool DashChanged(const CFX_GraphStateData* pState,
974 const CFX_GraphStateData& refState) { 1010 const CFX_GraphStateData& refState) const {
975 bool dashArray = pState && pState->m_DashArray; 1011 bool dashArray = pState && pState->m_DashArray;
976 if (!dashArray && !refState.m_DashArray) 1012 if (!dashArray && !refState.m_DashArray)
977 return false; 1013 return false;
978 if (!dashArray || !refState.m_DashArray) 1014 if (!dashArray || !refState.m_DashArray)
979 return true; 1015 return true;
980 if (pState->m_DashPhase != refState.m_DashPhase || 1016 if (pState->m_DashPhase != refState.m_DashPhase ||
981 pState->m_DashCount != refState.m_DashCount) { 1017 pState->m_DashCount != refState.m_DashCount) {
982 return true; 1018 return true;
983 } 1019 }
984 for (int index = 0; index < pState->m_DashCount; ++index) { 1020 for (int index = 0; index < pState->m_DashCount; ++index) {
985 if (pState->m_DashArray[index] != refState.m_DashArray[index]) 1021 if (pState->m_DashArray[index] != refState.m_DashArray[index])
986 return false; 1022 return true;
987 } 1023 }
988 return true; 1024 return true;
989 } 1025 }
990 1026
991 void Flush(CFX_SkiaDeviceDriver* pDriver) { 1027 void AdjustClip(int limit) {
992 if (m_drawPath) 1028 while (m_clipIndex > limit) {
993 FlushPath(pDriver); 1029 do {
994 if (m_drawText) 1030 --m_clipIndex;
995 FlushText(pDriver); 1031 SkASSERT(m_clipIndex >= 0);
1032 } while (m_commands[m_clipIndex] != Clip::kSave);
1033 m_pDriver->SkiaCanvas()->restore();
1034 }
1035 while (m_clipIndex < limit) {
1036 if (Clip::kSave == m_commands[m_clipIndex]) {
1037 m_pDriver->SkiaCanvas()->save();
1038 } else {
1039 SkASSERT(Clip::kPath == m_commands[m_clipIndex]);
1040 m_pDriver->SkiaCanvas()->clipPath(m_clips[m_clipIndex],
1041 SkCanvas::kIntersect_Op, true);
1042 }
1043 ++m_clipIndex;
1044 }
996 } 1045 }
997 1046
998 void Dump(const CFX_SkiaDeviceDriver* pDriver) const { 1047 void Flush() {
1048 if (m_debugDisable)
1049 return;
1050 Dump(__func__);
1051 if (Accumulator::kPath == m_type || Accumulator::kText == m_type) {
1052 AdjustClip(SkTMin(m_drawIndex, m_commands.count()));
1053 Accumulator::kPath == m_type ? FlushPath() : FlushText();
1054 }
1055 }
1056
1057 void FlushForDraw() {
1058 if (m_debugDisable)
1059 return;
1060 Flush(); // draw any pending text or path
1061 AdjustClip(m_commandIndex); // set up clip stack with any pending state
1062 }
1063
999 #if SHOW_SKIA_PATH 1064 #if SHOW_SKIA_PATH
1000 SkDebugf("\n\nSkia Save Count %d:\n", pDriver->m_pCanvas->getSaveCount()); 1065 void DumpPrefix(int index) const {
1001 pDriver->m_pCanvas->getClipStack()->dump(); 1066 if (index != m_commandIndex && index != m_drawIndex &&
1002 SkDebugf("Cache:\n"); 1067 index != m_clipIndex) {
1068 printf(" ");
1069 return;
1070 }
1071 printf("%c%c%c> ", index == m_commandIndex ? 'x' : '-',
1072 index == m_drawIndex ? 'd' : '-', index == m_clipIndex ? 'c' : '-');
1073 }
1074
1075 void DumpEndPrefix() const {
1076 int index = m_commands.count();
1077 if (index != m_commandIndex && index > m_drawIndex && index != m_clipIndex)
1078 return;
1079 printf("%c%c%c>\n", index == m_commandIndex ? 'x' : '-',
1080 index <= m_drawIndex ? 'd' : '-', index == m_clipIndex ? 'c' : '-');
1081 }
1082 #endif // SHOW_SKIA_PATH
1083
1084 void Dump(const char* where) const {
1085 #if SHOW_SKIA_PATH
1086 printf("\n%s\nSkia Save Count %d:\n", where,
1087 m_pDriver->m_pCanvas->getSaveCount());
1088 m_pDriver->m_pCanvas->getClipStack()->dump();
1089 printf("Cache:\n");
1003 for (int index = 0; index < m_commands.count(); ++index) { 1090 for (int index = 0; index < m_commands.count(); ++index) {
1004 SkDebugf("%s ", m_commandIndex == index ? "-->" : " "); 1091 DumpPrefix(index);
1005 switch (m_commands[index]) { 1092 switch (m_commands[index]) {
1006 case Clip::kSave: 1093 case Clip::kSave:
1007 SkDebugf("Save\n"); 1094 printf("Save %d\n", ++m_debugSaveCounter);
1008 break; 1095 break;
1009 case Clip::kPath: 1096 case Clip::kPath:
1010 m_clips[index].dump(); 1097 m_clips[index].dump();
1011 break; 1098 break;
1012 default: 1099 default:
1013 SkDebugf("unknown\n"); 1100 printf("unknown\n");
1014 } 1101 }
1015 } 1102 }
1016 if (m_commandIndex == m_commands.count()) 1103 DumpEndPrefix();
1017 SkDebugf("-->\n");
1018 #endif // SHOW_SKIA_PATH 1104 #endif // SHOW_SKIA_PATH
1105 #ifdef SK_DEBUG
1106 int skCanvasSaveCount = m_pDriver->m_pCanvas->getSaveCount();
1107 int cacheSaveCount = 1;
1108 SkASSERT(m_clipIndex <= m_commands.count());
1109 for (int index = 0; index < m_clipIndex; ++index)
1110 cacheSaveCount += Clip::kSave == m_commands[index];
1111 SkASSERT(skCanvasSaveCount == cacheSaveCount);
1112 #endif
1019 } 1113 }
1020 1114
1021 private: 1115 private:
1022 SkTArray<SkPath> m_clips; // stack of clips that may be reused 1116 SkTArray<SkPath> m_clips; // stack of clips that may be reused
1023 SkTDArray<Clip> m_commands; // stack of clip-related commands 1117 SkTDArray<Clip> m_commands; // stack of clip-related commands
1024 SkTDArray<SkPoint> m_positions; // accumulator for text positions 1118 SkTDArray<SkPoint> m_positions; // accumulator for text positions
1025 SkTDArray<uint16_t> m_glyphs; // accumulator for text glyphs 1119 SkTDArray<uint16_t> m_glyphs; // accumulator for text glyphs
1026 SkPath m_skPath; // accumulator for path contours 1120 SkPath m_skPath; // accumulator for path contours
1027 SkPath m_skEmptyPath; // used as placehold in the clips array 1121 SkPath m_skEmptyPath; // used as placehold in the clips array
1028 CFX_Matrix m_drawMatrix; 1122 CFX_Matrix m_drawMatrix;
1029 CFX_GraphStateData m_clipState; 1123 CFX_GraphStateData m_clipState;
1030 CFX_GraphStateData m_drawState; 1124 CFX_GraphStateData m_drawState;
1031 CFX_Matrix m_clipMatrix; 1125 CFX_Matrix m_clipMatrix;
1126 CFX_SkiaDeviceDriver* m_pDriver;
1032 CFX_Font* m_pFont; 1127 CFX_Font* m_pFont;
1033 FX_FLOAT m_fontSize; 1128 FX_FLOAT m_fontSize;
1034 uint32_t m_fillColor; 1129 uint32_t m_fillColor;
1035 uint32_t m_strokeColor; 1130 uint32_t m_strokeColor;
1036 int m_blendType; 1131 int m_blendType;
1037 int m_commandIndex; // active position in clip command stack 1132 int m_commandIndex; // active position in clip command stack
1038 bool m_drawText; 1133 int m_drawIndex; // position of the pending path or text draw
1039 bool m_drawPath; 1134 int m_clipIndex; // position reflecting depth of canvas clip stacck
1135 Accumulator m_type; // type of pending draw
1136 bool m_fillFullCover;
1040 bool m_fillPath; 1137 bool m_fillPath;
1041 bool m_groupKnockout; 1138 bool m_groupKnockout;
1042 bool m_debugDisable; // turn off cache for debugging 1139 bool m_debugDisable; // turn off cache for debugging
1140 #if SHOW_SKIA_PATH
1141 mutable int m_debugSaveCounter;
1142 #endif
1043 }; 1143 };
1044 #endif // _SKIA_SUPPORT_
1045 1144
1046 // convert a stroking path to scanlines 1145 // convert a stroking path to scanlines
1047 void CFX_SkiaDeviceDriver::PaintStroke(SkPaint* spaint, 1146 void CFX_SkiaDeviceDriver::PaintStroke(SkPaint* spaint,
1048 const CFX_GraphStateData* pGraphState, 1147 const CFX_GraphStateData* pGraphState,
1049 const SkMatrix& matrix) { 1148 const SkMatrix& matrix) {
1050 SkPaint::Cap cap; 1149 SkPaint::Cap cap;
1051 switch (pGraphState->m_LineCap) { 1150 switch (pGraphState->m_LineCap) {
1052 case CFX_GraphStateData::LineCapRound: 1151 case CFX_GraphStateData::LineCapRound:
1053 cap = SkPaint::kRound_Cap; 1152 cap = SkPaint::kRound_Cap;
1054 break; 1153 break;
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
1108 spaint->setStrokeJoin(join); 1207 spaint->setStrokeJoin(join);
1109 } 1208 }
1110 1209
1111 CFX_SkiaDeviceDriver::CFX_SkiaDeviceDriver(CFX_DIBitmap* pBitmap, 1210 CFX_SkiaDeviceDriver::CFX_SkiaDeviceDriver(CFX_DIBitmap* pBitmap,
1112 bool bRgbByteOrder, 1211 bool bRgbByteOrder,
1113 CFX_DIBitmap* pOriDevice, 1212 CFX_DIBitmap* pOriDevice,
1114 bool bGroupKnockout) 1213 bool bGroupKnockout)
1115 : m_pBitmap(pBitmap), 1214 : m_pBitmap(pBitmap),
1116 m_pOriDevice(pOriDevice), 1215 m_pOriDevice(pOriDevice),
1117 m_pRecorder(nullptr), 1216 m_pRecorder(nullptr),
1118 #ifdef _SKIA_SUPPORT_ 1217 m_pCache(new SkiaState(this)),
1119 m_pCache(new SkiaState),
1120 #endif
1121 #ifdef _SKIA_SUPPORT_PATHS_ 1218 #ifdef _SKIA_SUPPORT_PATHS_
1122 m_pClipRgn(nullptr), 1219 m_pClipRgn(nullptr),
1123 m_FillFlags(0), 1220 m_FillFlags(0),
1124 m_bRgbByteOrder(bRgbByteOrder), 1221 m_bRgbByteOrder(bRgbByteOrder),
1125 #endif // _SKIA_SUPPORT_PATHS_ 1222 #endif // _SKIA_SUPPORT_PATHS_
1126 m_bGroupKnockout(bGroupKnockout) { 1223 m_bGroupKnockout(bGroupKnockout) {
1127 SkBitmap skBitmap; 1224 SkBitmap skBitmap;
1128 SkASSERT(pBitmap->GetBPP() == 8 || pBitmap->GetBPP() == 32); 1225 SkASSERT(pBitmap->GetBPP() == 8 || pBitmap->GetBPP() == 32);
1129 SkImageInfo imageInfo = SkImageInfo::Make( 1226 SkImageInfo imageInfo = SkImageInfo::Make(
1130 pBitmap->GetWidth(), pBitmap->GetHeight(), 1227 pBitmap->GetWidth(), pBitmap->GetHeight(),
1131 pBitmap->GetBPP() == 8 ? kAlpha_8_SkColorType : kN32_SkColorType, 1228 pBitmap->GetBPP() == 8 ? kAlpha_8_SkColorType : kN32_SkColorType,
1132 kOpaque_SkAlphaType); 1229 kOpaque_SkAlphaType);
1133 skBitmap.installPixels(imageInfo, pBitmap->GetBuffer(), pBitmap->GetPitch(), 1230 skBitmap.installPixels(imageInfo, pBitmap->GetBuffer(), pBitmap->GetPitch(),
1134 nullptr, // FIXME(caryclark) set color table 1231 nullptr, // FIXME(caryclark) set color table
1135 nullptr, nullptr); 1232 nullptr, nullptr);
1136 m_pCanvas = new SkCanvas(skBitmap); 1233 m_pCanvas = new SkCanvas(skBitmap);
1137 } 1234 }
1138 1235
1139 #ifdef _SKIA_SUPPORT_ 1236 #ifdef _SKIA_SUPPORT_
1140 CFX_SkiaDeviceDriver::CFX_SkiaDeviceDriver(int size_x, int size_y) 1237 CFX_SkiaDeviceDriver::CFX_SkiaDeviceDriver(int size_x, int size_y)
1141 : m_pBitmap(nullptr), 1238 : m_pBitmap(nullptr),
1142 m_pOriDevice(nullptr), 1239 m_pOriDevice(nullptr),
1143 m_pRecorder(new SkPictureRecorder), 1240 m_pRecorder(new SkPictureRecorder),
1144 m_pCache(new SkiaState), 1241 m_pCache(new SkiaState(this)),
1145 m_bGroupKnockout(false) { 1242 m_bGroupKnockout(false) {
1146 m_pRecorder->beginRecording(SkIntToScalar(size_x), SkIntToScalar(size_y)); 1243 m_pRecorder->beginRecording(SkIntToScalar(size_x), SkIntToScalar(size_y));
1147 m_pCanvas = m_pRecorder->getRecordingCanvas(); 1244 m_pCanvas = m_pRecorder->getRecordingCanvas();
1148 } 1245 }
1149 1246
1150 CFX_SkiaDeviceDriver::CFX_SkiaDeviceDriver(SkPictureRecorder* recorder) 1247 CFX_SkiaDeviceDriver::CFX_SkiaDeviceDriver(SkPictureRecorder* recorder)
1151 : m_pBitmap(nullptr), 1248 : m_pBitmap(nullptr),
1152 m_pOriDevice(nullptr), 1249 m_pOriDevice(nullptr),
1153 m_pRecorder(recorder), 1250 m_pRecorder(recorder),
1154 m_pCache(new SkiaState), 1251 m_pCache(new SkiaState(this)),
1155 m_bGroupKnockout(false) { 1252 m_bGroupKnockout(false) {
1156 m_pCanvas = m_pRecorder->getRecordingCanvas(); 1253 m_pCanvas = m_pRecorder->getRecordingCanvas();
1157 } 1254 }
1158 #endif // _SKIA_SUPPORT_ 1255 #endif // _SKIA_SUPPORT_
1159 1256
1160 CFX_SkiaDeviceDriver::~CFX_SkiaDeviceDriver() { 1257 CFX_SkiaDeviceDriver::~CFX_SkiaDeviceDriver() {
1161 Flush(); 1258 Flush();
1162 if (!m_pRecorder) 1259 if (!m_pRecorder)
1163 delete m_pCanvas; 1260 delete m_pCanvas;
1164 } 1261 }
1165 1262
1166 void CFX_SkiaDeviceDriver::Flush() { 1263 void CFX_SkiaDeviceDriver::Flush() {
1167 #ifdef _SKIA_SUPPORT_ 1264 m_pCache->Flush();
1168 m_pCache->Flush(this);
1169 m_pCache->FlushCommands(this);
1170 #endif
1171 } 1265 }
1172 1266
1173 bool CFX_SkiaDeviceDriver::DrawDeviceText(int nChars, 1267 bool CFX_SkiaDeviceDriver::DrawDeviceText(int nChars,
1174 const FXTEXT_CHARPOS* pCharPos, 1268 const FXTEXT_CHARPOS* pCharPos,
1175 CFX_Font* pFont, 1269 CFX_Font* pFont,
1176 const CFX_Matrix* pObject2Device, 1270 const CFX_Matrix* pObject2Device,
1177 FX_FLOAT font_size, 1271 FX_FLOAT font_size,
1178 uint32_t color) { 1272 uint32_t color) {
1179 #ifdef _SKIA_SUPPORT_
1180 if (m_pCache->DrawText(nChars, pCharPos, pFont, pObject2Device, font_size, 1273 if (m_pCache->DrawText(nChars, pCharPos, pFont, pObject2Device, font_size,
1181 color, this)) { 1274 color)) {
1182 return true; 1275 return true;
1183 } 1276 }
1184 #endif
1185 sk_sp<SkTypeface> typeface(SkSafeRef(pFont->GetDeviceCache())); 1277 sk_sp<SkTypeface> typeface(SkSafeRef(pFont->GetDeviceCache()));
1186 SkPaint paint; 1278 SkPaint paint;
1187 paint.setAntiAlias(true); 1279 paint.setAntiAlias(true);
1188 paint.setColor(color); 1280 paint.setColor(color);
1189 paint.setTypeface(typeface); 1281 paint.setTypeface(typeface);
1190 paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); 1282 paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
1191 paint.setHinting(SkPaint::kNo_Hinting); 1283 paint.setHinting(SkPaint::kNo_Hinting);
1192 paint.setTextSize(SkTAbs(font_size)); 1284 paint.setTextSize(SkTAbs(font_size));
1193 paint.setSubpixelText(true); 1285 paint.setSubpixelText(true);
1194 m_pCanvas->save(); 1286 m_pCanvas->save();
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
1262 flags |= FXRC_CMYK_OUTPUT; 1354 flags |= FXRC_CMYK_OUTPUT;
1263 } 1355 }
1264 return flags; 1356 return flags;
1265 } 1357 }
1266 #endif // _SKIA_SUPPORT_PATHS_ 1358 #endif // _SKIA_SUPPORT_PATHS_
1267 } 1359 }
1268 return 0; 1360 return 0;
1269 } 1361 }
1270 1362
1271 void CFX_SkiaDeviceDriver::SaveState() { 1363 void CFX_SkiaDeviceDriver::SaveState() {
1272 #ifdef _SKIA_SUPPORT_ 1364 if (!m_pCache->ClipSave())
1273 if (!m_pCache->ClipSave(this))
1274 #endif
1275 m_pCanvas->save(); 1365 m_pCanvas->save();
1276 1366
1277 #ifdef _SKIA_SUPPORT_PATHS_ 1367 #ifdef _SKIA_SUPPORT_PATHS_
1278 std::unique_ptr<CFX_ClipRgn> pClip; 1368 std::unique_ptr<CFX_ClipRgn> pClip;
1279 if (m_pClipRgn) 1369 if (m_pClipRgn)
1280 pClip = pdfium::MakeUnique<CFX_ClipRgn>(*m_pClipRgn); 1370 pClip = pdfium::MakeUnique<CFX_ClipRgn>(*m_pClipRgn);
1281 m_StateStack.push_back(std::move(pClip)); 1371 m_StateStack.push_back(std::move(pClip));
1282 #endif // _SKIA_SUPPORT_PATHS_ 1372 #endif // _SKIA_SUPPORT_PATHS_
1283 } 1373 }
1284 1374
1285 void CFX_SkiaDeviceDriver::RestoreState(bool bKeepSaved) { 1375 void CFX_SkiaDeviceDriver::RestoreState(bool bKeepSaved) {
1286 #ifdef _SKIA_SUPPORT_ 1376 if (!m_pCache->ClipRestore())
1287 if (!m_pCache->ClipRestore(this))
1288 #endif
1289 m_pCanvas->restore(); 1377 m_pCanvas->restore();
1290 if (bKeepSaved 1378 if (bKeepSaved && !m_pCache->ClipSave())
1291 #ifdef _SKIA_SUPPORT_
1292 && !m_pCache->ClipSave(this)
1293 #endif
1294 ) {
1295 m_pCanvas->save(); 1379 m_pCanvas->save();
1296 }
1297 #ifdef _SKIA_SUPPORT_PATHS_ 1380 #ifdef _SKIA_SUPPORT_PATHS_
1298 m_pClipRgn.reset(); 1381 m_pClipRgn.reset();
1299 1382
1300 if (m_StateStack.empty()) 1383 if (m_StateStack.empty())
1301 return; 1384 return;
1302 1385
1303 if (bKeepSaved) { 1386 if (bKeepSaved) {
1304 if (m_StateStack.back()) 1387 if (m_StateStack.back())
1305 m_pClipRgn = pdfium::MakeUnique<CFX_ClipRgn>(*m_StateStack.back()); 1388 m_pClipRgn = pdfium::MakeUnique<CFX_ClipRgn>(*m_StateStack.back());
1306 } else { 1389 } else {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1339 } 1422 }
1340 #endif // _SKIA_SUPPORT_PATHS_ 1423 #endif // _SKIA_SUPPORT_PATHS_
1341 1424
1342 bool CFX_SkiaDeviceDriver::SetClip_PathFill( 1425 bool CFX_SkiaDeviceDriver::SetClip_PathFill(
1343 const CFX_PathData* pPathData, // path info 1426 const CFX_PathData* pPathData, // path info
1344 const CFX_Matrix* pObject2Device, // flips object's y-axis 1427 const CFX_Matrix* pObject2Device, // flips object's y-axis
1345 int fill_mode // fill mode, WINDING or ALTERNATE 1428 int fill_mode // fill mode, WINDING or ALTERNATE
1346 ) { 1429 ) {
1347 CFX_Matrix identity; 1430 CFX_Matrix identity;
1348 const CFX_Matrix* deviceMatrix = pObject2Device ? pObject2Device : &identity; 1431 const CFX_Matrix* deviceMatrix = pObject2Device ? pObject2Device : &identity;
1349 #ifdef _SKIA_SUPPORT_ 1432 bool cached = m_pCache->SetClipFill(pPathData, deviceMatrix, fill_mode);
1350 if (m_pCache->SetClipFill(pPathData, deviceMatrix, fill_mode, this))
1351 return true;
1352 #endif // _SKIA_SUPPORT_
1353 1433
1354 #ifdef _SKIA_SUPPORT_PATHS_ 1434 #ifdef _SKIA_SUPPORT_PATHS_
1355 m_FillFlags = fill_mode; 1435 m_FillFlags = fill_mode;
1356 if (!m_pClipRgn) { 1436 if (!m_pClipRgn) {
1357 m_pClipRgn = pdfium::MakeUnique<CFX_ClipRgn>( 1437 m_pClipRgn = pdfium::MakeUnique<CFX_ClipRgn>(
1358 GetDeviceCaps(FXDC_PIXEL_WIDTH), GetDeviceCaps(FXDC_PIXEL_HEIGHT)); 1438 GetDeviceCaps(FXDC_PIXEL_WIDTH), GetDeviceCaps(FXDC_PIXEL_HEIGHT));
1359 } 1439 }
1360 #endif // _SKIA_SUPPORT_PATHS_ 1440 #endif // _SKIA_SUPPORT_PATHS_
1361 if (pPathData->GetPointCount() == 5 || pPathData->GetPointCount() == 4) { 1441 if (pPathData->GetPointCount() == 5 || pPathData->GetPointCount() == 4) {
1362 CFX_FloatRect rectf; 1442 CFX_FloatRect rectf;
1363 if (pPathData->IsRect(deviceMatrix, &rectf)) { 1443 if (pPathData->IsRect(deviceMatrix, &rectf)) {
1364 rectf.Intersect( 1444 rectf.Intersect(
1365 CFX_FloatRect(0, 0, (FX_FLOAT)GetDeviceCaps(FXDC_PIXEL_WIDTH), 1445 CFX_FloatRect(0, 0, (FX_FLOAT)GetDeviceCaps(FXDC_PIXEL_WIDTH),
1366 (FX_FLOAT)GetDeviceCaps(FXDC_PIXEL_HEIGHT))); 1446 (FX_FLOAT)GetDeviceCaps(FXDC_PIXEL_HEIGHT)));
1367 // note that PDF's y-axis goes up; Skia's y-axis goes down 1447 // note that PDF's y-axis goes up; Skia's y-axis goes down
1368 SkRect skClipRect = 1448 if (!cached) {
1369 SkRect::MakeLTRB(rectf.left, rectf.bottom, rectf.right, rectf.top); 1449 SkRect skClipRect =
1370 DebugDrawSkiaClipRect(m_pCanvas, skClipRect); 1450 SkRect::MakeLTRB(rectf.left, rectf.bottom, rectf.right, rectf.top);
1371 m_pCanvas->clipRect(skClipRect, SkCanvas::kIntersect_Op, true); 1451 DebugDrawSkiaClipRect(m_pCanvas, skClipRect);
1452 m_pCanvas->clipRect(skClipRect, SkCanvas::kIntersect_Op, true);
1453 }
1372 1454
1373 #ifdef _SKIA_SUPPORT_PATHS_ 1455 #ifdef _SKIA_SUPPORT_PATHS_
1374 FX_RECT rect = rectf.GetOuterRect(); 1456 FX_RECT rect = rectf.GetOuterRect();
1375 m_pClipRgn->IntersectRect(rect); 1457 m_pClipRgn->IntersectRect(rect);
1376 #endif // _SKIA_SUPPORT_PATHS_ 1458 #endif // _SKIA_SUPPORT_PATHS_
1459 DebugShowCanvasClip(m_pCanvas);
1377 return true; 1460 return true;
1378 } 1461 }
1379 } 1462 }
1380 SkPath skClipPath = BuildPath(pPathData); 1463 SkPath skClipPath = BuildPath(pPathData);
1381 skClipPath.setFillType((fill_mode & 3) == FXFILL_ALTERNATE 1464 skClipPath.setFillType((fill_mode & 3) == FXFILL_ALTERNATE
1382 ? SkPath::kEvenOdd_FillType 1465 ? SkPath::kEvenOdd_FillType
1383 : SkPath::kWinding_FillType); 1466 : SkPath::kWinding_FillType);
1384 SkMatrix skMatrix = ToSkMatrix(*deviceMatrix); 1467 SkMatrix skMatrix = ToSkMatrix(*deviceMatrix);
1385 skClipPath.transform(skMatrix); 1468 skClipPath.transform(skMatrix);
1386 DebugShowSkiaPath(skClipPath); 1469 DebugShowSkiaPath(skClipPath);
1387 DebugDrawSkiaClipPath(m_pCanvas, skClipPath); 1470 if (!cached) {
1388 m_pCanvas->clipPath(skClipPath, SkCanvas::kIntersect_Op, true); 1471 DebugDrawSkiaClipPath(m_pCanvas, skClipPath);
1472 m_pCanvas->clipPath(skClipPath, SkCanvas::kIntersect_Op, true);
1473 }
1389 #ifdef _SKIA_SUPPORT_PATHS_ 1474 #ifdef _SKIA_SUPPORT_PATHS_
1390 FX_RECT clipBox(0, 0, GetDeviceCaps(FXDC_PIXEL_WIDTH), 1475 FX_RECT clipBox(0, 0, GetDeviceCaps(FXDC_PIXEL_WIDTH),
1391 GetDeviceCaps(FXDC_PIXEL_HEIGHT)); 1476 GetDeviceCaps(FXDC_PIXEL_HEIGHT));
1392 SetClipMask(clipBox, skClipPath); 1477 SetClipMask(clipBox, skClipPath);
1393 #endif // _SKIA_SUPPORT_PATHS_ 1478 #endif // _SKIA_SUPPORT_PATHS_
1479 DebugShowCanvasClip(m_pCanvas);
1394 return true; 1480 return true;
1395 } 1481 }
1396 1482
1397 bool CFX_SkiaDeviceDriver::SetClip_PathStroke( 1483 bool CFX_SkiaDeviceDriver::SetClip_PathStroke(
1398 const CFX_PathData* pPathData, // path info 1484 const CFX_PathData* pPathData, // path info
1399 const CFX_Matrix* pObject2Device, // optional transformation 1485 const CFX_Matrix* pObject2Device, // optional transformation
1400 const CFX_GraphStateData* pGraphState // graphic state, for pen attributes 1486 const CFX_GraphStateData* pGraphState // graphic state, for pen attributes
1401 ) { 1487 ) {
1402 #ifdef _SKIA_SUPPORT_ 1488 bool cached = m_pCache->SetClipStroke(pPathData, pObject2Device, pGraphState);
1403 if (m_pCache->SetClipStroke(pPathData, pObject2Device, pGraphState, this))
1404 return true;
1405 #endif // _SKIA_SUPPORT_
1406 1489
1407 #ifdef _SKIA_SUPPORT_PATHS_ 1490 #ifdef _SKIA_SUPPORT_PATHS_
1408 if (!m_pClipRgn) { 1491 if (!m_pClipRgn) {
1409 m_pClipRgn = pdfium::MakeUnique<CFX_ClipRgn>( 1492 m_pClipRgn = pdfium::MakeUnique<CFX_ClipRgn>(
1410 GetDeviceCaps(FXDC_PIXEL_WIDTH), GetDeviceCaps(FXDC_PIXEL_HEIGHT)); 1493 GetDeviceCaps(FXDC_PIXEL_WIDTH), GetDeviceCaps(FXDC_PIXEL_HEIGHT));
1411 } 1494 }
1412 #endif // _SKIA_SUPPORT_PATHS_ 1495 #endif // _SKIA_SUPPORT_PATHS_
1413 // build path data 1496 // build path data
1414 SkPath skPath = BuildPath(pPathData); 1497 SkPath skPath = BuildPath(pPathData);
1415 SkMatrix skMatrix = ToSkMatrix(*pObject2Device); 1498 SkMatrix skMatrix = ToSkMatrix(*pObject2Device);
1416 SkPaint skPaint; 1499 SkPaint skPaint;
1417 PaintStroke(&skPaint, pGraphState, skMatrix); 1500 PaintStroke(&skPaint, pGraphState, skMatrix);
1418 SkPath dst_path; 1501 SkPath dst_path;
1419 skPaint.getFillPath(skPath, &dst_path); 1502 skPaint.getFillPath(skPath, &dst_path);
1420 dst_path.transform(skMatrix); 1503 dst_path.transform(skMatrix);
1421 DebugDrawSkiaClipPath(m_pCanvas, dst_path); 1504 if (!cached) {
1422 #ifdef _SKIA_SUPPORT_ 1505 DebugDrawSkiaClipPath(m_pCanvas, dst_path);
1423 m_pCanvas->clipPath(dst_path, SkCanvas::kIntersect_Op, true); 1506 m_pCanvas->clipPath(dst_path, SkCanvas::kIntersect_Op, true);
1424 #endif // _SKIA_SUPPORT_ 1507 }
1425
1426 #ifdef _SKIA_SUPPORT_PATHS_ 1508 #ifdef _SKIA_SUPPORT_PATHS_
1427 FX_RECT clipBox(0, 0, GetDeviceCaps(FXDC_PIXEL_WIDTH), 1509 FX_RECT clipBox(0, 0, GetDeviceCaps(FXDC_PIXEL_WIDTH),
1428 GetDeviceCaps(FXDC_PIXEL_HEIGHT)); 1510 GetDeviceCaps(FXDC_PIXEL_HEIGHT));
1429 SetClipMask(clipBox, dst_path); 1511 SetClipMask(clipBox, dst_path);
1430 #endif // _SKIA_SUPPORT_PATHS_ 1512 #endif // _SKIA_SUPPORT_PATHS_
1513 DebugShowCanvasClip(m_pCanvas);
1431 return true; 1514 return true;
1432 } 1515 }
1433 1516
1434 bool CFX_SkiaDeviceDriver::DrawPath( 1517 bool CFX_SkiaDeviceDriver::DrawPath(
1435 const CFX_PathData* pPathData, // path info 1518 const CFX_PathData* pPathData, // path info
1436 const CFX_Matrix* pObject2Device, // optional transformation 1519 const CFX_Matrix* pObject2Device, // optional transformation
1437 const CFX_GraphStateData* pGraphState, // graphic state, for pen attributes 1520 const CFX_GraphStateData* pGraphState, // graphic state, for pen attributes
1438 uint32_t fill_color, // fill color 1521 uint32_t fill_color, // fill color
1439 uint32_t stroke_color, // stroke color 1522 uint32_t stroke_color, // stroke color
1440 int fill_mode, // fill mode, WINDING or ALTERNATE. 0 for not filled 1523 int fill_mode, // fill mode, WINDING or ALTERNATE. 0 for not filled
1441 int blend_type) { 1524 int blend_type) {
1442 if (fill_mode & FX_ZEROAREA_FILL) 1525 if (fill_mode & FX_ZEROAREA_FILL)
1443 return true; 1526 return true;
1444 #ifdef _SKIA_SUPPORT_
1445 if (m_pCache->DrawPath(pPathData, pObject2Device, pGraphState, fill_color, 1527 if (m_pCache->DrawPath(pPathData, pObject2Device, pGraphState, fill_color,
1446 stroke_color, fill_mode, blend_type, this)) { 1528 stroke_color, fill_mode, blend_type)) {
1447 return true; 1529 return true;
1448 } 1530 }
1449 #endif
1450 SkIRect rect;
1451 rect.set(0, 0, GetDeviceCaps(FXDC_PIXEL_WIDTH),
1452 GetDeviceCaps(FXDC_PIXEL_HEIGHT));
1453 SkMatrix skMatrix; 1531 SkMatrix skMatrix;
1454 if (pObject2Device) 1532 if (pObject2Device)
1455 skMatrix = ToSkMatrix(*pObject2Device); 1533 skMatrix = ToSkMatrix(*pObject2Device);
1456 else 1534 else
1457 skMatrix.setIdentity(); 1535 skMatrix.setIdentity();
1458 SkPaint skPaint; 1536 SkPaint skPaint;
1459 skPaint.setAntiAlias(true); 1537 skPaint.setAntiAlias(true);
1460 if (fill_mode & FXFILL_FULLCOVER) 1538 if (fill_mode & FXFILL_FULLCOVER)
1461 skPaint.setBlendMode(SkBlendMode::kPlus); 1539 skPaint.setBlendMode(SkBlendMode::kPlus);
1462 int stroke_alpha = FXARGB_A(stroke_color); 1540 int stroke_alpha = FXARGB_A(stroke_color);
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
1506 FX_FLOAT x2, 1584 FX_FLOAT x2,
1507 FX_FLOAT y2, 1585 FX_FLOAT y2,
1508 uint32_t color, 1586 uint32_t color,
1509 int blend_type) { 1587 int blend_type) {
1510 return false; 1588 return false;
1511 } 1589 }
1512 1590
1513 bool CFX_SkiaDeviceDriver::FillRectWithBlend(const FX_RECT* pRect, 1591 bool CFX_SkiaDeviceDriver::FillRectWithBlend(const FX_RECT* pRect,
1514 uint32_t fill_color, 1592 uint32_t fill_color,
1515 int blend_type) { 1593 int blend_type) {
1594 m_pCache->FlushForDraw();
1516 SkPaint spaint; 1595 SkPaint spaint;
1517 spaint.setAntiAlias(true); 1596 spaint.setAntiAlias(true);
1518 spaint.setColor(fill_color); 1597 spaint.setColor(fill_color);
1519 spaint.setBlendMode(GetSkiaBlendMode(blend_type)); 1598 spaint.setBlendMode(GetSkiaBlendMode(blend_type));
1520 SkRect rect = 1599 SkRect rect =
1521 SkRect::MakeLTRB(pRect->left, SkTMin(pRect->top, pRect->bottom), 1600 SkRect::MakeLTRB(pRect->left, SkTMin(pRect->top, pRect->bottom),
1522 pRect->right, SkTMax(pRect->bottom, pRect->top)); 1601 pRect->right, SkTMax(pRect->bottom, pRect->top));
1523 DebugShowSkiaDrawRect(m_pCanvas, spaint, rect); 1602 DebugShowSkiaDrawRect(m_pCanvas, spaint, rect);
1524 m_pCanvas->drawRect(rect, spaint); 1603 m_pCanvas->drawRect(rect, spaint);
1525 return true; 1604 return true;
1526 } 1605 }
1527 1606
1528 bool CFX_SkiaDeviceDriver::DrawShading(const CPDF_ShadingPattern* pPattern, 1607 bool CFX_SkiaDeviceDriver::DrawShading(const CPDF_ShadingPattern* pPattern,
1529 const CFX_Matrix* pMatrix, 1608 const CFX_Matrix* pMatrix,
1530 const FX_RECT& clip_rect, 1609 const FX_RECT& clip_rect,
1531 int alpha, 1610 int alpha,
1532 bool bAlphaMode) { 1611 bool bAlphaMode) {
1612 m_pCache->FlushForDraw();
1533 ShadingType shadingType = pPattern->GetShadingType(); 1613 ShadingType shadingType = pPattern->GetShadingType();
1534 if (kAxialShading != shadingType && kRadialShading != shadingType && 1614 if (kAxialShading != shadingType && kRadialShading != shadingType &&
1535 kCoonsPatchMeshShading != shadingType) { 1615 kCoonsPatchMeshShading != shadingType) {
1536 // TODO(caryclark) more types 1616 // TODO(caryclark) more types
1537 return false; 1617 return false;
1538 } 1618 }
1539 int csFamily = pPattern->GetCS()->GetFamily(); 1619 int csFamily = pPattern->GetCS()->GetFamily();
1540 if (PDFCS_DEVICERGB != csFamily && PDFCS_DEVICEGRAY != csFamily) 1620 if (PDFCS_DEVICERGB != csFamily && PDFCS_DEVICEGRAY != csFamily)
1541 return false; 1621 return false;
1542 const std::vector<std::unique_ptr<CPDF_Function>>& pFuncs = 1622 const std::vector<std::unique_ptr<CPDF_Function>>& pFuncs =
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
1717 return true; 1797 return true;
1718 } 1798 }
1719 1799
1720 bool CFX_SkiaDeviceDriver::GetDIBits(CFX_DIBitmap* pBitmap, int left, int top) { 1800 bool CFX_SkiaDeviceDriver::GetDIBits(CFX_DIBitmap* pBitmap, int left, int top) {
1721 if (!m_pBitmap) 1801 if (!m_pBitmap)
1722 return true; 1802 return true;
1723 uint8_t* srcBuffer = m_pBitmap->GetBuffer(); 1803 uint8_t* srcBuffer = m_pBitmap->GetBuffer();
1724 if (!srcBuffer) 1804 if (!srcBuffer)
1725 return true; 1805 return true;
1726 #ifdef _SKIA_SUPPORT_ 1806 #ifdef _SKIA_SUPPORT_
1807 m_pCache->FlushForDraw();
1727 int srcWidth = m_pBitmap->GetWidth(); 1808 int srcWidth = m_pBitmap->GetWidth();
1728 int srcHeight = m_pBitmap->GetHeight(); 1809 int srcHeight = m_pBitmap->GetHeight();
1729 int srcRowBytes = srcWidth * sizeof(uint32_t); 1810 int srcRowBytes = srcWidth * sizeof(uint32_t);
1730 SkImageInfo srcImageInfo = SkImageInfo::Make( 1811 SkImageInfo srcImageInfo = SkImageInfo::Make(
1731 srcWidth, srcHeight, SkColorType::kN32_SkColorType, kPremul_SkAlphaType); 1812 srcWidth, srcHeight, SkColorType::kN32_SkColorType, kPremul_SkAlphaType);
1732 SkBitmap skSrcBitmap; 1813 SkBitmap skSrcBitmap;
1733 skSrcBitmap.installPixels(srcImageInfo, srcBuffer, srcRowBytes, nullptr, 1814 skSrcBitmap.installPixels(srcImageInfo, srcBuffer, srcRowBytes, nullptr,
1734 nullptr, nullptr); 1815 nullptr, nullptr);
1735 SkASSERT(pBitmap); 1816 SkASSERT(pBitmap);
1736 uint8_t* dstBuffer = pBitmap->GetBuffer(); 1817 uint8_t* dstBuffer = pBitmap->GetBuffer();
1737 SkASSERT(dstBuffer); 1818 SkASSERT(dstBuffer);
1738 int dstWidth = pBitmap->GetWidth(); 1819 int dstWidth = pBitmap->GetWidth();
1739 int dstHeight = pBitmap->GetHeight(); 1820 int dstHeight = pBitmap->GetHeight();
1740 int dstRowBytes = dstWidth * sizeof(uint32_t); 1821 int dstRowBytes = dstWidth * sizeof(uint32_t);
1741 SkImageInfo dstImageInfo = SkImageInfo::Make( 1822 SkImageInfo dstImageInfo = SkImageInfo::Make(
1742 dstWidth, dstHeight, SkColorType::kN32_SkColorType, kPremul_SkAlphaType); 1823 dstWidth, dstHeight, SkColorType::kN32_SkColorType, kPremul_SkAlphaType);
1743 SkBitmap skDstBitmap; 1824 SkBitmap skDstBitmap;
1744 skDstBitmap.installPixels(dstImageInfo, dstBuffer, dstRowBytes, nullptr, 1825 skDstBitmap.installPixels(dstImageInfo, dstBuffer, dstRowBytes, nullptr,
1745 nullptr, nullptr); 1826 nullptr, nullptr);
1746 SkCanvas canvas(skDstBitmap); 1827 SkCanvas canvas(skDstBitmap);
1747 canvas.drawBitmap(skSrcBitmap, left, top, nullptr); 1828 canvas.drawBitmap(skSrcBitmap, left, top, nullptr);
1748 return true; 1829 return true;
1749 #endif // _SKIA_SUPPORT_ 1830 #endif // _SKIA_SUPPORT_
1750 1831
1751 #ifdef _SKIA_SUPPORT_PATHS_ 1832 #ifdef _SKIA_SUPPORT_PATHS_
1833 Flush();
1752 m_pBitmap->UnPreMultiply(); 1834 m_pBitmap->UnPreMultiply();
1753 FX_RECT rect(left, top, left + pBitmap->GetWidth(), 1835 FX_RECT rect(left, top, left + pBitmap->GetWidth(),
1754 top + pBitmap->GetHeight()); 1836 top + pBitmap->GetHeight());
1755 CFX_DIBitmap* pBack = nullptr; 1837 std::unique_ptr<CFX_DIBitmap> pBack;
1756 if (m_pOriDevice) { 1838 if (m_pOriDevice) {
1757 pBack = m_pOriDevice->Clone(&rect); 1839 pBack = m_pOriDevice->Clone(&rect);
1758 if (!pBack) 1840 if (!pBack)
1759 return true; 1841 return true;
1760 1842
1761 pBack->CompositeBitmap(0, 0, pBack->GetWidth(), pBack->GetHeight(), 1843 pBack->CompositeBitmap(0, 0, pBack->GetWidth(), pBack->GetHeight(),
1762 m_pBitmap, 0, 0); 1844 m_pBitmap, 0, 0);
1763 } else { 1845 } else {
1764 pBack = m_pBitmap->Clone(&rect); 1846 pBack = m_pBitmap->Clone(&rect);
1765 if (!pBack) 1847 if (!pBack)
1766 return true; 1848 return true;
1767 } 1849 }
1768 1850
1769 bool bRet = true; 1851 bool bRet = true;
1770 left = std::min(left, 0); 1852 left = std::min(left, 0);
1771 top = std::min(top, 0); 1853 top = std::min(top, 0);
1772 if (m_bRgbByteOrder) { 1854 if (m_bRgbByteOrder) {
1773 RgbByteOrderTransferBitmap(pBitmap, 0, 0, rect.Width(), rect.Height(), 1855 RgbByteOrderTransferBitmap(pBitmap, 0, 0, rect.Width(), rect.Height(),
1774 pBack, left, top); 1856 pBack.get(), left, top);
1775 } else { 1857 } else {
1776 bRet = pBitmap->TransferBitmap(0, 0, rect.Width(), rect.Height(), pBack, 1858 bRet = pBitmap->TransferBitmap(0, 0, rect.Width(), rect.Height(),
1777 left, top); 1859 pBack.get(), left, top);
1778 } 1860 }
1779 delete pBack;
1780 return bRet; 1861 return bRet;
1781 #endif // _SKIA_SUPPORT_PATHS_ 1862 #endif // _SKIA_SUPPORT_PATHS_
1782 } 1863 }
1783 1864
1784 CFX_DIBitmap* CFX_SkiaDeviceDriver::GetBackDrop() { 1865 CFX_DIBitmap* CFX_SkiaDeviceDriver::GetBackDrop() {
1785 return m_pOriDevice; 1866 return m_pOriDevice;
1786 } 1867 }
1787 1868
1788 bool CFX_SkiaDeviceDriver::SetDIBits(const CFX_DIBSource* pBitmap, 1869 bool CFX_SkiaDeviceDriver::SetDIBits(const CFX_DIBSource* pBitmap,
1789 uint32_t argb, 1870 uint32_t argb,
1790 const FX_RECT* pSrcRect, 1871 const FX_RECT* pSrcRect,
1791 int left, 1872 int left,
1792 int top, 1873 int top,
1793 int blend_type) { 1874 int blend_type) {
1794 if (!m_pBitmap || !m_pBitmap->GetBuffer()) 1875 if (!m_pBitmap || !m_pBitmap->GetBuffer())
1795 return true; 1876 return true;
1796 1877
1797 #ifdef _SKIA_SUPPORT_ 1878 #ifdef _SKIA_SUPPORT_
1798 CFX_Matrix m(pBitmap->GetWidth(), 0, 0, -pBitmap->GetHeight(), left, 1879 CFX_Matrix m(pBitmap->GetWidth(), 0, 0, -pBitmap->GetHeight(), left,
1799 top + pBitmap->GetHeight()); 1880 top + pBitmap->GetHeight());
1800 void* dummy; 1881 void* dummy;
1801 return StartDIBits(pBitmap, 0xFF, argb, &m, 0, dummy, blend_type); 1882 return StartDIBits(pBitmap, 0xFF, argb, &m, 0, dummy, blend_type);
1802 #endif // _SKIA_SUPPORT_ 1883 #endif // _SKIA_SUPPORT_
1803 1884
1804 #ifdef _SKIA_SUPPORT_PATHS_ 1885 #ifdef _SKIA_SUPPORT_PATHS_
1886 Flush();
1805 if (pBitmap->IsAlphaMask()) { 1887 if (pBitmap->IsAlphaMask()) {
1806 return m_pBitmap->CompositeMask( 1888 return m_pBitmap->CompositeMask(
1807 left, top, pSrcRect->Width(), pSrcRect->Height(), pBitmap, argb, 1889 left, top, pSrcRect->Width(), pSrcRect->Height(), pBitmap, argb,
1808 pSrcRect->left, pSrcRect->top, blend_type, m_pClipRgn.get(), 1890 pSrcRect->left, pSrcRect->top, blend_type, m_pClipRgn.get(),
1809 m_bRgbByteOrder, 0, nullptr); 1891 m_bRgbByteOrder, 0, nullptr);
1810 } 1892 }
1811 return m_pBitmap->CompositeBitmap( 1893 return m_pBitmap->CompositeBitmap(
1812 left, top, pSrcRect->Width(), pSrcRect->Height(), pBitmap, pSrcRect->left, 1894 left, top, pSrcRect->Width(), pSrcRect->Height(), pBitmap, pSrcRect->left,
1813 pSrcRect->top, blend_type, m_pClipRgn.get(), m_bRgbByteOrder, nullptr); 1895 pSrcRect->top, blend_type, m_pClipRgn.get(), m_bRgbByteOrder, nullptr);
1814 #endif // _SKIA_SUPPORT_PATHS_ 1896 #endif // _SKIA_SUPPORT_PATHS_
1815 } 1897 }
1816 1898
1817 bool CFX_SkiaDeviceDriver::StretchDIBits(const CFX_DIBSource* pSource, 1899 bool CFX_SkiaDeviceDriver::StretchDIBits(const CFX_DIBSource* pSource,
1818 uint32_t argb, 1900 uint32_t argb,
1819 int dest_left, 1901 int dest_left,
1820 int dest_top, 1902 int dest_top,
1821 int dest_width, 1903 int dest_width,
1822 int dest_height, 1904 int dest_height,
1823 const FX_RECT* pClipRect, 1905 const FX_RECT* pClipRect,
1824 uint32_t flags, 1906 uint32_t flags,
1825 int blend_type) { 1907 int blend_type) {
1826 #ifdef _SKIA_SUPPORT_ 1908 #ifdef _SKIA_SUPPORT_
1909 m_pCache->FlushForDraw();
1827 if (!m_pBitmap->GetBuffer()) 1910 if (!m_pBitmap->GetBuffer())
1828 return true; 1911 return true;
1829 CFX_Matrix m(dest_width, 0, 0, -dest_height, dest_left, 1912 CFX_Matrix m(dest_width, 0, 0, -dest_height, dest_left,
1830 dest_top + dest_height); 1913 dest_top + dest_height);
1831 1914
1832 m_pCanvas->save(); 1915 m_pCanvas->save();
1833 SkRect skClipRect = SkRect::MakeLTRB(pClipRect->left, pClipRect->bottom, 1916 SkRect skClipRect = SkRect::MakeLTRB(pClipRect->left, pClipRect->bottom,
1834 pClipRect->right, pClipRect->top); 1917 pClipRect->right, pClipRect->top);
1835 m_pCanvas->clipRect(skClipRect, SkCanvas::kIntersect_Op, true); 1918 m_pCanvas->clipRect(skClipRect, SkCanvas::kIntersect_Op, true);
1836 void* dummy; 1919 void* dummy;
1837 bool result = StartDIBits(pSource, 0xFF, argb, &m, 0, dummy, blend_type); 1920 bool result = StartDIBits(pSource, 0xFF, argb, &m, 0, dummy, blend_type);
1838 m_pCanvas->restore(); 1921 m_pCanvas->restore();
1839 1922
1840 return result; 1923 return result;
1841 #endif // _SKIA_SUPPORT_ 1924 #endif // _SKIA_SUPPORT_
1842 1925
1843 #ifdef _SKIA_SUPPORT_PATHS_ 1926 #ifdef _SKIA_SUPPORT_PATHS_
1844 if (dest_width == pSource->GetWidth() && 1927 if (dest_width == pSource->GetWidth() &&
1845 dest_height == pSource->GetHeight()) { 1928 dest_height == pSource->GetHeight()) {
1846 FX_RECT rect(0, 0, dest_width, dest_height); 1929 FX_RECT rect(0, 0, dest_width, dest_height);
1847 return SetDIBits(pSource, argb, &rect, dest_left, dest_top, blend_type); 1930 return SetDIBits(pSource, argb, &rect, dest_left, dest_top, blend_type);
1848 } 1931 }
1932 Flush();
1849 FX_RECT dest_rect(dest_left, dest_top, dest_left + dest_width, 1933 FX_RECT dest_rect(dest_left, dest_top, dest_left + dest_width,
1850 dest_top + dest_height); 1934 dest_top + dest_height);
1851 dest_rect.Normalize(); 1935 dest_rect.Normalize();
1852 FX_RECT dest_clip = dest_rect; 1936 FX_RECT dest_clip = dest_rect;
1853 dest_clip.Intersect(*pClipRect); 1937 dest_clip.Intersect(*pClipRect);
1854 CFX_BitmapComposer composer; 1938 CFX_BitmapComposer composer;
1855 composer.Compose(m_pBitmap, m_pClipRgn.get(), 255, argb, dest_clip, false, 1939 composer.Compose(m_pBitmap, m_pClipRgn.get(), 255, argb, dest_clip, false,
1856 false, false, m_bRgbByteOrder, 0, nullptr, blend_type); 1940 false, false, m_bRgbByteOrder, 0, nullptr, blend_type);
1857 dest_clip.Offset(-dest_rect.left, -dest_rect.top); 1941 dest_clip.Offset(-dest_rect.left, -dest_rect.top);
1858 CFX_ImageStretcher stretcher(&composer, pSource, dest_width, dest_height, 1942 CFX_ImageStretcher stretcher(&composer, pSource, dest_width, dest_height,
1859 dest_clip, flags); 1943 dest_clip, flags);
1860 if (stretcher.Start()) 1944 if (stretcher.Start())
1861 stretcher.Continue(nullptr); 1945 stretcher.Continue(nullptr);
1862 return true; 1946 return true;
1863 #endif // _SKIA_SUPPORT_PATHS_ 1947 #endif // _SKIA_SUPPORT_PATHS_
1864 } 1948 }
1865 1949
1866 bool CFX_SkiaDeviceDriver::StartDIBits(const CFX_DIBSource* pSource, 1950 bool CFX_SkiaDeviceDriver::StartDIBits(const CFX_DIBSource* pSource,
1867 int bitmap_alpha, 1951 int bitmap_alpha,
1868 uint32_t argb, 1952 uint32_t argb,
1869 const CFX_Matrix* pMatrix, 1953 const CFX_Matrix* pMatrix,
1870 uint32_t render_flags, 1954 uint32_t render_flags,
1871 void*& handle, 1955 void*& handle,
1872 int blend_type) { 1956 int blend_type) {
1873 #ifdef _SKIA_SUPPORT_ 1957 #ifdef _SKIA_SUPPORT_
1958 m_pCache->FlushForDraw();
1874 DebugValidate(m_pBitmap, m_pOriDevice); 1959 DebugValidate(m_pBitmap, m_pOriDevice);
1875 SkColorTable* ct = nullptr; 1960 SkColorTable* ct = nullptr;
1876 std::unique_ptr<uint8_t, FxFreeDeleter> dst8Storage; 1961 std::unique_ptr<uint8_t, FxFreeDeleter> dst8Storage;
1877 std::unique_ptr<uint32_t, FxFreeDeleter> dst32Storage; 1962 std::unique_ptr<uint32_t, FxFreeDeleter> dst32Storage;
1878 SkBitmap skBitmap; 1963 SkBitmap skBitmap;
1879 int width, height; 1964 int width, height;
1880 if (!Upsample(pSource, dst8Storage, dst32Storage, &ct, &skBitmap, &width, 1965 if (!Upsample(pSource, dst8Storage, dst32Storage, &ct, &skBitmap, &width,
1881 &height, false)) { 1966 &height, false)) {
1882 return false; 1967 return false;
1883 } 1968 }
(...skipping 21 matching lines...) Expand all
1905 } else { 1990 } else {
1906 m_pCanvas->drawBitmap(skBitmap, 0, 0, &paint); 1991 m_pCanvas->drawBitmap(skBitmap, 0, 0, &paint);
1907 } 1992 }
1908 m_pCanvas->restore(); 1993 m_pCanvas->restore();
1909 if (ct) 1994 if (ct)
1910 ct->unref(); 1995 ct->unref();
1911 DebugValidate(m_pBitmap, m_pOriDevice); 1996 DebugValidate(m_pBitmap, m_pOriDevice);
1912 #endif // _SKIA_SUPPORT_ 1997 #endif // _SKIA_SUPPORT_
1913 1998
1914 #ifdef _SKIA_SUPPORT_PATHS_ 1999 #ifdef _SKIA_SUPPORT_PATHS_
2000 Flush();
1915 if (!m_pBitmap->GetBuffer()) 2001 if (!m_pBitmap->GetBuffer())
1916 return true; 2002 return true;
1917 m_pBitmap->UnPreMultiply(); 2003 m_pBitmap->UnPreMultiply();
1918 CFX_ImageRenderer* pRenderer = new CFX_ImageRenderer; 2004 CFX_ImageRenderer* pRenderer = new CFX_ImageRenderer;
1919 pRenderer->Start(m_pBitmap, m_pClipRgn.get(), pSource, bitmap_alpha, argb, 2005 pRenderer->Start(m_pBitmap, m_pClipRgn.get(), pSource, bitmap_alpha, argb,
1920 pMatrix, render_flags, m_bRgbByteOrder, 0, nullptr); 2006 pMatrix, render_flags, m_bRgbByteOrder, 0, nullptr);
1921 handle = pRenderer; 2007 handle = pRenderer;
1922 #endif // _SKIA_SUPPORT_PATHS_ 2008 #endif // _SKIA_SUPPORT_PATHS_
1923 return true; 2009 return true;
1924 } 2010 }
1925 2011
1926 bool CFX_SkiaDeviceDriver::ContinueDIBits(void* handle, IFX_Pause* pPause) { 2012 bool CFX_SkiaDeviceDriver::ContinueDIBits(void* handle, IFX_Pause* pPause) {
1927 #ifdef _SKIA_SUPPORT_ 2013 #ifdef _SKIA_SUPPORT_
2014 m_pCache->FlushForDraw();
1928 return false; 2015 return false;
1929 #endif // _SKIA_SUPPORT_ 2016 #endif // _SKIA_SUPPORT_
1930 2017
1931 #ifdef _SKIA_SUPPORT_PATHS_ 2018 #ifdef _SKIA_SUPPORT_PATHS_
2019 Flush();
1932 if (!m_pBitmap->GetBuffer()) { 2020 if (!m_pBitmap->GetBuffer()) {
1933 return true; 2021 return true;
1934 } 2022 }
1935 return static_cast<CFX_ImageRenderer*>(handle)->Continue(pPause); 2023 return static_cast<CFX_ImageRenderer*>(handle)->Continue(pPause);
1936 #endif // _SKIA_SUPPORT_PATHS_ 2024 #endif // _SKIA_SUPPORT_PATHS_
1937 } 2025 }
1938 2026
1939 #if defined _SKIA_SUPPORT_ 2027 #if defined _SKIA_SUPPORT_
1940 void CFX_SkiaDeviceDriver::PreMultiply(CFX_DIBitmap* pDIBitmap) { 2028 void CFX_SkiaDeviceDriver::PreMultiply(CFX_DIBitmap* pDIBitmap) {
1941 pDIBitmap->PreMultiply(); 2029 pDIBitmap->PreMultiply();
(...skipping 1064 matching lines...) Expand 10 before | Expand all | Expand 10 after
3006 } 3094 }
3007 } 3095 }
3008 if (m_pDevice->GetBPP() == 1) { 3096 if (m_pDevice->GetBPP() == 1) {
3009 composite_span = &CFX_Renderer::CompositeSpan1bpp; 3097 composite_span = &CFX_Renderer::CompositeSpan1bpp;
3010 } 3098 }
3011 return true; 3099 return true;
3012 } 3100 }
3013 }; 3101 };
3014 3102
3015 #endif // _SKIA_SUPPORT_PATHS_ 3103 #endif // _SKIA_SUPPORT_PATHS_
OLDNEW
« no previous file with comments | « core/fxge/skia/fx_skia_device.h ('k') | fpdfsdk/fpdfformfill.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698