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

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

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

Powered by Google App Engine
This is Rietveld 408576698