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

Side by Side Diff: core/fxge/ge/cfx_pathdata.cpp

Issue 2216853004: Refactor fx_ge part 2 (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Fixing build, comments Created 4 years, 4 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/ge/cfx_gemodule.cpp ('k') | core/fxge/ge/fx_ge_device.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 2016 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 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #include "core/fxge/include/cfx_pathdata.h"
8
7 #include "core/fxcrt/include/fx_system.h" 9 #include "core/fxcrt/include/fx_system.h"
8 #include "core/fxge/include/fx_ge.h" 10 #include "core/fxge/include/fx_ge.h"
9 #include "third_party/base/numerics/safe_math.h" 11 #include "third_party/base/numerics/safe_math.h"
10 12
11 CFX_ClipRgn::CFX_ClipRgn(int width, int height)
12 : m_Type(RectI), m_Box(0, 0, width, height) {}
13
14 CFX_ClipRgn::CFX_ClipRgn(const FX_RECT& rect) : m_Type(RectI), m_Box(rect) {}
15
16 CFX_ClipRgn::CFX_ClipRgn(const CFX_ClipRgn& src) {
17 m_Type = src.m_Type;
18 m_Box = src.m_Box;
19 m_Mask = src.m_Mask;
20 }
21
22 CFX_ClipRgn::~CFX_ClipRgn() {}
23
24 void CFX_ClipRgn::Reset(const FX_RECT& rect) {
25 m_Type = RectI;
26 m_Box = rect;
27 m_Mask.SetNull();
28 }
29
30 void CFX_ClipRgn::IntersectRect(const FX_RECT& rect) {
31 if (m_Type == RectI) {
32 m_Box.Intersect(rect);
33 return;
34 }
35 if (m_Type == MaskF) {
36 IntersectMaskRect(rect, m_Box, m_Mask);
37 return;
38 }
39 }
40
41 void CFX_ClipRgn::IntersectMaskRect(FX_RECT rect,
42 FX_RECT mask_rect,
43 CFX_DIBitmapRef Mask) {
44 const CFX_DIBitmap* mask_dib = Mask.GetObject();
45 m_Type = MaskF;
46 m_Box = rect;
47 m_Box.Intersect(mask_rect);
48 if (m_Box.IsEmpty()) {
49 m_Type = RectI;
50 return;
51 }
52 if (m_Box == mask_rect) {
53 m_Mask = Mask;
54 return;
55 }
56 CFX_DIBitmap* new_dib = m_Mask.New();
57 if (!new_dib) {
58 return;
59 }
60 new_dib->Create(m_Box.Width(), m_Box.Height(), FXDIB_8bppMask);
61 for (int row = m_Box.top; row < m_Box.bottom; row++) {
62 uint8_t* dest_scan =
63 new_dib->GetBuffer() + new_dib->GetPitch() * (row - m_Box.top);
64 uint8_t* src_scan =
65 mask_dib->GetBuffer() + mask_dib->GetPitch() * (row - mask_rect.top);
66 for (int col = m_Box.left; col < m_Box.right; col++) {
67 dest_scan[col - m_Box.left] = src_scan[col - mask_rect.left];
68 }
69 }
70 }
71
72 void CFX_ClipRgn::IntersectMaskF(int left, int top, CFX_DIBitmapRef Mask) {
73 const CFX_DIBitmap* mask_dib = Mask.GetObject();
74 ASSERT(mask_dib->GetFormat() == FXDIB_8bppMask);
75 FX_RECT mask_box(left, top, left + mask_dib->GetWidth(),
76 top + mask_dib->GetHeight());
77 if (m_Type == RectI) {
78 IntersectMaskRect(m_Box, mask_box, Mask);
79 return;
80 }
81 if (m_Type == MaskF) {
82 FX_RECT new_box = m_Box;
83 new_box.Intersect(mask_box);
84 if (new_box.IsEmpty()) {
85 m_Type = RectI;
86 m_Mask.SetNull();
87 m_Box = new_box;
88 return;
89 }
90 CFX_DIBitmapRef new_mask;
91 CFX_DIBitmap* new_dib = new_mask.New();
92 if (!new_dib) {
93 return;
94 }
95 new_dib->Create(new_box.Width(), new_box.Height(), FXDIB_8bppMask);
96 const CFX_DIBitmap* old_dib = m_Mask.GetObject();
97 for (int row = new_box.top; row < new_box.bottom; row++) {
98 uint8_t* old_scan =
99 old_dib->GetBuffer() + (row - m_Box.top) * old_dib->GetPitch();
100 uint8_t* mask_scan =
101 mask_dib->GetBuffer() + (row - top) * mask_dib->GetPitch();
102 uint8_t* new_scan =
103 new_dib->GetBuffer() + (row - new_box.top) * new_dib->GetPitch();
104 for (int col = new_box.left; col < new_box.right; col++) {
105 new_scan[col - new_box.left] =
106 old_scan[col - m_Box.left] * mask_scan[col - left] / 255;
107 }
108 }
109 m_Box = new_box;
110 m_Mask = new_mask;
111 return;
112 }
113 ASSERT(FALSE);
114 }
115
116 CFX_PathData::CFX_PathData() 13 CFX_PathData::CFX_PathData()
117 : m_PointCount(0), m_pPoints(nullptr), m_AllocCount(0) {} 14 : m_PointCount(0), m_pPoints(nullptr), m_AllocCount(0) {}
118 15
119 CFX_PathData::~CFX_PathData() { 16 CFX_PathData::~CFX_PathData() {
120 FX_Free(m_pPoints); 17 FX_Free(m_pPoints);
121 } 18 }
122 19
123 void CFX_PathData::SetPointCount(int nPoints) { 20 void CFX_PathData::SetPointCount(int nPoints) {
124 m_PointCount = nPoints; 21 m_PointCount = nPoints;
125 if (m_AllocCount < nPoints) { 22 if (m_AllocCount < nPoints) {
(...skipping 501 matching lines...) Expand 10 before | Expand all | Expand 10 after
627 pRect->top = y[2]; 524 pRect->top = y[2];
628 pRect->Normalize(); 525 pRect->Normalize();
629 } 526 }
630 return TRUE; 527 return TRUE;
631 } 528 }
632 529
633 void CFX_PathData::Copy(const CFX_PathData& src) { 530 void CFX_PathData::Copy(const CFX_PathData& src) {
634 SetPointCount(src.m_PointCount); 531 SetPointCount(src.m_PointCount);
635 FXSYS_memcpy(m_pPoints, src.m_pPoints, sizeof(FX_PATHPOINT) * m_PointCount); 532 FXSYS_memcpy(m_pPoints, src.m_pPoints, sizeof(FX_PATHPOINT) * m_PointCount);
636 } 533 }
637
638 CFX_GraphStateData::CFX_GraphStateData()
639 : m_LineCap(LineCapButt),
640 m_DashCount(0),
641 m_DashArray(nullptr),
642 m_DashPhase(0),
643 m_LineJoin(LineJoinMiter),
644 m_MiterLimit(10 * 1.0f),
645 m_LineWidth(1.0f) {}
646
647 CFX_GraphStateData::CFX_GraphStateData(const CFX_GraphStateData& src) {
648 m_DashArray = nullptr;
649 Copy(src);
650 }
651
652 void CFX_GraphStateData::Copy(const CFX_GraphStateData& src) {
653 m_LineCap = src.m_LineCap;
654 m_DashCount = src.m_DashCount;
655 FX_Free(m_DashArray);
656 m_DashArray = nullptr;
657 m_DashPhase = src.m_DashPhase;
658 m_LineJoin = src.m_LineJoin;
659 m_MiterLimit = src.m_MiterLimit;
660 m_LineWidth = src.m_LineWidth;
661 if (m_DashCount) {
662 m_DashArray = FX_Alloc(FX_FLOAT, m_DashCount);
663 FXSYS_memcpy(m_DashArray, src.m_DashArray, m_DashCount * sizeof(FX_FLOAT));
664 }
665 }
666
667 CFX_GraphStateData::~CFX_GraphStateData() {
668 FX_Free(m_DashArray);
669 }
670
671 void CFX_GraphStateData::SetDashCount(int count) {
672 FX_Free(m_DashArray);
673 m_DashArray = nullptr;
674 m_DashCount = count;
675 if (count == 0) {
676 return;
677 }
678 m_DashArray = FX_Alloc(FX_FLOAT, count);
679 }
OLDNEW
« no previous file with comments | « core/fxge/ge/cfx_gemodule.cpp ('k') | core/fxge/ge/fx_ge_device.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698