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

Side by Side Diff: core/src/fxge/ge/fx_ge_device.cpp

Issue 453133004: clang-format all code (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 6 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
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 // 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 "../../../include/fxge/fx_ge.h" 7 #include "../../../include/fxge/fx_ge.h"
8 CFX_RenderDevice::CFX_RenderDevice() 8 CFX_RenderDevice::CFX_RenderDevice() {
9 { 9 m_pDeviceDriver = NULL;
10 m_pDeviceDriver = NULL; 10 m_pBitmap = NULL;
11 m_pBitmap = NULL; 11 }
12 } 12 CFX_RenderDevice::~CFX_RenderDevice() {
13 CFX_RenderDevice::~CFX_RenderDevice() 13 if (m_pDeviceDriver) {
14 { 14 delete m_pDeviceDriver;
15 if (m_pDeviceDriver) { 15 }
16 delete m_pDeviceDriver; 16 }
17 } 17 void CFX_RenderDevice::SetDeviceDriver(IFX_RenderDeviceDriver* pDriver) {
18 } 18 if (m_pDeviceDriver) {
19 void CFX_RenderDevice::SetDeviceDriver(IFX_RenderDeviceDriver* pDriver) 19 delete m_pDeviceDriver;
20 { 20 }
21 if (m_pDeviceDriver) { 21 m_pDeviceDriver = pDriver;
22 delete m_pDeviceDriver; 22 InitDeviceInfo();
23 } 23 }
24 m_pDeviceDriver = pDriver; 24 void CFX_RenderDevice::InitDeviceInfo() {
25 InitDeviceInfo(); 25 ASSERT(m_pDeviceDriver != NULL);
26 } 26 m_Width = m_pDeviceDriver->GetDeviceCaps(FXDC_PIXEL_WIDTH);
27 void CFX_RenderDevice::InitDeviceInfo() 27 m_Height = m_pDeviceDriver->GetDeviceCaps(FXDC_PIXEL_HEIGHT);
28 { 28 m_bpp = m_pDeviceDriver->GetDeviceCaps(FXDC_BITS_PIXEL);
29 ASSERT(m_pDeviceDriver != NULL); 29 m_RenderCaps = m_pDeviceDriver->GetDeviceCaps(FXDC_RENDER_CAPS);
30 m_Width = m_pDeviceDriver->GetDeviceCaps(FXDC_PIXEL_WIDTH); 30 m_DeviceClass = m_pDeviceDriver->GetDeviceCaps(FXDC_DEVICE_CLASS);
31 m_Height = m_pDeviceDriver->GetDeviceCaps(FXDC_PIXEL_HEIGHT); 31 if (!m_pDeviceDriver->GetClipBox(&m_ClipBox)) {
32 m_bpp = m_pDeviceDriver->GetDeviceCaps(FXDC_BITS_PIXEL);
33 m_RenderCaps = m_pDeviceDriver->GetDeviceCaps(FXDC_RENDER_CAPS);
34 m_DeviceClass = m_pDeviceDriver->GetDeviceCaps(FXDC_DEVICE_CLASS);
35 if (!m_pDeviceDriver->GetClipBox(&m_ClipBox)) {
36 m_ClipBox.left = 0;
37 m_ClipBox.top = 0;
38 m_ClipBox.right = m_Width;
39 m_ClipBox.bottom = m_Height;
40 }
41 }
42 FX_BOOL CFX_RenderDevice::StartRendering()
43 {
44 return m_pDeviceDriver->StartRendering();
45 }
46 void CFX_RenderDevice::EndRendering()
47 {
48 m_pDeviceDriver->EndRendering();
49 }
50 void CFX_RenderDevice::SaveState()
51 {
52 m_pDeviceDriver->SaveState();
53 }
54 void CFX_RenderDevice::RestoreState(FX_BOOL bKeepSaved)
55 {
56 m_pDeviceDriver->RestoreState(bKeepSaved);
57 UpdateClipBox();
58 }
59 int CFX_RenderDevice::GetDeviceCaps(int caps_id) const
60 {
61 return m_pDeviceDriver->GetDeviceCaps(caps_id);
62 }
63 CFX_Matrix CFX_RenderDevice::GetCTM() const
64 {
65 return m_pDeviceDriver->GetCTM();
66 }
67 FX_BOOL CFX_RenderDevice::CreateCompatibleBitmap(CFX_DIBitmap* pDIB, int width, int height) const
68 {
69 if (m_RenderCaps & FXRC_CMYK_OUTPUT) {
70 return pDIB->Create(width, height, m_RenderCaps & FXRC_ALPHA_OUTPUT ? FX DIB_Cmyka : FXDIB_Cmyk);
71 } else if (m_RenderCaps & FXRC_BYTEMASK_OUTPUT) {
72 return pDIB->Create(width, height, FXDIB_8bppMask);
73 } else
74 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_
75 return pDIB->Create(width, height, m_RenderCaps & FXRC_ALPHA_OUTPUT ? FX DIB_Argb : FXDIB_Rgb32);
76 #else
77 return pDIB->Create(width, height, m_RenderCaps & FXRC_ALPHA_OUTPUT ? FX DIB_Argb : FXDIB_Rgb);
78 #endif
79 }
80 FX_BOOL CFX_RenderDevice::SetClip_PathFill(const CFX_PathData* pPathData,
81 const CFX_AffineMatrix* pObject2Device,
82 int fill_mode
83 )
84 {
85 if (!m_pDeviceDriver->SetClip_PathFill(pPathData, pObject2Device, fill_mode) ) {
86 return FALSE;
87 }
88 UpdateClipBox();
89 return TRUE;
90 }
91 FX_BOOL CFX_RenderDevice::SetClip_PathStroke(const CFX_PathData* pPathData,
92 const CFX_AffineMatrix* pObject2Device,
93 const CFX_GraphStateData* pGraphState
94 )
95 {
96 if (!m_pDeviceDriver->SetClip_PathStroke(pPathData, pObject2Device, pGraphSt ate)) {
97 return FALSE;
98 }
99 UpdateClipBox();
100 return TRUE;
101 }
102 FX_BOOL CFX_RenderDevice::SetClip_Rect(const FX_RECT* pRect)
103 {
104 CFX_PathData path;
105 path.AppendRect((FX_FLOAT)(pRect->left), (FX_FLOAT)(pRect->bottom), (FX_FLOA T)(pRect->right), (FX_FLOAT)(pRect->top));
106 if (!SetClip_PathFill(&path, NULL, FXFILL_WINDING)) {
107 return FALSE;
108 }
109 UpdateClipBox();
110 return TRUE;
111 }
112 void CFX_RenderDevice::UpdateClipBox()
113 {
114 if (m_pDeviceDriver->GetClipBox(&m_ClipBox)) {
115 return;
116 }
117 m_ClipBox.left = 0; 32 m_ClipBox.left = 0;
118 m_ClipBox.top = 0; 33 m_ClipBox.top = 0;
119 m_ClipBox.right = m_Width; 34 m_ClipBox.right = m_Width;
120 m_ClipBox.bottom = m_Height; 35 m_ClipBox.bottom = m_Height;
36 }
37 }
38 FX_BOOL CFX_RenderDevice::StartRendering() {
39 return m_pDeviceDriver->StartRendering();
40 }
41 void CFX_RenderDevice::EndRendering() {
42 m_pDeviceDriver->EndRendering();
43 }
44 void CFX_RenderDevice::SaveState() {
45 m_pDeviceDriver->SaveState();
46 }
47 void CFX_RenderDevice::RestoreState(FX_BOOL bKeepSaved) {
48 m_pDeviceDriver->RestoreState(bKeepSaved);
49 UpdateClipBox();
50 }
51 int CFX_RenderDevice::GetDeviceCaps(int caps_id) const {
52 return m_pDeviceDriver->GetDeviceCaps(caps_id);
53 }
54 CFX_Matrix CFX_RenderDevice::GetCTM() const {
55 return m_pDeviceDriver->GetCTM();
56 }
57 FX_BOOL CFX_RenderDevice::CreateCompatibleBitmap(CFX_DIBitmap* pDIB,
58 int width,
59 int height) const {
60 if (m_RenderCaps & FXRC_CMYK_OUTPUT) {
61 return pDIB->Create(
62 width,
63 height,
64 m_RenderCaps & FXRC_ALPHA_OUTPUT ? FXDIB_Cmyka : FXDIB_Cmyk);
65 } else if (m_RenderCaps & FXRC_BYTEMASK_OUTPUT) {
66 return pDIB->Create(width, height, FXDIB_8bppMask);
67 } else
68 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_
69 return pDIB->Create(
70 width,
71 height,
72 m_RenderCaps & FXRC_ALPHA_OUTPUT ? FXDIB_Argb : FXDIB_Rgb32);
73 #else
74 return pDIB->Create(
75 width,
76 height,
77 m_RenderCaps & FXRC_ALPHA_OUTPUT ? FXDIB_Argb : FXDIB_Rgb);
78 #endif
79 }
80 FX_BOOL CFX_RenderDevice::SetClip_PathFill(
81 const CFX_PathData* pPathData,
82 const CFX_AffineMatrix* pObject2Device,
83 int fill_mode) {
84 if (!m_pDeviceDriver->SetClip_PathFill(
85 pPathData, pObject2Device, fill_mode)) {
86 return FALSE;
87 }
88 UpdateClipBox();
89 return TRUE;
90 }
91 FX_BOOL CFX_RenderDevice::SetClip_PathStroke(
92 const CFX_PathData* pPathData,
93 const CFX_AffineMatrix* pObject2Device,
94 const CFX_GraphStateData* pGraphState) {
95 if (!m_pDeviceDriver->SetClip_PathStroke(
96 pPathData, pObject2Device, pGraphState)) {
97 return FALSE;
98 }
99 UpdateClipBox();
100 return TRUE;
101 }
102 FX_BOOL CFX_RenderDevice::SetClip_Rect(const FX_RECT* pRect) {
103 CFX_PathData path;
104 path.AppendRect((FX_FLOAT)(pRect->left),
105 (FX_FLOAT)(pRect->bottom),
106 (FX_FLOAT)(pRect->right),
107 (FX_FLOAT)(pRect->top));
108 if (!SetClip_PathFill(&path, NULL, FXFILL_WINDING)) {
109 return FALSE;
110 }
111 UpdateClipBox();
112 return TRUE;
113 }
114 void CFX_RenderDevice::UpdateClipBox() {
115 if (m_pDeviceDriver->GetClipBox(&m_ClipBox)) {
116 return;
117 }
118 m_ClipBox.left = 0;
119 m_ClipBox.top = 0;
120 m_ClipBox.right = m_Width;
121 m_ClipBox.bottom = m_Height;
121 } 122 }
122 FX_BOOL CFX_RenderDevice::DrawPath(const CFX_PathData* pPathData, 123 FX_BOOL CFX_RenderDevice::DrawPath(const CFX_PathData* pPathData,
123 const CFX_AffineMatrix* pObject2Device, 124 const CFX_AffineMatrix* pObject2Device,
124 const CFX_GraphStateData* pGraphState, 125 const CFX_GraphStateData* pGraphState,
125 FX_DWORD fill_color, FX_DWORD stroke_color, i nt fill_mode, 126 FX_DWORD fill_color,
126 int alpha_flag, void* pIccTransform, int blen d_type) 127 FX_DWORD stroke_color,
127 { 128 int fill_mode,
128 FX_BYTE fill_alpha, stroke_alpha; 129 int alpha_flag,
129 if (FXGETFLAG_COLORTYPE(alpha_flag)) { 130 void* pIccTransform,
130 fill_alpha = FXGETFLAG_ALPHA_FILL(alpha_flag); 131 int blend_type) {
131 stroke_alpha = FXGETFLAG_ALPHA_STROKE(alpha_flag); 132 FX_BYTE fill_alpha, stroke_alpha;
133 if (FXGETFLAG_COLORTYPE(alpha_flag)) {
134 fill_alpha = FXGETFLAG_ALPHA_FILL(alpha_flag);
135 stroke_alpha = FXGETFLAG_ALPHA_STROKE(alpha_flag);
136 } else {
137 fill_alpha = FXARGB_A(fill_color);
138 stroke_alpha = FXARGB_A(stroke_color);
139 }
140 if ((fill_mode & 3) == 0) {
141 fill_alpha = 0;
142 }
143 if (pGraphState == NULL) {
144 stroke_alpha = 0;
145 }
146 if (stroke_alpha == 0 && pPathData->GetPointCount() == 2) {
147 FX_PATHPOINT* pPoints = pPathData->GetPoints();
148 FX_FLOAT x1, x2, y1, y2;
149 if (pObject2Device) {
150 pObject2Device->Transform(
151 pPoints[0].m_PointX, pPoints[0].m_PointY, x1, y1);
152 pObject2Device->Transform(
153 pPoints[1].m_PointX, pPoints[1].m_PointY, x2, y2);
132 } else { 154 } else {
133 fill_alpha = FXARGB_A(fill_color); 155 x1 = pPoints[0].m_PointX;
134 stroke_alpha = FXARGB_A(stroke_color); 156 y1 = pPoints[0].m_PointY;
135 } 157 x2 = pPoints[1].m_PointX;
136 if ((fill_mode & 3) == 0) { 158 y2 = pPoints[1].m_PointY;
137 fill_alpha = 0; 159 }
138 } 160 DrawCosmeticLine(x1,
139 if (pGraphState == NULL) { 161 y1,
140 stroke_alpha = 0; 162 x2,
141 } 163 y2,
142 if (stroke_alpha == 0 && pPathData->GetPointCount() == 2) { 164 fill_color,
143 FX_PATHPOINT* pPoints = pPathData->GetPoints(); 165 fill_mode,
144 FX_FLOAT x1, x2, y1, y2; 166 alpha_flag,
145 if (pObject2Device) { 167 pIccTransform,
146 pObject2Device->Transform(pPoints[0].m_PointX, pPoints[0].m_PointY, x1, y1); 168 blend_type);
147 pObject2Device->Transform(pPoints[1].m_PointX, pPoints[1].m_PointY, x2, y2); 169 return TRUE;
170 }
171 if ((pPathData->GetPointCount() == 5 || pPathData->GetPointCount() == 4) &&
172 stroke_alpha == 0) {
173 CFX_FloatRect rect_f;
174 if (!(fill_mode & FXFILL_RECT_AA) &&
175 pPathData->IsRect(pObject2Device, &rect_f)) {
176 FX_RECT rect_i = rect_f.GetOutterRect();
177 int width = (int)FXSYS_ceil(rect_f.right - rect_f.left);
178 if (width < 1) {
179 width = 1;
180 if (rect_i.left == rect_i.right) {
181 rect_i.right++;
182 }
183 }
184 int height = (int)FXSYS_ceil(rect_f.top - rect_f.bottom);
185 if (height < 1) {
186 height = 1;
187 if (rect_i.bottom == rect_i.top) {
188 rect_i.bottom++;
189 }
190 }
191 if (rect_i.Width() >= width + 1) {
192 if (rect_f.left - (FX_FLOAT)(rect_i.left) >
193 (FX_FLOAT)(rect_i.right) - rect_f.right) {
194 rect_i.left++;
148 } else { 195 } else {
149 x1 = pPoints[0].m_PointX; 196 rect_i.right--;
150 y1 = pPoints[0].m_PointY;
151 x2 = pPoints[1].m_PointX;
152 y2 = pPoints[1].m_PointY;
153 } 197 }
154 DrawCosmeticLine(x1, y1, x2, y2, fill_color, fill_mode, alpha_flag, pIcc Transform, blend_type); 198 }
199 if (rect_i.Height() >= height + 1) {
200 if (rect_f.top - (FX_FLOAT)(rect_i.top) >
201 (FX_FLOAT)(rect_i.bottom) - rect_f.bottom) {
202 rect_i.top++;
203 } else {
204 rect_i.bottom--;
205 }
206 }
207 if (FillRect(
208 &rect_i, fill_color, alpha_flag, pIccTransform, blend_type)) {
155 return TRUE; 209 return TRUE;
156 } 210 }
157 if ((pPathData->GetPointCount() == 5 || pPathData->GetPointCount() == 4) && stroke_alpha == 0) { 211 }
158 CFX_FloatRect rect_f; 212 }
159 if (!(fill_mode & FXFILL_RECT_AA) && pPathData->IsRect(pObject2Device, & rect_f)) { 213 if ((fill_mode & 3) && stroke_alpha == 0 && !(fill_mode & FX_FILL_STROKE) &&
160 FX_RECT rect_i = rect_f.GetOutterRect(); 214 !(fill_mode & FX_FILL_TEXT_MODE)) {
161 int width = (int)FXSYS_ceil(rect_f.right - rect_f.left); 215 CFX_PathData newPath;
162 if (width < 1) { 216 FX_BOOL bThin = FALSE;
163 width = 1; 217 if (pPathData->GetZeroAreaPath(newPath,
164 if (rect_i.left == rect_i.right) { 218 (CFX_Matrix*)pObject2Device,
165 rect_i.right ++; 219 bThin,
166 } 220 m_pDeviceDriver->GetDriverType())) {
167 } 221 CFX_GraphStateData graphState;
168 int height = (int)FXSYS_ceil(rect_f.top - rect_f.bottom); 222 graphState.m_LineWidth = 0.0f;
169 if (height < 1) { 223 FX_DWORD strokecolor = fill_color;
170 height = 1; 224 if (bThin) {
171 if (rect_i.bottom == rect_i.top) { 225 if (FXGETFLAG_COLORTYPE(alpha_flag)) {
172 rect_i.bottom ++; 226 FXSETFLAG_ALPHA_STROKE(alpha_flag, fill_alpha >> 2);
173 } 227 } else {
174 } 228 strokecolor =
175 if (rect_i.Width() >= width + 1) { 229 (((fill_alpha >> 2) << 24) | (strokecolor & 0x00ffffff));
176 if (rect_f.left - (FX_FLOAT)(rect_i.left) > (FX_FLOAT)(rect_i.ri ght) - rect_f.right) {
177 rect_i.left ++;
178 } else {
179 rect_i.right --;
180 }
181 }
182 if (rect_i.Height() >= height + 1) {
183 if (rect_f.top - (FX_FLOAT)(rect_i.top) > (FX_FLOAT)(rect_i.bott om) - rect_f.bottom) {
184 rect_i.top ++;
185 } else {
186 rect_i.bottom --;
187 }
188 }
189 if (FillRect(&rect_i, fill_color, alpha_flag, pIccTransform, blend_t ype)) {
190 return TRUE;
191 }
192 } 230 }
193 } 231 }
194 if((fill_mode & 3) && stroke_alpha == 0 && !(fill_mode & FX_FILL_STROKE) && !(fill_mode & FX_FILL_TEXT_MODE)) { 232 CFX_AffineMatrix* pMatrix = NULL;
195 CFX_PathData newPath; 233 if (pObject2Device && !pObject2Device->IsIdentity()) {
196 FX_BOOL bThin = FALSE; 234 pMatrix = (CFX_AffineMatrix*)pObject2Device;
197 if (pPathData->GetZeroAreaPath(newPath, (CFX_Matrix*)pObject2Device, bTh in, m_pDeviceDriver->GetDriverType())) { 235 }
198 CFX_GraphStateData graphState; 236 int smooth_path = FX_ZEROAREA_FILL;
199 graphState.m_LineWidth = 0.0f; 237 if (fill_mode & FXFILL_NOPATHSMOOTH) {
200 FX_DWORD strokecolor = fill_color; 238 smooth_path |= FXFILL_NOPATHSMOOTH;
201 if (bThin) { 239 }
202 if (FXGETFLAG_COLORTYPE(alpha_flag)) { 240 m_pDeviceDriver->DrawPath(&newPath,
203 FXSETFLAG_ALPHA_STROKE(alpha_flag, fill_alpha >> 2); 241 pMatrix,
204 } else { 242 &graphState,
205 strokecolor = (((fill_alpha >> 2) << 24) | (strokecolor & 0x 00ffffff)); 243 0,
206 } 244 strokecolor,
207 } 245 smooth_path,
208 CFX_AffineMatrix* pMatrix = NULL; 246 alpha_flag,
209 if (pObject2Device && !pObject2Device->IsIdentity()) { 247 pIccTransform,
210 pMatrix = (CFX_AffineMatrix*)pObject2Device; 248 blend_type);
211 } 249 }
212 int smooth_path = FX_ZEROAREA_FILL; 250 }
213 if (fill_mode & FXFILL_NOPATHSMOOTH) { 251 if ((fill_mode & 3) && fill_alpha && stroke_alpha < 0xff &&
214 smooth_path |= FXFILL_NOPATHSMOOTH; 252 (fill_mode & FX_FILL_STROKE)) {
215 }
216 m_pDeviceDriver->DrawPath(&newPath, pMatrix, &graphState, 0, strokec olor, smooth_path, alpha_flag, pIccTransform, blend_type);
217 }
218 }
219 if ((fill_mode & 3) && fill_alpha && stroke_alpha < 0xff && (fill_mode & FX_ FILL_STROKE)) {
220 if (!(m_RenderCaps & FXRC_GET_BITS)) {
221 return FALSE;
222 }
223 CFX_FloatRect bbox;
224 if (pGraphState) {
225 bbox = pPathData->GetBoundingBox(pGraphState->m_LineWidth, pGraphSta te->m_MiterLimit);
226 } else {
227 bbox = pPathData->GetBoundingBox();
228 }
229 if (pObject2Device) {
230 bbox.Transform(pObject2Device);
231 }
232 CFX_Matrix ctm = GetCTM();
233 FX_FLOAT fScaleX = FXSYS_fabs(ctm.a);
234 FX_FLOAT fScaleY = FXSYS_fabs(ctm.d);
235 FX_RECT rect = bbox.GetOutterRect();
236 CFX_DIBitmap bitmap, Backdrop;
237 if (!CreateCompatibleBitmap(&bitmap, FXSYS_round(rect.Width() * fScaleX) , FXSYS_round(rect.Height() * fScaleY))) {
238 return FALSE;
239 }
240 if (bitmap.HasAlpha()) {
241 bitmap.Clear(0);
242 Backdrop.Copy(&bitmap);
243 } else {
244 if (!m_pDeviceDriver->GetDIBits(&bitmap, rect.left, rect.top, NULL)) {
245 return FALSE;
246 }
247 Backdrop.Copy(&bitmap);
248 }
249 CFX_FxgeDevice bitmap_device;
250 bitmap_device.Attach(&bitmap, 0, FALSE, &Backdrop, TRUE);
251 CFX_AffineMatrix matrix;
252 if (pObject2Device) {
253 matrix = *pObject2Device;
254 }
255 matrix.TranslateI(-rect.left, -rect.top);
256 matrix.Concat(fScaleX, 0, 0, fScaleY, 0, 0);
257 if (!bitmap_device.GetDeviceDriver()->DrawPath(pPathData, &matrix, pGrap hState, fill_color, stroke_color, fill_mode, alpha_flag, pIccTransform, blend_ty pe)) {
258 return FALSE;
259 }
260 FX_RECT src_rect(0, 0, FXSYS_round(rect.Width() * fScaleX), FXSYS_round( rect.Height() * fScaleY));
261 return m_pDeviceDriver->SetDIBits(&bitmap, 0, &src_rect, rect.left, rect .top, FXDIB_BLEND_NORMAL);
262 }
263 return m_pDeviceDriver->DrawPath(pPathData, pObject2Device, pGraphState, fil l_color, stroke_color, fill_mode, alpha_flag, pIccTransform, blend_type);
264 }
265 FX_BOOL CFX_RenderDevice::SetPixel(int x, int y, FX_DWORD color, int alpha_flag, void* pIccTransform)
266 {
267 if (m_pDeviceDriver->SetPixel(x, y, color, alpha_flag, pIccTransform)) {
268 return TRUE;
269 }
270 FX_RECT rect(x, y, x + 1, y + 1);
271 return FillRect(&rect, color, alpha_flag, pIccTransform);
272 }
273 FX_BOOL CFX_RenderDevice::FillRect(const FX_RECT* pRect, FX_DWORD fill_color, in t alpha_flag, void* pIccTransform, int blend_type)
274 {
275 if (m_pDeviceDriver->FillRect(pRect, fill_color, alpha_flag, pIccTransform, blend_type)) {
276 return TRUE;
277 }
278 if (!(m_RenderCaps & FXRC_GET_BITS)) { 253 if (!(m_RenderCaps & FXRC_GET_BITS)) {
279 return FALSE; 254 return FALSE;
280 } 255 }
281 CFX_DIBitmap bitmap; 256 CFX_FloatRect bbox;
282 if (!CreateCompatibleBitmap(&bitmap, pRect->Width(), pRect->Height())) { 257 if (pGraphState) {
283 return FALSE; 258 bbox = pPathData->GetBoundingBox(pGraphState->m_LineWidth,
284 } 259 pGraphState->m_MiterLimit);
285 if (!m_pDeviceDriver->GetDIBits(&bitmap, pRect->left, pRect->top)) { 260 } else {
286 return FALSE; 261 bbox = pPathData->GetBoundingBox();
287 } 262 }
288 if (!bitmap.CompositeRect(0, 0, pRect->Width(), pRect->Height(), fill_color, alpha_flag, pIccTransform)) { 263 if (pObject2Device) {
289 return FALSE; 264 bbox.Transform(pObject2Device);
290 } 265 }
291 FX_RECT src_rect(0, 0, pRect->Width(), pRect->Height()); 266 CFX_Matrix ctm = GetCTM();
292 m_pDeviceDriver->SetDIBits(&bitmap, 0, &src_rect, pRect->left, pRect->top, F XDIB_BLEND_NORMAL);
293 return TRUE;
294 }
295 FX_BOOL CFX_RenderDevice::DrawCosmeticLine(FX_FLOAT x1, FX_FLOAT y1, FX_FLOAT x2 , FX_FLOAT y2, FX_DWORD color,
296 int fill_mode, int alpha_flag, void* pIccTransform, int blend_type)
297 {
298 if (((m_RenderCaps & FXRC_ALPHA_PATH) &&
299 (FXGETFLAG_COLORTYPE(alpha_flag) && FXGETFLAG_ALPHA_FILL(alpha_flag) == 0xff)) ||
300 color >= 0xff000000)
301 if (m_pDeviceDriver->DrawCosmeticLine(x1, y1, x2, y2, color, alpha_flag, pIccTransform, blend_type)) {
302 return TRUE;
303 }
304 CFX_GraphStateData graph_state;
305 CFX_PathData path;
306 path.SetPointCount(2);
307 path.SetPoint(0, x1, y1, FXPT_MOVETO);
308 path.SetPoint(1, x2, y2, FXPT_LINETO);
309 return m_pDeviceDriver->DrawPath(&path, NULL, &graph_state, 0, color, fill_m ode, alpha_flag, pIccTransform, blend_type);
310 }
311 FX_BOOL CFX_RenderDevice::GetDIBits(CFX_DIBitmap* pBitmap, int left, int top, vo id* pIccTransform)
312 {
313 if (!(m_RenderCaps & FXRC_GET_BITS)) {
314 return FALSE;
315 }
316 return m_pDeviceDriver->GetDIBits(pBitmap, left, top, pIccTransform);
317 }
318 CFX_DIBitmap* CFX_RenderDevice::GetBackDrop()
319 {
320 return m_pDeviceDriver->GetBackDrop();
321 }
322 FX_BOOL CFX_RenderDevice::SetDIBits(const CFX_DIBSource* pBitmap, int left, int top, int blend_mode,
323 void* pIccTransform)
324 {
325 ASSERT(!pBitmap->IsAlphaMask());
326 CFX_AffineMatrix ctm = GetCTM();
327 FX_FLOAT fScaleX = FXSYS_fabs(ctm.a); 267 FX_FLOAT fScaleX = FXSYS_fabs(ctm.a);
328 FX_FLOAT fScaleY = FXSYS_fabs(ctm.d); 268 FX_FLOAT fScaleY = FXSYS_fabs(ctm.d);
329 FX_RECT dest_rect(left, top, FXSYS_round(left + pBitmap->GetWidth() / fScale X), FXSYS_round(top + pBitmap->GetHeight() / fScaleY)); 269 FX_RECT rect = bbox.GetOutterRect();
330 dest_rect.Intersect(m_ClipBox); 270 CFX_DIBitmap bitmap, Backdrop;
331 if (dest_rect.IsEmpty()) { 271 if (!CreateCompatibleBitmap(&bitmap,
332 return TRUE; 272 FXSYS_round(rect.Width() * fScaleX),
333 } 273 FXSYS_round(rect.Height() * fScaleY))) {
334 FX_RECT src_rect(dest_rect.left - left, dest_rect.top - top, 274 return FALSE;
335 dest_rect.left - left + dest_rect.Width(), dest_rect.top - top + dest_rect.Height()); 275 }
336 src_rect.left = FXSYS_round(src_rect.left * fScaleX); 276 if (bitmap.HasAlpha()) {
337 src_rect.top = FXSYS_round(src_rect.top * fScaleY); 277 bitmap.Clear(0);
338 src_rect.right = FXSYS_round(src_rect.right * fScaleX); 278 Backdrop.Copy(&bitmap);
339 src_rect.bottom = FXSYS_round(src_rect.bottom * fScaleY); 279 } else {
340 if ((blend_mode != FXDIB_BLEND_NORMAL && !(m_RenderCaps & FXRC_BLEND_MODE)) || 280 if (!m_pDeviceDriver->GetDIBits(&bitmap, rect.left, rect.top, NULL)) {
341 (pBitmap->HasAlpha() && !(m_RenderCaps & FXRC_ALPHA_IMAGE))) { 281 return FALSE;
342 if (!(m_RenderCaps & FXRC_GET_BITS)) { 282 }
343 return FALSE; 283 Backdrop.Copy(&bitmap);
344 } 284 }
345 int bg_pixel_width = FXSYS_round(dest_rect.Width() * fScaleX); 285 CFX_FxgeDevice bitmap_device;
346 int bg_pixel_height = FXSYS_round(dest_rect.Height() * fScaleY); 286 bitmap_device.Attach(&bitmap, 0, FALSE, &Backdrop, TRUE);
347 CFX_DIBitmap background; 287 CFX_AffineMatrix matrix;
348 if (!background.Create(bg_pixel_width, bg_pixel_height, 288 if (pObject2Device) {
349 (m_RenderCaps & FXRC_CMYK_OUTPUT) ? FXDIB_Cmyk : FXDIB_Rgb32)) { 289 matrix = *pObject2Device;
350 return FALSE; 290 }
351 } 291 matrix.TranslateI(-rect.left, -rect.top);
352 if (!m_pDeviceDriver->GetDIBits(&background, dest_rect.left, dest_rect.t op)) { 292 matrix.Concat(fScaleX, 0, 0, fScaleY, 0, 0);
353 return FALSE; 293 if (!bitmap_device.GetDeviceDriver()->DrawPath(pPathData,
354 } 294 &matrix,
355 if (!background.CompositeBitmap(0, 0, bg_pixel_width, bg_pixel_height, 295 pGraphState,
356 pBitmap, src_rect.left, src_rect.top, 296 fill_color,
357 blend_mode, NULL, FALSE, pIccTransform)) { 297 stroke_color,
358 return FALSE; 298 fill_mode,
359 } 299 alpha_flag,
360 FX_RECT src_rect(0, 0, bg_pixel_width, bg_pixel_height); 300 pIccTransform,
361 return m_pDeviceDriver->SetDIBits(&background, 0, &src_rect, dest_rect.l eft, dest_rect.top, FXDIB_BLEND_NORMAL); 301 blend_type)) {
362 } 302 return FALSE;
363 return m_pDeviceDriver->SetDIBits(pBitmap, 0, &src_rect, dest_rect.left, des t_rect.top, blend_mode, 0, pIccTransform); 303 }
364 } 304 FX_RECT src_rect(0,
365 FX_BOOL CFX_RenderDevice::StretchDIBits(const CFX_DIBSource* pBitmap, int left, int top, 305 0,
366 int dest_width, int dest_height, FX_DWOR D flags, 306 FXSYS_round(rect.Width() * fScaleX),
367 void* pIccTransform, int blend_mode) 307 FXSYS_round(rect.Height() * fScaleY));
368 { 308 return m_pDeviceDriver->SetDIBits(
369 FX_RECT dest_rect(left, top, left + dest_width, top + dest_height); 309 &bitmap, 0, &src_rect, rect.left, rect.top, FXDIB_BLEND_NORMAL);
370 FX_RECT clip_box = m_ClipBox; 310 }
371 clip_box.Intersect(dest_rect); 311 return m_pDeviceDriver->DrawPath(pPathData,
372 if (clip_box.IsEmpty()) { 312 pObject2Device,
373 return TRUE; 313 pGraphState,
374 } 314 fill_color,
375 return m_pDeviceDriver->StretchDIBits(pBitmap, 0, left, top, dest_width, des t_height, &clip_box, flags, 0, pIccTransform, blend_mode); 315 stroke_color,
376 } 316 fill_mode,
377 FX_BOOL CFX_RenderDevice::SetBitMask(const CFX_DIBSource* pBitmap, int left, int top, FX_DWORD argb, 317 alpha_flag,
378 int alpha_flag, void* pIccTransform) 318 pIccTransform,
379 { 319 blend_type);
380 FX_RECT src_rect(0, 0, pBitmap->GetWidth(), pBitmap->GetHeight()); 320 }
381 return m_pDeviceDriver->SetDIBits(pBitmap, argb, &src_rect, left, top, FXDIB _BLEND_NORMAL, alpha_flag, pIccTransform); 321 FX_BOOL CFX_RenderDevice::SetPixel(int x,
382 } 322 int y,
383 FX_BOOL CFX_RenderDevice::StretchBitMask(const CFX_DIBSource* pBitmap, int left, int top, 323 FX_DWORD color,
384 int dest_width, int dest_height, FX_DWORD argb, FX_DWORD flags, 324 int alpha_flag,
385 int alpha_flag, void* pIccTransform) 325 void* pIccTransform) {
386 { 326 if (m_pDeviceDriver->SetPixel(x, y, color, alpha_flag, pIccTransform)) {
387 FX_RECT dest_rect(left, top, left + dest_width, top + dest_height); 327 return TRUE;
388 FX_RECT clip_box = m_ClipBox; 328 }
389 clip_box.Intersect(dest_rect); 329 FX_RECT rect(x, y, x + 1, y + 1);
390 return m_pDeviceDriver->StretchDIBits(pBitmap, argb, left, top, dest_width, dest_height, &clip_box, flags, alpha_flag, pIccTransform); 330 return FillRect(&rect, color, alpha_flag, pIccTransform);
391 } 331 }
392 FX_BOOL CFX_RenderDevice::StartDIBits(const CFX_DIBSource* pBitmap, int bitmap_a lpha, FX_DWORD argb, 332 FX_BOOL CFX_RenderDevice::FillRect(const FX_RECT* pRect,
393 const CFX_AffineMatrix* pMatrix, FX_DWORD flags, FX_LPVOID& handle, 333 FX_DWORD fill_color,
394 int alpha_flag, void* pIccTransform, int b lend_mode) 334 int alpha_flag,
395 { 335 void* pIccTransform,
396 return m_pDeviceDriver->StartDIBits(pBitmap, bitmap_alpha, argb, pMatrix, fl ags, handle, alpha_flag, pIccTransform, blend_mode); 336 int blend_type) {
397 } 337 if (m_pDeviceDriver->FillRect(
398 FX_BOOL CFX_RenderDevice::ContinueDIBits(FX_LPVOID handle, IFX_Pause* pPause) 338 pRect, fill_color, alpha_flag, pIccTransform, blend_type)) {
399 { 339 return TRUE;
400 return m_pDeviceDriver->ContinueDIBits(handle, pPause); 340 }
401 } 341 if (!(m_RenderCaps & FXRC_GET_BITS)) {
402 void CFX_RenderDevice::CancelDIBits(FX_LPVOID handle) 342 return FALSE;
403 { 343 }
404 m_pDeviceDriver->CancelDIBits(handle); 344 CFX_DIBitmap bitmap;
405 } 345 if (!CreateCompatibleBitmap(&bitmap, pRect->Width(), pRect->Height())) {
346 return FALSE;
347 }
348 if (!m_pDeviceDriver->GetDIBits(&bitmap, pRect->left, pRect->top)) {
349 return FALSE;
350 }
351 if (!bitmap.CompositeRect(0,
352 0,
353 pRect->Width(),
354 pRect->Height(),
355 fill_color,
356 alpha_flag,
357 pIccTransform)) {
358 return FALSE;
359 }
360 FX_RECT src_rect(0, 0, pRect->Width(), pRect->Height());
361 m_pDeviceDriver->SetDIBits(
362 &bitmap, 0, &src_rect, pRect->left, pRect->top, FXDIB_BLEND_NORMAL);
363 return TRUE;
364 }
365 FX_BOOL CFX_RenderDevice::DrawCosmeticLine(FX_FLOAT x1,
366 FX_FLOAT y1,
367 FX_FLOAT x2,
368 FX_FLOAT y2,
369 FX_DWORD color,
370 int fill_mode,
371 int alpha_flag,
372 void* pIccTransform,
373 int blend_type) {
374 if (((m_RenderCaps & FXRC_ALPHA_PATH) &&
375 (FXGETFLAG_COLORTYPE(alpha_flag) &&
376 FXGETFLAG_ALPHA_FILL(alpha_flag) == 0xff)) ||
377 color >= 0xff000000)
378 if (m_pDeviceDriver->DrawCosmeticLine(
379 x1, y1, x2, y2, color, alpha_flag, pIccTransform, blend_type)) {
380 return TRUE;
381 }
382 CFX_GraphStateData graph_state;
383 CFX_PathData path;
384 path.SetPointCount(2);
385 path.SetPoint(0, x1, y1, FXPT_MOVETO);
386 path.SetPoint(1, x2, y2, FXPT_LINETO);
387 return m_pDeviceDriver->DrawPath(&path,
388 NULL,
389 &graph_state,
390 0,
391 color,
392 fill_mode,
393 alpha_flag,
394 pIccTransform,
395 blend_type);
396 }
397 FX_BOOL CFX_RenderDevice::GetDIBits(CFX_DIBitmap* pBitmap,
398 int left,
399 int top,
400 void* pIccTransform) {
401 if (!(m_RenderCaps & FXRC_GET_BITS)) {
402 return FALSE;
403 }
404 return m_pDeviceDriver->GetDIBits(pBitmap, left, top, pIccTransform);
405 }
406 CFX_DIBitmap* CFX_RenderDevice::GetBackDrop() {
407 return m_pDeviceDriver->GetBackDrop();
408 }
409 FX_BOOL CFX_RenderDevice::SetDIBits(const CFX_DIBSource* pBitmap,
410 int left,
411 int top,
412 int blend_mode,
413 void* pIccTransform) {
414 ASSERT(!pBitmap->IsAlphaMask());
415 CFX_AffineMatrix ctm = GetCTM();
416 FX_FLOAT fScaleX = FXSYS_fabs(ctm.a);
417 FX_FLOAT fScaleY = FXSYS_fabs(ctm.d);
418 FX_RECT dest_rect(left,
419 top,
420 FXSYS_round(left + pBitmap->GetWidth() / fScaleX),
421 FXSYS_round(top + pBitmap->GetHeight() / fScaleY));
422 dest_rect.Intersect(m_ClipBox);
423 if (dest_rect.IsEmpty()) {
424 return TRUE;
425 }
426 FX_RECT src_rect(dest_rect.left - left,
427 dest_rect.top - top,
428 dest_rect.left - left + dest_rect.Width(),
429 dest_rect.top - top + dest_rect.Height());
430 src_rect.left = FXSYS_round(src_rect.left * fScaleX);
431 src_rect.top = FXSYS_round(src_rect.top * fScaleY);
432 src_rect.right = FXSYS_round(src_rect.right * fScaleX);
433 src_rect.bottom = FXSYS_round(src_rect.bottom * fScaleY);
434 if ((blend_mode != FXDIB_BLEND_NORMAL && !(m_RenderCaps & FXRC_BLEND_MODE)) ||
435 (pBitmap->HasAlpha() && !(m_RenderCaps & FXRC_ALPHA_IMAGE))) {
436 if (!(m_RenderCaps & FXRC_GET_BITS)) {
437 return FALSE;
438 }
439 int bg_pixel_width = FXSYS_round(dest_rect.Width() * fScaleX);
440 int bg_pixel_height = FXSYS_round(dest_rect.Height() * fScaleY);
441 CFX_DIBitmap background;
442 if (!background.Create(
443 bg_pixel_width,
444 bg_pixel_height,
445 (m_RenderCaps & FXRC_CMYK_OUTPUT) ? FXDIB_Cmyk : FXDIB_Rgb32)) {
446 return FALSE;
447 }
448 if (!m_pDeviceDriver->GetDIBits(
449 &background, dest_rect.left, dest_rect.top)) {
450 return FALSE;
451 }
452 if (!background.CompositeBitmap(0,
453 0,
454 bg_pixel_width,
455 bg_pixel_height,
456 pBitmap,
457 src_rect.left,
458 src_rect.top,
459 blend_mode,
460 NULL,
461 FALSE,
462 pIccTransform)) {
463 return FALSE;
464 }
465 FX_RECT src_rect(0, 0, bg_pixel_width, bg_pixel_height);
466 return m_pDeviceDriver->SetDIBits(&background,
467 0,
468 &src_rect,
469 dest_rect.left,
470 dest_rect.top,
471 FXDIB_BLEND_NORMAL);
472 }
473 return m_pDeviceDriver->SetDIBits(pBitmap,
474 0,
475 &src_rect,
476 dest_rect.left,
477 dest_rect.top,
478 blend_mode,
479 0,
480 pIccTransform);
481 }
482 FX_BOOL CFX_RenderDevice::StretchDIBits(const CFX_DIBSource* pBitmap,
483 int left,
484 int top,
485 int dest_width,
486 int dest_height,
487 FX_DWORD flags,
488 void* pIccTransform,
489 int blend_mode) {
490 FX_RECT dest_rect(left, top, left + dest_width, top + dest_height);
491 FX_RECT clip_box = m_ClipBox;
492 clip_box.Intersect(dest_rect);
493 if (clip_box.IsEmpty()) {
494 return TRUE;
495 }
496 return m_pDeviceDriver->StretchDIBits(pBitmap,
497 0,
498 left,
499 top,
500 dest_width,
501 dest_height,
502 &clip_box,
503 flags,
504 0,
505 pIccTransform,
506 blend_mode);
507 }
508 FX_BOOL CFX_RenderDevice::SetBitMask(const CFX_DIBSource* pBitmap,
509 int left,
510 int top,
511 FX_DWORD argb,
512 int alpha_flag,
513 void* pIccTransform) {
514 FX_RECT src_rect(0, 0, pBitmap->GetWidth(), pBitmap->GetHeight());
515 return m_pDeviceDriver->SetDIBits(pBitmap,
516 argb,
517 &src_rect,
518 left,
519 top,
520 FXDIB_BLEND_NORMAL,
521 alpha_flag,
522 pIccTransform);
523 }
524 FX_BOOL CFX_RenderDevice::StretchBitMask(const CFX_DIBSource* pBitmap,
525 int left,
526 int top,
527 int dest_width,
528 int dest_height,
529 FX_DWORD argb,
530 FX_DWORD flags,
531 int alpha_flag,
532 void* pIccTransform) {
533 FX_RECT dest_rect(left, top, left + dest_width, top + dest_height);
534 FX_RECT clip_box = m_ClipBox;
535 clip_box.Intersect(dest_rect);
536 return m_pDeviceDriver->StretchDIBits(pBitmap,
537 argb,
538 left,
539 top,
540 dest_width,
541 dest_height,
542 &clip_box,
543 flags,
544 alpha_flag,
545 pIccTransform);
546 }
547 FX_BOOL CFX_RenderDevice::StartDIBits(const CFX_DIBSource* pBitmap,
548 int bitmap_alpha,
549 FX_DWORD argb,
550 const CFX_AffineMatrix* pMatrix,
551 FX_DWORD flags,
552 FX_LPVOID& handle,
553 int alpha_flag,
554 void* pIccTransform,
555 int blend_mode) {
556 return m_pDeviceDriver->StartDIBits(pBitmap,
557 bitmap_alpha,
558 argb,
559 pMatrix,
560 flags,
561 handle,
562 alpha_flag,
563 pIccTransform,
564 blend_mode);
565 }
566 FX_BOOL CFX_RenderDevice::ContinueDIBits(FX_LPVOID handle, IFX_Pause* pPause) {
567 return m_pDeviceDriver->ContinueDIBits(handle, pPause);
568 }
569 void CFX_RenderDevice::CancelDIBits(FX_LPVOID handle) {
570 m_pDeviceDriver->CancelDIBits(handle);
571 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698