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