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

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

Issue 2158023002: Pdfium: Fix fonts leaking on ClosePage. (Closed) Base URL: https://pdfium.googlesource.com/pdfium@master
Patch Set: Fix xfa tests. Created 4 years, 3 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
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 #if defined(_SKIA_SUPPORT_) 5 #if defined(_SKIA_SUPPORT_)
6 #include <algorithm> 6 #include <algorithm>
7 #include <vector> 7 #include <vector>
8 8
9 #include "core/fxcodec/include/fx_codec.h" 9 #include "core/fxcodec/include/fx_codec.h"
10 #include "core/fxcrt/include/fx_memory.h" 10 #include "core/fxcrt/include/fx_memory.h"
11 11
12 #include "core/fpdfapi/fpdf_page/cpdf_shadingpattern.h" 12 #include "core/fpdfapi/fpdf_page/cpdf_shadingpattern.h"
13 #include "core/fpdfapi/fpdf_page/pageint.h" 13 #include "core/fpdfapi/fpdf_page/pageint.h"
14 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" 14 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h"
15 #include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h" 15 #include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h"
16 #include "core/fpdfapi/fpdf_parser/include/cpdf_stream_acc.h" 16 #include "core/fpdfapi/fpdf_parser/include/cpdf_stream_acc.h"
17 #include "core/fxge/include/cfx_fontcache.h"
18 #include "core/fxge/include/cfx_fxgedevice.h" 17 #include "core/fxge/include/cfx_fxgedevice.h"
19 #include "core/fxge/include/cfx_gemodule.h" 18 #include "core/fxge/include/cfx_gemodule.h"
20 #include "core/fxge/include/cfx_graphstatedata.h" 19 #include "core/fxge/include/cfx_graphstatedata.h"
21 #include "core/fxge/include/cfx_pathdata.h" 20 #include "core/fxge/include/cfx_pathdata.h"
22 #include "core/fxge/include/cfx_renderdevice.h" 21 #include "core/fxge/include/cfx_renderdevice.h"
23 #include "core/fxge/skia/fx_skia_device.h" 22 #include "core/fxge/skia/fx_skia_device.h"
24 23
25 #include "third_party/skia/include/core/SkCanvas.h" 24 #include "third_party/skia/include/core/SkCanvas.h"
26 #include "third_party/skia/include/core/SkColorFilter.h" 25 #include "third_party/skia/include/core/SkColorFilter.h"
27 #include "third_party/skia/include/core/SkColorPriv.h" 26 #include "third_party/skia/include/core/SkColorPriv.h"
(...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after
479 class SkiaState { 478 class SkiaState {
480 public: 479 public:
481 enum class Clip { 480 enum class Clip {
482 kSave, 481 kSave,
483 kPath, 482 kPath,
484 }; 483 };
485 484
486 // mark all cached state as uninitialized 485 // mark all cached state as uninitialized
487 SkiaState() 486 SkiaState()
488 : m_pFont(nullptr), 487 : m_pFont(nullptr),
489 m_pCache(nullptr),
490 m_fontSize(0), 488 m_fontSize(0),
491 m_fillColor(0), 489 m_fillColor(0),
492 m_strokeColor(0), 490 m_strokeColor(0),
493 m_blendType(0), 491 m_blendType(0),
494 m_commandIndex(0), 492 m_commandIndex(0),
495 m_drawText(false), 493 m_drawText(false),
496 m_drawPath(false), 494 m_drawPath(false),
497 m_fillPath(false), 495 m_fillPath(false),
498 m_debugDisable(false) {} 496 m_debugDisable(false) {}
499 497
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
573 skPaint.setColor(m_strokeColor); 571 skPaint.setColor(m_strokeColor);
574 skCanvas->drawPath(m_skPath, skPaint); 572 skCanvas->drawPath(m_skPath, skPaint);
575 } 573 }
576 skCanvas->restore(); 574 skCanvas->restore();
577 m_drawPath = false; 575 m_drawPath = false;
578 } 576 }
579 577
580 bool DrawText(int nChars, 578 bool DrawText(int nChars,
581 const FXTEXT_CHARPOS* pCharPos, 579 const FXTEXT_CHARPOS* pCharPos,
582 CFX_Font* pFont, 580 CFX_Font* pFont,
583 CFX_FontCache* pCache,
584 const CFX_Matrix* pMatrix, 581 const CFX_Matrix* pMatrix,
585 FX_FLOAT font_size, 582 FX_FLOAT font_size,
586 uint32_t color, 583 uint32_t color,
587 CFX_SkiaDeviceDriver* pDriver) { 584 CFX_SkiaDeviceDriver* pDriver) {
588 if (m_debugDisable) 585 if (m_debugDisable)
589 return false; 586 return false;
590 if (m_commandIndex < m_commands.count()) 587 if (m_commandIndex < m_commands.count())
591 FlushCommands(pDriver); 588 FlushCommands(pDriver);
592 if (m_drawPath) 589 if (m_drawPath)
593 FlushPath(pDriver); 590 FlushPath(pDriver);
594 if (m_drawText && FontChanged(pFont, pCache, pMatrix, font_size, color)) 591 if (m_drawText && FontChanged(pFont, pMatrix, font_size, color))
595 FlushText(pDriver); 592 FlushText(pDriver);
596 if (!m_drawText) { 593 if (!m_drawText) {
597 m_positions.setCount(0); 594 m_positions.setCount(0);
598 m_glyphs.setCount(0); 595 m_glyphs.setCount(0);
599 m_pFont = pFont; 596 m_pFont = pFont;
600 m_pCache = pCache;
601 m_fontSize = font_size; 597 m_fontSize = font_size;
602 m_fillColor = color; 598 m_fillColor = color;
603 m_drawMatrix = *pMatrix; 599 m_drawMatrix = *pMatrix;
604 } 600 }
605 int count = m_positions.count(); 601 int count = m_positions.count();
606 m_positions.setCount(nChars + count); 602 m_positions.setCount(nChars + count);
607 m_glyphs.setCount(nChars + count); 603 m_glyphs.setCount(nChars + count);
608 SkScalar flip = m_fontSize < 0 ? -1 : 1; 604 SkScalar flip = m_fontSize < 0 ? -1 : 1;
609 for (int index = 0; index < nChars; ++index) { 605 for (int index = 0; index < nChars; ++index) {
610 const FXTEXT_CHARPOS& cp = pCharPos[index]; 606 const FXTEXT_CHARPOS& cp = pCharPos[index];
611 m_positions[index + count] = {cp.m_OriginX * flip, cp.m_OriginY * flip}; 607 m_positions[index + count] = {cp.m_OriginX * flip, cp.m_OriginY * flip};
612 m_glyphs[index + count] = (uint16_t)cp.m_GlyphIndex; 608 m_glyphs[index + count] = (uint16_t)cp.m_GlyphIndex;
613 } 609 }
614 SkPoint delta; 610 SkPoint delta;
615 if (MatrixOffset(pMatrix, &delta)) { 611 if (MatrixOffset(pMatrix, &delta)) {
616 for (int index = 0; index < nChars; ++index) 612 for (int index = 0; index < nChars; ++index)
617 m_positions[index + count].offset(delta.fX * flip, -delta.fY * flip); 613 m_positions[index + count].offset(delta.fX * flip, -delta.fY * flip);
618 } 614 }
619 m_drawText = true; 615 m_drawText = true;
620 return true; 616 return true;
621 } 617 }
622 618
623 void FlushText(CFX_SkiaDeviceDriver* pDriver) { 619 void FlushText(CFX_SkiaDeviceDriver* pDriver) {
624 SkScalar flip = m_fontSize < 0 ? -1 : 1; 620 SkScalar flip = m_fontSize < 0 ? -1 : 1;
625 SkMatrix skMatrix = ToFlippedSkMatrix(m_drawMatrix, flip); 621 SkMatrix skMatrix = ToFlippedSkMatrix(m_drawMatrix, flip);
626 SkPaint skPaint; 622 SkPaint skPaint;
627 skPaint.setAntiAlias(true); 623 skPaint.setAntiAlias(true);
628 skPaint.setColor(m_fillColor); 624 skPaint.setColor(m_fillColor);
629 if (m_pFont->GetFace() && m_pCache) { // exclude placeholder test fonts 625 if (m_pFont->GetFace()) { // exclude placeholder test fonts
630 sk_sp<SkTypeface> typeface(SkSafeRef(m_pCache->GetDeviceCache(m_pFont))); 626 sk_sp<SkTypeface> typeface(SkSafeRef(m_pFont->GetDeviceCache()));
631 skPaint.setTypeface(typeface); 627 skPaint.setTypeface(typeface);
632 } 628 }
633 skPaint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); 629 skPaint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
634 skPaint.setTextSize(m_fontSize); 630 skPaint.setTextSize(m_fontSize);
635 skPaint.setSubpixelText(true); 631 skPaint.setSubpixelText(true);
636 skPaint.setHinting(SkPaint::kNo_Hinting); 632 skPaint.setHinting(SkPaint::kNo_Hinting);
637 SkCanvas* skCanvas = pDriver->SkiaCanvas(); 633 SkCanvas* skCanvas = pDriver->SkiaCanvas();
638 skCanvas->save(); 634 skCanvas->save();
639 skCanvas->concat(skMatrix); 635 skCanvas->concat(skMatrix);
640 skCanvas->drawPosText(m_glyphs.begin(), m_glyphs.count() * 2, 636 skCanvas->drawPosText(m_glyphs.begin(), m_glyphs.count() * 2,
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
776 int blend_type) { 772 int blend_type) {
777 return MatrixChanged(pMatrix, m_drawMatrix) || 773 return MatrixChanged(pMatrix, m_drawMatrix) ||
778 StateChanged(pState, m_drawState) || fill_color != m_fillColor || 774 StateChanged(pState, m_drawState) || fill_color != m_fillColor ||
779 stroke_color != m_strokeColor || 775 stroke_color != m_strokeColor ||
780 ((fill_mode & 3) == FXFILL_ALTERNATE) != 776 ((fill_mode & 3) == FXFILL_ALTERNATE) !=
781 (m_skPath.getFillType() == SkPath::kEvenOdd_FillType) || 777 (m_skPath.getFillType() == SkPath::kEvenOdd_FillType) ||
782 blend_type != m_blendType; 778 blend_type != m_blendType;
783 } 779 }
784 780
785 bool FontChanged(CFX_Font* pFont, 781 bool FontChanged(CFX_Font* pFont,
786 CFX_FontCache* pCache,
787 const CFX_Matrix* pMatrix, 782 const CFX_Matrix* pMatrix,
788 FX_FLOAT font_size, 783 FX_FLOAT font_size,
789 uint32_t color) { 784 uint32_t color) {
790 return pFont != m_pFont || pCache != m_pCache || 785 return pFont != m_pFont || MatrixChanged(pMatrix, m_drawMatrix) ||
791 MatrixChanged(pMatrix, m_drawMatrix) || font_size != m_fontSize || 786 font_size != m_fontSize || color != m_fillColor;
792 color != m_fillColor;
793 } 787 }
794 788
795 bool MatrixChanged(const CFX_Matrix* pMatrix, const CFX_Matrix& refMatrix) { 789 bool MatrixChanged(const CFX_Matrix* pMatrix, const CFX_Matrix& refMatrix) {
796 CFX_Matrix identityMatrix; 790 CFX_Matrix identityMatrix;
797 if (!pMatrix) 791 if (!pMatrix)
798 pMatrix = &identityMatrix; 792 pMatrix = &identityMatrix;
799 return pMatrix->a != refMatrix.a || pMatrix->b != refMatrix.b || 793 return pMatrix->a != refMatrix.a || pMatrix->b != refMatrix.b ||
800 pMatrix->c != refMatrix.c || pMatrix->d != refMatrix.d; 794 pMatrix->c != refMatrix.c || pMatrix->d != refMatrix.d;
801 } 795 }
802 796
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
865 SkTDArray<Clip> m_commands; // stack of clip-related commands 859 SkTDArray<Clip> m_commands; // stack of clip-related commands
866 SkTDArray<SkPoint> m_positions; // accumulator for text positions 860 SkTDArray<SkPoint> m_positions; // accumulator for text positions
867 SkTDArray<uint16_t> m_glyphs; // accumulator for text glyphs 861 SkTDArray<uint16_t> m_glyphs; // accumulator for text glyphs
868 SkPath m_skPath; // accumulator for path contours 862 SkPath m_skPath; // accumulator for path contours
869 SkPath m_skEmptyPath; // used as placehold in the clips array 863 SkPath m_skEmptyPath; // used as placehold in the clips array
870 CFX_Matrix m_drawMatrix; 864 CFX_Matrix m_drawMatrix;
871 CFX_GraphStateData m_clipState; 865 CFX_GraphStateData m_clipState;
872 CFX_GraphStateData m_drawState; 866 CFX_GraphStateData m_drawState;
873 CFX_Matrix m_clipMatrix; 867 CFX_Matrix m_clipMatrix;
874 CFX_Font* m_pFont; 868 CFX_Font* m_pFont;
875 CFX_FontCache* m_pCache;
876 FX_FLOAT m_fontSize; 869 FX_FLOAT m_fontSize;
877 uint32_t m_fillColor; 870 uint32_t m_fillColor;
878 uint32_t m_strokeColor; 871 uint32_t m_strokeColor;
879 int m_blendType; 872 int m_blendType;
880 int m_commandIndex; // active position in clip command stack 873 int m_commandIndex; // active position in clip command stack
881 bool m_drawText; 874 bool m_drawText;
882 bool m_drawPath; 875 bool m_drawPath;
883 bool m_fillPath; 876 bool m_fillPath;
884 bool m_debugDisable; // turn off cache for debugging 877 bool m_debugDisable; // turn off cache for debugging
885 }; 878 };
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
998 } 991 }
999 992
1000 void CFX_SkiaDeviceDriver::Flush() { 993 void CFX_SkiaDeviceDriver::Flush() {
1001 m_pCache->Flush(this); 994 m_pCache->Flush(this);
1002 m_pCache->FlushCommands(this); 995 m_pCache->FlushCommands(this);
1003 } 996 }
1004 997
1005 FX_BOOL CFX_SkiaDeviceDriver::DrawDeviceText(int nChars, 998 FX_BOOL CFX_SkiaDeviceDriver::DrawDeviceText(int nChars,
1006 const FXTEXT_CHARPOS* pCharPos, 999 const FXTEXT_CHARPOS* pCharPos,
1007 CFX_Font* pFont, 1000 CFX_Font* pFont,
1008 CFX_FontCache* pCache,
1009 const CFX_Matrix* pObject2Device, 1001 const CFX_Matrix* pObject2Device,
1010 FX_FLOAT font_size, 1002 FX_FLOAT font_size,
1011 uint32_t color) { 1003 uint32_t color) {
1012 if (!pCache) 1004 if (m_pCache->DrawText(nChars, pCharPos, pFont, pObject2Device, font_size,
1013 pCache = CFX_GEModule::Get()->GetFontCache(); 1005 color, this)) {
1014 if (m_pCache->DrawText(nChars, pCharPos, pFont, pCache, pObject2Device,
1015 font_size, color, this)) {
1016 return TRUE; 1006 return TRUE;
1017 } 1007 }
1018 sk_sp<SkTypeface> typeface( 1008 sk_sp<SkTypeface> typeface(SkSafeRef(pFont->GetDeviceCache()));
1019 SkSafeRef(pCache ? pCache->GetDeviceCache(pFont) : nullptr));
1020 SkPaint paint; 1009 SkPaint paint;
1021 paint.setAntiAlias(true); 1010 paint.setAntiAlias(true);
1022 paint.setColor(color); 1011 paint.setColor(color);
1023 paint.setTypeface(typeface); 1012 paint.setTypeface(typeface);
1024 paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); 1013 paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
1025 paint.setHinting(SkPaint::kNo_Hinting); 1014 paint.setHinting(SkPaint::kNo_Hinting);
1026 paint.setTextSize(font_size); 1015 paint.setTextSize(font_size);
1027 paint.setSubpixelText(true); 1016 paint.setSubpixelText(true);
1028 m_pCanvas->save(); 1017 m_pCanvas->save();
1029 SkScalar flip = font_size < 0 ? -1 : 1; 1018 SkScalar flip = font_size < 0 ? -1 : 1;
(...skipping 653 matching lines...) Expand 10 before | Expand all | Expand 10 after
1683 SkA32Assert(a); 1672 SkA32Assert(a);
1684 SkASSERT(r <= a); 1673 SkASSERT(r <= a);
1685 SkASSERT(g <= a); 1674 SkASSERT(g <= a);
1686 SkASSERT(b <= a); 1675 SkASSERT(b <= a);
1687 } 1676 }
1688 } 1677 }
1689 #endif 1678 #endif
1690 } 1679 }
1691 1680
1692 #endif 1681 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698