Revert "FX Bool considered harmful, part 3"
[pdfium.git] / core / src / fxge / skia / fx_skia_device.cpp
1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "../../../include/fxge/fx_ge.h"
6 //#define _SKIA_SUPPORT_
7 #if defined(_SKIA_SUPPORT_)
8 #include "../../../include/fxcodec/fx_codec.h"
9
10
11 //#define _FOXIT_DEBUG_
12 //#define _FOXIT_BENCHMARK_
13
14 extern "C" {
15         extern void FX_OUTPUT_LOG_FUNC(const char*, ...);
16         extern int FX_GET_TICK_FUNC();
17 };
18
19 #ifdef _FOXIT_DEBUG_
20 #define FOXIT_DEBUG1(msg) FX_OUTPUT_LOG_FUNC(msg)
21 #define FOXIT_DEBUG2(msg,para) FX_OUTPUT_LOG_FUNC(msg,para)
22 #define FOXIT_DEBUG3(msg,para1,para2) FX_OUTPUT_LOG_FUNC(msg,para1,para2)
23 #define FOXIT_DEBUG4(msg,para1,para2,para3) FX_OUTPUT_LOG_FUNC(msg,para1,para2,para3)
24 #define FOXIT_DEBUG5(msg,para1,para2,para3,param4) FX_OUTPUT_LOG_FUNC(msg,para1,para2,para3,param4)
25 #else
26 #define FOXIT_DEBUG1(msg)
27 #define FOXIT_DEBUG2(msg,para)
28 #define FOXIT_DEBUG3(msg,para1,para2)
29 #define FOXIT_DEBUG4(msg,para1,para2,para3)
30 #define FOXIT_DEBUG5(msg,para1,para2,para3,param4)
31 #endif
32
33 #include "SkDashPathEffect.h"
34 #include "SkTLazy.h"
35 #include "SkScan.h"
36 #include "SkRasterClip.h"
37 #include "SkStroke.h"
38
39
40 #include "fx_skia_blitter_new.h"
41 #include "../agg/fx_agg_driver.h"
42 #include "fx_skia_device.h"
43 /// Run-length-encoded supersampling antialiased blitter.
44 class SuperBlitter_skia
45 {
46 public:
47         static void DrawPath(const SkPath& srcPath, SkBlitter* blitter,  const SkRasterClip& rect, const SkPaint& origPaint);
48 };
49 FX_BOOL FxSkDrawTreatAsHairline(const SkPaint& paint, SkScalar* coverage) {
50         if (SkPaint::kStroke_Style != paint.getStyle())
51                 return FALSE;
52         FXSYS_assert(coverage);
53         SkScalar strokeWidth = paint.getStrokeWidth();
54         if (0 == strokeWidth) {
55                 *coverage = SK_Scalar1;
56                 return TRUE;
57         }
58         // if we get here, we need to try to fake a thick-stroke with a modulated
59         // hairline
60         if (!paint.isAntiAlias())
61                 return FALSE;
62         if (strokeWidth <= SK_Scalar1) {
63                 *coverage = strokeWidth;
64                 return TRUE;
65         }
66         return FALSE;
67 }
68
69 void SuperBlitter_skia::DrawPath(const SkPath& srcPath, SkBlitter* blitter, const SkRasterClip& rect, const SkPaint& origPaint)
70 {
71         SkPath*         pathPtr = (SkPath*)&srcPath;
72         bool            doFill = true;
73         SkPath          tmpPath;
74         SkTCopyOnFirstWrite<SkPaint> paint(origPaint);
75         {
76                 SkScalar coverage;
77                 if (FxSkDrawTreatAsHairline(origPaint, &coverage)) {
78                         if (SK_Scalar1 == coverage) {
79                                 paint.writable()->setStrokeWidth(0);
80                         } else if (1) {//xfermodeSupportsCoverageAsAlpha(xfer), we not use blend mode here, xfer aways NULL.
81                                 U8CPU newAlpha;
82                                 // this is the old technique, which we preserve for now so
83                                 // we don't change previous results (testing)
84                                 // the new way seems fine, its just (a tiny bit) different
85                                 int scale = (int)SkScalarMul(coverage, 256);
86                                 newAlpha = origPaint.getAlpha() * scale >> 8;
87                                 SkPaint* writablePaint = paint.writable();
88                                 writablePaint->setStrokeWidth(0);
89                                 writablePaint->setAlpha(newAlpha);
90                         }
91                 }
92         }
93         if (paint->getPathEffect() || paint->getStyle() != SkPaint::kFill_Style) {
94                 SkIRect devBounds = rect.getBounds();
95                 // outset to have slop for antialasing and hairlines
96                 devBounds.outset(1, 1);
97                 SkRect cullRect = SkRect::Make(devBounds);
98                 doFill = paint->getFillPath(*pathPtr, &tmpPath, &cullRect);
99                 pathPtr = &tmpPath;
100         }
101         // avoid possibly allocating a new path in transform if we can
102         SkPath* devPathPtr = pathPtr;
103         void (*proc)(const SkPath&, const SkRasterClip&, SkBlitter*);
104         if (doFill) {
105                 if (paint->isAntiAlias()) {
106                         proc = SkScan::AntiFillPath;
107                 } else {
108                         proc = SkScan::FillPath;
109                 }
110         } else {        // hairline
111                 if (paint->isAntiAlias()) {
112                         proc = SkScan::AntiHairPath;
113                 } else {
114                         proc = SkScan::HairPath;
115                 }
116         }
117         proc(*devPathPtr, rect, blitter);
118 }
119
120 class CSkia_PathData
121 {
122 public:
123         CSkia_PathData() {}
124         ~CSkia_PathData() {}
125         SkPath                  m_PathData;
126
127         void                    BuildPath(const CFX_PathData* pPathData, const CFX_AffineMatrix* pObject2Device);
128 };
129
130 void CSkia_PathData::BuildPath(const CFX_PathData* pPathData, const CFX_AffineMatrix* pObject2Device)
131 {
132         const CFX_PathData* pFPath = pPathData;
133         int nPoints = pFPath->GetPointCount();
134         FX_PATHPOINT* pPoints = pFPath->GetPoints();
135         for (int i = 0; i < nPoints; i ++) {
136                 FX_FIXFLOAT x = pPoints[i].m_PointX, y = pPoints[i].m_PointY;
137                 if (pObject2Device) pObject2Device->Transform(x, y);
138                 int point_type = pPoints[i].m_Flag & FXPT_TYPE;
139                 if (point_type == FXPT_MOVETO) {
140                         m_PathData.moveTo(x, y);
141                 } else if (point_type == FXPT_LINETO) {
142                         if (pPoints[i-1].m_Flag == FXPT_MOVETO && (i == nPoints-1 || pPoints[i+1].m_Flag == FXPT_MOVETO) &&
143                                         FXSYS_abs(pPoints[i].m_PointX - pPoints[i-1].m_PointX) < 0.4f && FXSYS_abs(pPoints[i].m_PointY - pPoints[i-1].m_PointY)< 0.4f)
144                                 // PDF line includes the destination point, unlike Windows line.
145                                 // We received some PDF which actually draws zero length lines. TESTDOC: summer cha show.pdf
146                                 // Therefore, we have to extend the line by 0.4 pixel here.
147                                 // But only for standalone segment. TESTDOC: bug #1434 - maze.pdf; TESTDOC: bug#1508 di704P_QIG_111.pdf
148                                 x += 0.4;
149                         // TODO: we should actually tell skia vertex generator to process zero length stroked line
150                         // (only butts are drawn)
151                         m_PathData.lineTo(x, y);
152                 } else if (point_type == FXPT_BEZIERTO) {
153                         FX_FIXFLOAT x2 = pPoints[i+1].m_PointX, y2 = pPoints[i+1].m_PointY;
154                         FX_FIXFLOAT x3 = pPoints[i+2].m_PointX, y3 = pPoints[i+2].m_PointY;
155                         if (pObject2Device){
156                                 pObject2Device->Transform(x2, y2);
157                                 pObject2Device->Transform(x3, y3);
158                         }
159                         m_PathData.cubicTo(x, y, x2, y2, x3, y3);
160                         i += 2;
161                 }
162                 if (pPoints[i].m_Flag & FXPT_CLOSEFIGURE) m_PathData.close();
163         }
164 }
165
166 // convert a stroking path to scanlines
167 static void SkRasterizeStroke(SkPaint& spaint, SkPath* dstPathData, SkPath& path_data,
168                                          const CFX_AffineMatrix* pObject2Device,
169                                          const CFX_GraphStateData* pGraphState, FX_FIXFLOAT scale = FIX8_ONE,
170                                          FX_BOOL bStrokeAdjust = FALSE, FX_BOOL bTextMode = FALSE)
171 {
172         SkPaint::Cap cap;
173         switch (pGraphState->m_LineCap) {
174                 case CFX_GraphStateData::LineCapRound:
175                         cap = SkPaint::kRound_Cap;
176                         break;
177                 case CFX_GraphStateData::LineCapSquare:
178                         cap = SkPaint::kSquare_Cap;
179                         break;
180                 default:
181                         cap = SkPaint::kButt_Cap;
182                         break;
183         }
184         SkPaint::Join join;
185         switch (pGraphState->m_LineJoin) {
186                 case CFX_GraphStateData::LineJoinRound:
187                         join = SkPaint::kRound_Join;
188                         break;
189                 case CFX_GraphStateData::LineJoinBevel:
190                         join = SkPaint::kBevel_Join;
191                         break;
192                 default:
193                         join = SkPaint::kMiter_Join;
194                         break;
195         }
196         FX_FIXFLOAT width = pGraphState->m_LineWidth*scale;
197         FX_FIXFLOAT unit = fix32_to_8(fixdiv_8_8_to_32(FIX8_ONE, (pObject2Device->GetXUnit() + pObject2Device->GetYUnit()) / 2));
198         if (width <= unit) width = unit;
199
200         if (pGraphState->m_DashArray == NULL) {
201                 SkStroke stroker;
202                 stroker.setCap(cap);
203                 stroker.setJoin(join);
204                 stroker.setMiterLimit(pGraphState->m_MiterLimit);
205                 stroker.setWidth(width);
206                 stroker.setDoFill(FALSE);
207                 stroker.strokePath(path_data, dstPathData);
208                 SkMatrix smatrix;
209                 smatrix.setAll(pObject2Device->a, pObject2Device->c, pObject2Device->e, pObject2Device->b, pObject2Device->d, pObject2Device->f, 0, 0, 1);
210                 dstPathData->transform(smatrix);
211         } else {
212                 int count = (pGraphState->m_DashCount+1)/2;
213                 SkScalar* intervals = FX_Alloc2D(SkScalar, count, sizeof(SkScalar));
214                 // Set dash pattern
215                 for (int i = 0; i < count; i ++) {
216                         FX_FIXFLOAT on = pGraphState->m_DashArray[i*2];
217                         if (on <= 0.000001f) on = FIX8_ONE/10;
218                         FX_FIXFLOAT off = i*2+1 == pGraphState->m_DashCount ? on :
219                                         pGraphState->m_DashArray[i*2+1];
220                         if (off < 0) off = 0;
221                         intervals[i*2]=on*scale;
222                         intervals[i*2+1]=off*scale;
223                 }
224                 SkDashPathEffect* pEffect = new SkDashPathEffect(intervals,count*2, pGraphState->m_DashPhase*scale);
225                 spaint.setPathEffect(pEffect)->unref();
226                 spaint.setStrokeWidth(width);
227                 spaint.setStrokeMiter(pGraphState->m_MiterLimit);
228                 spaint.setStrokeCap(cap);
229                 spaint.setStrokeJoin(join);
230                 spaint.getFillPath(path_data, dstPathData);
231                 SkMatrix smatrix;
232                 smatrix.setAll(pObject2Device->a, pObject2Device->c, pObject2Device->e, pObject2Device->b, pObject2Device->d, pObject2Device->f, 0, 0, 1);
233                 dstPathData->transform(smatrix);
234                 FX_Free(intervals);
235         }
236 }
237
238 CFX_SkiaDeviceDriver::CFX_SkiaDeviceDriver(CFX_DIBitmap* pBitmap, int dither_bits, FX_BOOL bRgbByteOrder, CFX_DIBitmap* pOriDevice, FX_BOOL bGroupKnockout)
239 {
240         m_pAggDriver = new CFX_AggDeviceDriver(pBitmap, dither_bits, bRgbByteOrder, pOriDevice, bGroupKnockout);
241 }
242 CFX_SkiaDeviceDriver::~CFX_SkiaDeviceDriver()
243 {
244     delete m_pAggDriver;
245 }
246 FX_BOOL CFX_SkiaDeviceDriver::DrawDeviceText(int nChars, const FXTEXT_CHARPOS* pCharPos, CFX_Font* pFont,
247                 CFX_FontCache* pCache, const CFX_AffineMatrix* pObject2Device, FX_FIXFLOAT font_size, FX_DWORD color,
248                 int alpha_flag, void* pIccTransform)
249 {
250         return m_pAggDriver->DrawDeviceText(nChars, pCharPos, pFont,pCache, pObject2Device, font_size, color,
251                 alpha_flag, pIccTransform);
252 }
253 int CFX_SkiaDeviceDriver::GetDeviceCaps(int caps_id)
254 {
255         return m_pAggDriver->GetDeviceCaps(caps_id);
256 }
257 void CFX_SkiaDeviceDriver::SaveState()
258 {
259         m_pAggDriver->SaveState();
260 }
261
262 void CFX_SkiaDeviceDriver::RestoreState(FX_BOOL bKeepSaved)
263 {
264         m_pAggDriver->RestoreState(bKeepSaved);
265 }
266 void CFX_SkiaDeviceDriver::SetClipMask(rasterizer_scanline_aa& rasterizer)
267 {
268         m_pAggDriver->SetClipMask(rasterizer);
269 }
270 void CFX_SkiaDeviceDriver::SetClipMask(SkPath& skPath, SkPaint* spaint)
271 {
272         SkIRect clip_box;
273         clip_box.set(0, 0, fix0_to_8(GetDeviceCaps(FXDC_PIXEL_WIDTH)), fix0_to_8(GetDeviceCaps(FXDC_PIXEL_HEIGHT)));
274         clip_box.intersect(m_pAggDriver->m_pClipRgn->GetBox().left, m_pAggDriver->m_pClipRgn->GetBox().top,
275                 m_pAggDriver->m_pClipRgn->GetBox().right, m_pAggDriver->m_pClipRgn->GetBox().bottom);
276
277         SkPath* pathPtr = &skPath;
278
279         SkRect path_rect = skPath.getBounds();
280
281         clip_box.intersect(FXSYS_floor(path_rect.fLeft), FXSYS_floor(path_rect.fTop), FXSYS_floor(path_rect.fRight)+1, FXSYS_floor(path_rect.fBottom)+1);
282         CFX_DIBitmapRef mask;
283         CFX_DIBitmap* pThisLayer = mask.New();
284         pThisLayer->Create(clip_box.width(), clip_box.height(), FXDIB_8bppMask);
285         pThisLayer->Clear(0);
286
287         CFX_SkiaA8Renderer render;
288         render.Init(pThisLayer, clip_box.fLeft, clip_box.fTop);
289
290         SkRasterClip rasterClip(clip_box);
291         SuperBlitter_skia::DrawPath(skPath, (SkBlitter*)&render, rasterClip, *spaint);
292
293         // Finally, we have got the mask that we need, intersect with current clip region
294         m_pAggDriver->m_pClipRgn->IntersectMaskF(clip_box.fLeft, clip_box.fTop, mask);
295
296 }
297 FX_BOOL CFX_SkiaDeviceDriver::SetClip_PathFill(const CFX_PathData* pPathData,   // path info
298                                                 const CFX_AffineMatrix* pObject2Device, // optional transformation
299                                                 int fill_mode   // fill mode, WINDING or ALTERNATE
300                                                 )
301 {
302         if (m_pAggDriver->m_pClipRgn == NULL)
303                 m_pAggDriver->m_pClipRgn = new CFX_ClipRgn(GetDeviceCaps(FXDC_PIXEL_WIDTH), GetDeviceCaps(FXDC_PIXEL_HEIGHT));
304
305         if (pPathData->GetPointCount() == 5 || pPathData->GetPointCount() == 4) {
306                 CFX_FloatRect rectf;
307                 if (pPathData->IsRect(pObject2Device, &rectf)) {
308                         rectf.Intersect(CFX_FloatRect(0, 0, (FX_FIXFLOAT)GetDeviceCaps(FXDC_PIXEL_WIDTH), (FX_FIXFLOAT)GetDeviceCaps(FXDC_PIXEL_HEIGHT)));
309                         FX_RECT rect = rectf.GetOutterRect();
310                         m_pAggDriver->m_pClipRgn->IntersectRect(rect);
311                         return TRUE;
312                 }
313         }
314         CSkia_PathData path_data;
315         path_data.BuildPath(pPathData, pObject2Device);
316         path_data.m_PathData.close();
317         path_data.m_PathData.setFillType((fill_mode&3) == FXFILL_WINDING? SkPath::kWinding_FillType:SkPath::kEvenOdd_FillType);
318
319         SkPaint spaint;
320         spaint.setColor(0xffffffff);
321         spaint.setAntiAlias(TRUE);
322         spaint.setStyle(SkPaint::kFill_Style);
323
324         SetClipMask(path_data.m_PathData, &spaint);
325
326         return TRUE;
327 }
328
329 FX_BOOL CFX_SkiaDeviceDriver::SetClip_PathStroke(const CFX_PathData* pPathData, // path info
330                                                 const CFX_AffineMatrix* pObject2Device, // optional transformation
331                                                 const CFX_GraphStateData* pGraphState   // graphic state, for pen attributes
332                                         )
333 {
334         if (m_pAggDriver->m_pClipRgn == NULL)
335                 m_pAggDriver->m_pClipRgn = new CFX_ClipRgn(GetDeviceCaps(FXDC_PIXEL_WIDTH), GetDeviceCaps(FXDC_PIXEL_HEIGHT));
336
337         // build path data
338         CSkia_PathData path_data;
339         path_data.BuildPath(pPathData, NULL);
340         path_data.m_PathData.setFillType(SkPath::kWinding_FillType);
341
342         SkPaint spaint;
343         spaint.setColor(0xffffffff);
344         spaint.setStyle(SkPaint::kStroke_Style);
345         spaint.setAntiAlias(TRUE);
346
347         SkPath dst_path;
348         SkRasterizeStroke(spaint, &dst_path, path_data.m_PathData, pObject2Device, pGraphState, 1, FALSE, 0);
349         spaint.setStyle(SkPaint::kFill_Style);
350         SetClipMask(dst_path, &spaint);
351
352         return TRUE;
353 }
354 FX_BOOL CFX_SkiaDeviceDriver::RenderRasterizer(rasterizer_scanline_aa& rasterizer, FX_DWORD color, FX_BOOL bFullCover, FX_BOOL bGroupKnockout,
355                                                                                           int alpha_flag, void* pIccTransform)
356 {
357         return m_pAggDriver->RenderRasterizer(rasterizer, color, bFullCover, bGroupKnockout,alpha_flag, pIccTransform);
358 }
359 FX_BOOL CFX_SkiaDeviceDriver::RenderRasterizerSkia(SkPath& skPath, const SkPaint& origPaint, SkIRect& rect, FX_DWORD color, FX_BOOL bFullCover, FX_BOOL bGroupKnockout,
360                                                         int alpha_flag, void* pIccTransform, FX_BOOL bFill)
361 {
362         CFX_DIBitmap* pt = bGroupKnockout?m_pAggDriver->GetBackDrop():NULL;
363         CFX_SkiaRenderer render;
364         if (!render.Init(m_pAggDriver->m_pBitmap, pt, m_pAggDriver->m_pClipRgn, color, bFullCover, m_pAggDriver->m_bRgbByteOrder, alpha_flag, pIccTransform))
365                 return FALSE;
366
367         SkRasterClip rasterClip(rect);
368         SuperBlitter_skia::DrawPath(skPath, (SkBlitter*)&render,  rasterClip, origPaint);
369
370         return TRUE;
371
372 }
373
374 FX_BOOL CFX_SkiaDeviceDriver::DrawPath(const CFX_PathData* pPathData,   // path info
375                                                 const CFX_AffineMatrix* pObject2Device, // optional transformation
376                                                 const CFX_GraphStateData* pGraphState,  // graphic state, for pen attributes
377                                                 FX_DWORD fill_color,                    // fill color
378                                                 FX_DWORD stroke_color,                  // stroke color
379                                                 int fill_mode,                                  // fill mode, WINDING or ALTERNATE. 0 for not filled
380                                                 int alpha_flag,
381                                                 void* pIccTransform
382                                                 )
383 {
384         if (GetBuffer() == NULL) return TRUE;
385         FOXIT_DEBUG1("CFX_SkiaDeviceDriver::DrawPath: entering");
386         SkIRect rect;
387         rect.set(0, 0, GetDeviceCaps(FXDC_PIXEL_WIDTH), GetDeviceCaps(FXDC_PIXEL_HEIGHT));
388         if ((fill_mode & 3) && fill_color) {
389                 // We have to transform before building path data, otherwise we'll have flatting problem
390                 // when we enlarge a small path (flatten before transformed)
391                 // TESTDOC: Bug #5115 - DS_S1Dimpact_lr.pdf
392                 // build path data
393                 CSkia_PathData path_data;
394                 path_data.BuildPath(pPathData, pObject2Device);
395                 //path_data.m_PathData.close();
396                 path_data.m_PathData.setFillType((fill_mode&3) == FXFILL_WINDING? SkPath::kWinding_FillType:SkPath::kEvenOdd_FillType);
397
398                 SkPaint spaint;
399                 spaint.setAntiAlias(TRUE);
400                 spaint.setStyle(SkPaint::kFill_Style);
401                 spaint.setColor(fill_color);
402                 if (!RenderRasterizerSkia(path_data.m_PathData, spaint, rect, fill_color, fill_mode & FXFILL_FULLCOVER, FALSE, alpha_flag, pIccTransform))
403                         return FALSE;
404         }
405
406         int stroke_alpha = FXGETFLAG_COLORTYPE(alpha_flag) ? FXGETFLAG_ALPHA_STROKE(alpha_flag) : FXARGB_A(stroke_color);
407
408         if (pGraphState && stroke_alpha) {
409                 // We split the matrix into two parts: first part doing the scaling, so we won't have the
410                 // flatness problem, second part doing the transformation, so we don't have stroking geo problem.
411                 // TESTDOC: Bug #5253 - test[1].pdf
412                 CFX_AffineMatrix matrix1, matrix2;
413                 if (pObject2Device) {
414                         matrix1.a = FXSYS_fabs(pObject2Device->a) > FXSYS_fabs(pObject2Device->b) ?
415                                         FXSYS_fabs(pObject2Device->a) : FXSYS_fabs(pObject2Device->b);
416                         matrix1.d = matrix1.a;//FXSYS_fabs(pObject2Device->c) > FXSYS_fabs(pObject2Device->d) ?
417                                         //pObject2Device->c : pObject2Device->d;
418                         matrix2.Set(pObject2Device->a/matrix1.a, pObject2Device->b/matrix1.a,
419                                         pObject2Device->c/matrix1.d, pObject2Device->d/matrix1.d,
420                                         pObject2Device->e, pObject2Device->f);
421                 }
422                 // build path data
423                 CSkia_PathData path_data;
424                 path_data.BuildPath(pPathData, &matrix1);
425                 path_data.m_PathData.setFillType(SkPath::kWinding_FillType);
426
427                 SkPaint spaint;
428                 spaint.setColor(stroke_color);
429                 spaint.setStyle(SkPaint::kStroke_Style);
430                 spaint.setAntiAlias(TRUE);
431                 SkPath dst_path;
432                 SkRasterizeStroke(spaint, &dst_path, path_data.m_PathData, &matrix2, pGraphState, matrix1.a, FALSE, 0);
433                 spaint.setStyle(SkPaint::kFill_Style);
434                 int fill_flag = FXGETFLAG_COLORTYPE(alpha_flag)<<8 | FXGETFLAG_ALPHA_STROKE(alpha_flag);
435
436                 if (!RenderRasterizerSkia(dst_path, spaint, rect, stroke_color, fill_mode & FXFILL_FULLCOVER, FALSE, fill_flag, pIccTransform, FALSE))
437                         return FALSE;
438
439         }
440
441         return TRUE;
442 }
443
444 FX_BOOL CFX_SkiaDeviceDriver::SetPixel(int x, int y, FX_DWORD color,
445                                                 int alpha_flag, void* pIccTransform)
446 {
447         return m_pAggDriver->SetPixel(x, y, color, alpha_flag, pIccTransform);
448 }
449
450 FX_BOOL CFX_SkiaDeviceDriver::FillRect(const FX_RECT* pRect, FX_DWORD fill_color, int alpha_flag, void* pIccTransform)
451 {
452         return m_pAggDriver->FillRect(pRect, fill_color, alpha_flag, pIccTransform);
453 }
454
455 FX_BOOL CFX_SkiaDeviceDriver::GetClipBox(FX_RECT* pRect)
456 {
457         return m_pAggDriver->GetClipBox(pRect);
458 }
459
460 FX_BOOL CFX_SkiaDeviceDriver::GetDIBits(CFX_DIBitmap* pBitmap, int left, int top, void* pIccTransform, FX_BOOL bDEdge)
461 {
462         return m_pAggDriver->GetDIBits(pBitmap, left, top, pIccTransform, bDEdge);
463 }
464
465 FX_BOOL CFX_SkiaDeviceDriver::SetDIBits(const CFX_DIBSource* pBitmap, FX_DWORD argb, const FX_RECT* pSrcRect, int left, int top, int blend_type,
466                                                                            int alpha_flag, void* pIccTransform)
467 {
468         return m_pAggDriver->SetDIBits(pBitmap, argb, pSrcRect, left, top, blend_type, alpha_flag, pIccTransform);
469 }
470
471 FX_BOOL CFX_SkiaDeviceDriver::StretchDIBits(const CFX_DIBSource* pSource, FX_DWORD argb, int dest_left, int dest_top,
472                                                         int dest_width, int dest_height, const FX_RECT* pClipRect, FX_DWORD flags,
473                                                         int alpha_flag, void* pIccTransform)
474 {
475         return m_pAggDriver->StretchDIBits(pSource, argb, dest_left, dest_top,
476                                                         dest_width, dest_height, pClipRect, flags,
477                                                         alpha_flag, pIccTransform);
478 }
479
480 FX_BOOL CFX_SkiaDeviceDriver::StartDIBits(const CFX_DIBSource* pSource, int bitmap_alpha, FX_DWORD argb,
481                                                 const CFX_AffineMatrix* pMatrix, FX_DWORD render_flags, void*& handle,
482                                                 int alpha_flag, void* pIccTransform)
483 {
484         return m_pAggDriver->StartDIBits(pSource, bitmap_alpha, argb,
485                                                 pMatrix, render_flags, handle, alpha_flag, pIccTransform);
486 }
487
488 FX_BOOL CFX_SkiaDeviceDriver::ContinueDIBits(void* pHandle, IFX_Pause* pPause)
489 {
490         return m_pAggDriver->ContinueDIBits(pHandle, pPause);
491 }
492
493 void CFX_SkiaDeviceDriver::CancelDIBits(void* pHandle)
494 {
495         m_pAggDriver->CancelDIBits(pHandle);
496 }
497
498 CFX_SkiaDevice::CFX_SkiaDevice()
499 {
500         m_bOwnedBitmap = FALSE;
501 }
502
503 FX_BOOL CFX_SkiaDevice::Attach(CFX_DIBitmap* pBitmap, int dither_bits, FX_BOOL bRgbByteOrder, CFX_DIBitmap* pOriDevice, FX_BOOL bGroupKnockout)
504 {
505         if (pBitmap == NULL)
506                 return FALSE;
507         SetBitmap(pBitmap);
508         CFX_SkiaDeviceDriver* pDriver = new CFX_SkiaDeviceDriver(pBitmap, dither_bits, bRgbByteOrder, pOriDevice, bGroupKnockout);
509         SetDeviceDriver(pDriver);
510         return TRUE;
511 }
512
513 FX_BOOL CFX_SkiaDevice::Create(int width, int height, FXDIB_Format format, int dither_bits, CFX_DIBitmap* pOriDevice)
514 {
515         m_bOwnedBitmap = TRUE;
516         CFX_DIBitmap* pBitmap = new CFX_DIBitmap;
517         if (!pBitmap->Create(width, height, format)) {
518                 delete pBitmap;
519                 return FALSE;
520         }
521         SetBitmap(pBitmap);
522         CFX_SkiaDeviceDriver* pDriver =  new CFX_SkiaDeviceDriver(pBitmap, dither_bits, FALSE, pOriDevice, FALSE);
523         SetDeviceDriver(pDriver);
524         return TRUE;
525 }
526 CFX_SkiaDevice::~CFX_SkiaDevice()
527 {
528         if (m_bOwnedBitmap && GetBitmap()) delete GetBitmap();
529 }
530
531 #endif