summaryrefslogtreecommitdiffstats
path: root/Source/WebCore/platform/graphics/android/context/GraphicsOperation.h
blob: 927ff0a2aedf90738ec37764a81f6d5580ccd836 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
/*
 * Copyright 2012, The Android Open Source Project
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *  * Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *  * Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#ifndef GraphicsOperation_h
#define GraphicsOperation_h

#if USE(ACCELERATED_COMPOSITING)

#include "Color.h"
#include "FloatRect.h"
#include "GlyphBuffer.h"
#include "Font.h"
#include "IntRect.h"
#include "PlatformGraphicsContext.h"
#include "PlatformGraphicsContextSkia.h"
#include "SkCanvas.h"
#include "SkShader.h"
#include "SkRefCnt.h"

#include <utils/threads.h>
#include <wtf/text/CString.h>

#define TYPE_CASE(type) case type: return #type;

namespace WebCore {

namespace GraphicsOperation {

class Operation : public SkRefCnt {
public:
    typedef enum { UndefinedOperation
                  // State management
                  , BeginTransparencyLayerOperation
                  , EndTransparencyLayerOperation
                  , SaveOperation
                  , RestoreOperation
                  // State setters
                  , SetAlphaOperation
                  , SetCompositeOpOperation
                  , SetFillColorOperation
                  , SetFillShaderOperation
                  , SetLineCapOperation
                  , SetLineDashOperation
                  , SetLineJoinOperation
                  , SetMiterLimitOperation
                  , SetShadowOperation
                  , SetShouldAntialiasOperation
                  , SetStrokeColorOperation
                  , SetStrokeShaderOperation
                  , SetStrokeStyleOperation
                  , SetStrokeThicknessOperation
                  // Paint setup
                  , SetupPaintFillOperation
                  , SetupPaintShadowOperation
                  , SetupPaintStrokeOperation
                  // Matrix operations
                  , ConcatCTMOperation
                  , ScaleOperation
                  , RotateOperation
                  , TranslateOperation
                  // Clipping
                  , InnerRoundedRectClipOperation
                  , ClipOperation
                  , ClipPathOperation
                  , ClipOutOperation
                  , ClearRectOperation
                  // Drawing
                  , DrawBitmapPatternOperation
                  , DrawBitmapRectOperation
                  , DrawEllipseOperation
                  , DrawLineOperation
                  , DrawLineForTextOperation
                  , DrawLineForTextCheckingOperation
                  , DrawRectOperation
                  , FillPathOperation
                  , FillRectOperation
                  , FillRoundedRectOperation
                  , StrokeArcOperation
                  , StrokePathOperation
                  , StrokeRectOperation
                  // Text
                  , DrawComplexTextOperation
                  , DrawTextOperation
    } OperationType;

    virtual void apply(PlatformGraphicsContext* context) = 0;
    virtual ~Operation() {}
    virtual OperationType type() { return UndefinedOperation; }
    virtual String parameters() { return ""; }
    String name()
    {
        switch (type()) {
            TYPE_CASE(UndefinedOperation)
            // State management
            TYPE_CASE(BeginTransparencyLayerOperation)
            TYPE_CASE(EndTransparencyLayerOperation)
            TYPE_CASE(SaveOperation)
            TYPE_CASE(RestoreOperation)
            // State setters
            TYPE_CASE(SetAlphaOperation)
            TYPE_CASE(SetCompositeOpOperation)
            TYPE_CASE(SetFillColorOperation)
            TYPE_CASE(SetFillShaderOperation)
            TYPE_CASE(SetLineCapOperation)
            TYPE_CASE(SetLineDashOperation)
            TYPE_CASE(SetLineJoinOperation)
            TYPE_CASE(SetMiterLimitOperation)
            TYPE_CASE(SetShadowOperation)
            TYPE_CASE(SetShouldAntialiasOperation)
            TYPE_CASE(SetStrokeColorOperation)
            TYPE_CASE(SetStrokeShaderOperation)
            TYPE_CASE(SetStrokeStyleOperation)
            TYPE_CASE(SetStrokeThicknessOperation)
            // Paint setup
            TYPE_CASE(SetupPaintFillOperation)
            TYPE_CASE(SetupPaintShadowOperation)
            TYPE_CASE(SetupPaintStrokeOperation)
            // Matrix operations
            TYPE_CASE(ConcatCTMOperation)
            TYPE_CASE(ScaleOperation)
            TYPE_CASE(RotateOperation)
            TYPE_CASE(TranslateOperation)
            // Clipping
            TYPE_CASE(InnerRoundedRectClipOperation)
            TYPE_CASE(ClipOperation)
            TYPE_CASE(ClipPathOperation)
            TYPE_CASE(ClipOutOperation)
            TYPE_CASE(ClearRectOperation)
            // Drawing
            TYPE_CASE(DrawBitmapPatternOperation)
            TYPE_CASE(DrawBitmapRectOperation)
            TYPE_CASE(DrawEllipseOperation)
            TYPE_CASE(DrawLineOperation)
            TYPE_CASE(DrawLineForTextOperation)
            TYPE_CASE(DrawLineForTextCheckingOperation)
            TYPE_CASE(DrawRectOperation)
            TYPE_CASE(FillPathOperation)
            TYPE_CASE(FillRectOperation)
            TYPE_CASE(FillRoundedRectOperation)
            TYPE_CASE(StrokeArcOperation)
            TYPE_CASE(StrokePathOperation)
            TYPE_CASE(StrokeRectOperation)
            // Text
            TYPE_CASE(DrawComplexTextOperation)
            TYPE_CASE(DrawTextOperation)
        }
        return "Undefined";
    }
};

//**************************************
// State management
//**************************************

class BeginTransparencyLayer : public Operation {
public:
    BeginTransparencyLayer(const float opacity) : m_opacity(opacity) {}
    virtual void apply(PlatformGraphicsContext* context) { context->beginTransparencyLayer(m_opacity); }
    virtual OperationType type() { return BeginTransparencyLayerOperation; }
private:
    float m_opacity;
};
class EndTransparencyLayer : public Operation {
public:
    EndTransparencyLayer() {}
    virtual void apply(PlatformGraphicsContext* context) { context->endTransparencyLayer(); }
    virtual OperationType type() { return EndTransparencyLayerOperation; }
};
class Save : public Operation {
public:
    virtual void apply(PlatformGraphicsContext* context) { context->save(); }
    virtual OperationType type() { return SaveOperation; }
};
class Restore : public Operation {
public:
    virtual void apply(PlatformGraphicsContext* context) { context->restore(); }
    virtual OperationType type() { return RestoreOperation; }
};

//**************************************
// State setters
//**************************************

class SetAlpha : public Operation {
public:
    SetAlpha(const float alpha) : m_alpha(alpha) {}
    virtual void apply(PlatformGraphicsContext* context) { context->setAlpha(m_alpha); }
    virtual OperationType type() { return SetAlphaOperation; }
private:
    float m_alpha;
};

class SetCompositeOperation : public Operation {
public:
    SetCompositeOperation(CompositeOperator op) : m_operator(op) {}
    virtual void apply(PlatformGraphicsContext* context) {
        context->setCompositeOperation(m_operator);
    }
    virtual OperationType type() { return SetCompositeOpOperation; }
private:
    CompositeOperator m_operator;
};

class SetFillColor : public Operation {
public:
    SetFillColor(Color color) : m_color(color) {}
    virtual void apply(PlatformGraphicsContext* context) {
        context->setFillColor(m_color);
    }
    virtual OperationType type() { return SetFillColorOperation; }
    virtual String parameters() {
        return String::format("r: %d g: %d b: %d a: %d",
                              m_color.red(),
                              m_color.green(),
                              m_color.blue(),
                              m_color.alpha());
    }
private:
    Color m_color;
};

class SetFillShader : public Operation {
public:
    SetFillShader(SkShader* shader) : m_shader(shader) {
        SkSafeRef(m_shader);
    }
    ~SetFillShader() { SkSafeUnref(m_shader); }
    virtual void apply(PlatformGraphicsContext* context) {
        context->setFillShader(m_shader);
    }
    virtual OperationType type() { return SetFillShaderOperation; }
private:
    SkShader* m_shader;
};

class SetLineCap : public Operation {
public:
    SetLineCap(LineCap cap) : m_cap(cap) {}
    virtual void apply(PlatformGraphicsContext* context) {
        context->setLineCap(m_cap);
    }
    virtual OperationType type() { return SetLineCapOperation; }
private:
    LineCap m_cap;
};

class SetLineDash : public Operation {
public:
    SetLineDash(const DashArray& dashes, float dashOffset)
        : m_dashes(dashes), m_dashOffset(dashOffset) {}
    virtual void apply(PlatformGraphicsContext* context) {
        context->setLineDash(m_dashes, m_dashOffset);
    }
    virtual OperationType type() { return SetLineDashOperation; }
private:
    DashArray m_dashes;
    float m_dashOffset;
};

class SetLineJoin : public Operation {
public:
    SetLineJoin(LineJoin join) : m_join(join) {}
    virtual void apply(PlatformGraphicsContext* context) {
        context->setLineJoin(m_join);
    }
    virtual OperationType type() { return SetLineJoinOperation; }
private:
    LineJoin m_join;
};

class SetMiterLimit : public Operation {
public:
    SetMiterLimit(float limit) : m_limit(limit) {}
    virtual void apply(PlatformGraphicsContext* context) {
        context->setMiterLimit(m_limit);
    }
    virtual OperationType type() { return SetMiterLimitOperation; }
private:
    float m_limit;
};

class SetShadow : public Operation {
public:
    SetShadow(int radius, int dx, int dy, SkColor c)
        : m_radius(radius), m_dx(dx), m_dy(dy), m_color(c) {}
    virtual void apply(PlatformGraphicsContext* context) {
        context->setShadow(m_radius, m_dx, m_dy, m_color);
    }
    virtual OperationType type() { return SetShadowOperation; }
private:
    int m_radius;
    int m_dx;
    int m_dy;
    SkColor m_color;
};

class SetShouldAntialias : public Operation {
public:
    SetShouldAntialias(bool useAA) : m_useAA(useAA) {}
    virtual void apply(PlatformGraphicsContext* context) {
        context->setShouldAntialias(m_useAA);
    }
    virtual OperationType type() { return SetShouldAntialiasOperation; }
private:
    bool m_useAA;
};

class SetStrokeColor : public Operation {
public:
    SetStrokeColor(const Color& c) : m_color(c) {}
    virtual void apply(PlatformGraphicsContext* context) {
        context->setStrokeColor(m_color);
    }
    virtual OperationType type() { return SetStrokeColorOperation; }
private:
    Color m_color;
};

class SetStrokeShader : public Operation {
public:
    SetStrokeShader(SkShader* strokeShader) : m_shader(strokeShader) {
        SkSafeRef(m_shader);
    }
    ~SetStrokeShader() { SkSafeUnref(m_shader); }
    virtual void apply(PlatformGraphicsContext* context) {
        context->setStrokeShader(m_shader);
    }
    virtual OperationType type() { return SetStrokeShaderOperation; }
private:
    SkShader* m_shader;
};

class SetStrokeStyle : public Operation {
public:
    SetStrokeStyle(StrokeStyle style) : m_style(style) {}
    virtual void apply(PlatformGraphicsContext* context) {
        context->setStrokeStyle(m_style);
    }
    virtual OperationType type() { return SetStrokeStyleOperation; }
private:
    StrokeStyle m_style;
};

class SetStrokeThickness : public Operation {
public:
    SetStrokeThickness(float thickness) : m_thickness(thickness) {}
    virtual void apply(PlatformGraphicsContext* context) {
        context->setStrokeThickness(m_thickness);
    }
    virtual OperationType type() { return SetStrokeThicknessOperation; }
private:
    float m_thickness;
};

//**************************************
// Paint setup
//**************************************

class SetupPaintFill : public Operation {
public:
    SetupPaintFill(SkPaint* paint) : m_paint(*paint) {}
    virtual void apply(PlatformGraphicsContext* context) {
        context->setupPaintFill(&m_paint);
    }
    virtual OperationType type() { return SetupPaintFillOperation; }
private:
    SkPaint m_paint;
};

class SetupPaintShadow : public Operation {
public:
    SetupPaintShadow(SkPaint* paint, SkPoint* offset)
        : m_paint(*paint), m_offset(*offset) {}
    virtual void apply(PlatformGraphicsContext* context) {
        context->setupPaintShadow(&m_paint, &m_offset);
    }
    virtual OperationType type() { return SetupPaintShadowOperation; }
private:
    SkPaint m_paint;
    SkPoint m_offset;
};

class SetupPaintStroke : public Operation {
public:
    SetupPaintStroke(SkPaint* paint, SkRect* rect, bool isHLine)
        : m_paint(*paint), m_rect(*rect), m_isHLine(isHLine) {}
    virtual void apply(PlatformGraphicsContext* context) {
        context->setupPaintStroke(&m_paint, &m_rect, m_isHLine);
    }
    virtual OperationType type() { return SetupPaintStrokeOperation; }
private:
    SkPaint m_paint;
    SkRect m_rect;
    bool m_isHLine;
};

//**************************************
// Matrix operations
//**************************************

class ConcatCTM : public Operation {
public:
    ConcatCTM(const AffineTransform& affine) : m_matrix(affine) {}
    virtual void apply(PlatformGraphicsContext* context) {
        context->concatCTM(m_matrix);
    }
    virtual OperationType type() { return ConcatCTMOperation; }
private:
    AffineTransform m_matrix;
};

class Rotate : public Operation {
public:
    Rotate(float angleInRadians) : m_angle(angleInRadians) {}
    virtual void apply(PlatformGraphicsContext* context) {
        context->rotate(m_angle);
    }
    virtual OperationType type() { return RotateOperation; }
private:
    float m_angle;
};

class Scale : public Operation {
public:
    Scale(const FloatSize& size) : m_scale(size) {}
    virtual void apply(PlatformGraphicsContext* context) {
        context->scale(m_scale);
    }
    virtual OperationType type() { return ScaleOperation; }
private:
    FloatSize m_scale;
};

class Translate : public Operation {
public:
    Translate(float x, float y) : m_x(x), m_y(y) {}
    virtual void apply(PlatformGraphicsContext* context) {
        context->translate(m_x, m_y);
    }
    virtual OperationType type() { return TranslateOperation; }
private:
    float m_x;
    float m_y;
};

//**************************************
// Clipping
//**************************************

class InnerRoundedRectClip : public Operation {
public:
    InnerRoundedRectClip(const IntRect& rect, int thickness)
        : m_rect(rect), m_thickness(thickness) {}
    virtual void apply(PlatformGraphicsContext* context) {
        context->addInnerRoundedRectClip(m_rect, m_thickness);
    }
    virtual OperationType type() { return InnerRoundedRectClipOperation; }
private:
    IntRect m_rect;
    int m_thickness;
};

class Clip : public Operation {
public:
    Clip(const FloatRect& rect) : m_rect(rect) {}
    virtual void apply(PlatformGraphicsContext* context) {
        context->clip(m_rect);
    }
    virtual OperationType type() { return ClipOperation; }
private:
    const FloatRect m_rect;
};

class ClipPath : public Operation {
public:
    ClipPath(const Path& path, bool clipout = false)
        : m_path(path), m_clipOut(clipout), m_hasWindRule(false) {}
    void setWindRule(WindRule rule) { m_windRule = rule; m_hasWindRule = true; }
    virtual void apply(PlatformGraphicsContext* context) {
        if (m_hasWindRule) {
            context->clipPath(m_path, m_windRule);
            return;
        }
        if (m_clipOut)
            context->clipOut(m_path);
        else
            context->clip(m_path);
    }
    virtual OperationType type() { return ClipPathOperation; }
private:
    const Path m_path;
    bool m_clipOut;
    WindRule m_windRule;
    bool m_hasWindRule;
};

class ClipOut : public Operation {
public:
    ClipOut(const IntRect& rect) : m_rect(rect) {}
    virtual void apply(PlatformGraphicsContext* context) {
        context->clipOut(m_rect);
    }
    virtual OperationType type() { return ClipOutOperation; }
private:
    const IntRect m_rect;
};

class ClearRect : public Operation {
public:
    ClearRect(const FloatRect& rect) : m_rect(rect) {}
    virtual void apply(PlatformGraphicsContext* context) {
        context->clearRect(m_rect);
    }
    virtual OperationType type() { return ClearRectOperation; }
private:
    FloatRect m_rect;
};

//**************************************
// Drawing
//**************************************

class DrawBitmapPattern : public Operation {
public:
    DrawBitmapPattern(const SkBitmap& bitmap, const SkMatrix& matrix,
                      CompositeOperator op, const FloatRect& destRect)
        : m_bitmap(bitmap), m_matrix(matrix), m_operator(op), m_destRect(destRect) {}
    virtual void apply(PlatformGraphicsContext* context) {
        context->drawBitmapPattern(m_bitmap, m_matrix, m_operator, m_destRect);
    }
    virtual OperationType type() { return DrawBitmapPatternOperation; }
private:
    // TODO: use refcounted bitmap
    const SkBitmap m_bitmap;
    SkMatrix m_matrix;
    CompositeOperator m_operator;
    FloatRect m_destRect;
};

class DrawBitmapRect : public Operation {
public:
    DrawBitmapRect(const SkBitmap& bitmap, const SkIRect& srcR,
                   const SkRect& dstR, CompositeOperator op)
        : m_bitmap(bitmap), m_srcR(srcR), m_dstR(dstR), m_operator(op) {}
    virtual void apply(PlatformGraphicsContext* context) {
        context->drawBitmapRect(m_bitmap, &m_srcR, m_dstR, m_operator);
    }
    virtual OperationType type() { return DrawBitmapRectOperation; }
    virtual String parameters() {
        return String::format("%.2f, %.2f - %.2f x %.2f",
                 m_dstR.fLeft, m_dstR.fTop,
                 m_dstR.width(), m_dstR.height());
    }
private:
    const SkBitmap& m_bitmap;
    SkIRect m_srcR;
    SkRect m_dstR;
    CompositeOperator m_operator;
};

class DrawEllipse : public Operation {
public:
    DrawEllipse(const IntRect& rect) : m_rect(rect) {}
    virtual void apply(PlatformGraphicsContext* context) {
        context->drawEllipse(m_rect);
    }
    virtual OperationType type() { return DrawEllipseOperation; }
private:
    IntRect m_rect;
};

class DrawLine : public Operation {
public:
    DrawLine(const IntPoint& point1, const IntPoint& point2)
        : m_point1(point1), m_point2(point2) {}
    virtual void apply(PlatformGraphicsContext* context) {
        context->drawLine(m_point1, m_point2);
    }
    virtual OperationType type() { return DrawLineOperation; }
private:
    IntPoint m_point1;
    IntPoint m_point2;
};

class DrawLineForText : public Operation {
public:
    DrawLineForText(const FloatPoint& pt, float width)
        : m_point(pt), m_width(width) {}
    virtual void apply(PlatformGraphicsContext* context) {
        context->drawLineForText(m_point, m_width);
    }
    virtual OperationType type() { return DrawLineForTextOperation; }
private:
    FloatPoint m_point;
    float m_width;
};

class DrawLineForTextChecking : public Operation {
public:
    DrawLineForTextChecking(const FloatPoint& pt, float width,
                            GraphicsContext::TextCheckingLineStyle lineStyle)
        : m_point(pt), m_width(width), m_lineStyle(lineStyle) {}
    virtual void apply(PlatformGraphicsContext* context) {
        context->drawLineForTextChecking(m_point, m_width, m_lineStyle);
    }
    virtual OperationType type() { return DrawLineForTextCheckingOperation; }
private:
    FloatPoint m_point;
    float m_width;
    GraphicsContext::TextCheckingLineStyle m_lineStyle;
};

class DrawRect : public Operation {
public:
    DrawRect(const IntRect& rect) : m_rect(rect) {}
    virtual void apply(PlatformGraphicsContext* context) {
        context->drawRect(m_rect);
    }
    virtual OperationType type() { return DrawRectOperation; }
private:
    IntRect m_rect;
};

class FillPath : public Operation {
public:
    FillPath(const Path& pathToFill, WindRule fillRule)
        : m_path(pathToFill), m_fillRule(fillRule) {}
    virtual void apply(PlatformGraphicsContext* context) {
        context->fillPath(m_path, m_fillRule);
    }
    virtual OperationType type() { return FillPathOperation; }
private:
    Path m_path;
    WindRule m_fillRule;
};

class FillRect : public Operation {
public:
    FillRect(const FloatRect& rect) : m_rect(rect), m_hasColor(false) {}
    void setColor(Color c) { m_color = c; m_hasColor = true; }
    virtual void apply(PlatformGraphicsContext* context) {
        if (m_hasColor)
             context->fillRect(m_rect, m_color);
        else
             context->fillRect(m_rect);
    }
    virtual OperationType type() { return FillRectOperation; }
private:
    FloatRect m_rect;
    Color m_color;
    bool m_hasColor;
};

class FillRoundedRect : public Operation {
public:
    FillRoundedRect(const IntRect& rect,
                    const IntSize& topLeft,
                    const IntSize& topRight,
                    const IntSize& bottomLeft,
                    const IntSize& bottomRight,
                    const Color& color)
        : m_rect(rect)
        , m_topLeft(topLeft)
        , m_topRight(topRight)
        , m_bottomLeft(bottomLeft)
        , m_bottomRight(bottomRight)
        , m_color(color)
    {}
    virtual void apply(PlatformGraphicsContext* context) {
        context->fillRoundedRect(m_rect, m_topLeft, m_topRight,
                                 m_bottomLeft, m_bottomRight,
                                 m_color);
    }
    virtual OperationType type() { return FillRoundedRectOperation; }
private:
    IntRect m_rect;
    IntSize m_topLeft;
    IntSize m_topRight;
    IntSize m_bottomLeft;
    IntSize m_bottomRight;
    Color m_color;
};

class StrokeArc : public Operation {
public:
    StrokeArc(const IntRect& r, int startAngle, int angleSpan)
        : m_rect(r)
        , m_startAngle(startAngle)
        , m_angleSpan(angleSpan)
    {}
    virtual void apply(PlatformGraphicsContext* context) {
        context->strokeArc(m_rect, m_startAngle, m_angleSpan);
    }
    virtual OperationType type() { return StrokeArcOperation; }
private:
    IntRect m_rect;
    int m_startAngle;
    int m_angleSpan;
};

class StrokePath : public Operation {
public:
    StrokePath(const Path& path) : m_path(path) {}
    virtual void apply(PlatformGraphicsContext* context) {
        context->strokePath(m_path);
    }
    virtual OperationType type() { return StrokePathOperation; }
private:
    Path m_path;
};


class StrokeRect : public Operation {
public:
    StrokeRect(const FloatRect& rect, float lineWidth)
        : m_rect(rect), m_lineWidth(lineWidth) {}
    virtual void apply(PlatformGraphicsContext* context) {
        context->strokeRect(m_rect, m_lineWidth);
    }
    virtual OperationType type() { return StrokeRectOperation; }
private:
    FloatRect m_rect;
    float m_lineWidth;
};

//**************************************
// Text
//**************************************

class DrawComplexText : public Operation {
public:
    DrawComplexText(SkPicture* picture) : m_picture(picture) {
        SkSafeRef(m_picture);
    }
    ~DrawComplexText() { SkSafeUnref(m_picture); }
    virtual void apply(PlatformGraphicsContext* context) {
        if (!context->getCanvas())
            return;
        context->getCanvas()->drawPicture(*m_picture);
    }
    virtual OperationType type() { return DrawComplexTextOperation; }
private:
    SkPicture* m_picture;
};

class DrawText : public Operation {
public:
    DrawText(const Font* font, const SimpleFontData* simpleFont,
             const GlyphBuffer& glyphBuffer,
             int from, int numGlyphs, const FloatPoint& point)
        : m_font(font), m_simpleFont(simpleFont)
        , m_glyphBuffer(glyphBuffer), m_from(from)
        , m_numGlyphs(numGlyphs), m_point(point) {

        SkPicture* picture = new SkPicture();
        SkCanvas* canvas = picture->beginRecording(0, 0, 0);
        PlatformGraphicsContextSkia platformContext(canvas);
        GraphicsContext graphicsContext(&platformContext);
        m_font->drawGlyphs(&graphicsContext, m_simpleFont,
                           m_glyphBuffer, m_from, m_numGlyphs, m_point);
        picture->endRecording();
        m_picture = picture;
    }
    ~DrawText() { SkSafeUnref(m_picture); }
    virtual void apply(PlatformGraphicsContext* context) {
        if (!context->getCanvas())
            return;
        context->getCanvas()->drawPicture(*m_picture);
    }
    virtual OperationType type() { return DrawTextOperation; }
private:
    SkPicture* m_picture;
    const Font* m_font;
    const SimpleFontData* m_simpleFont;
    const GlyphBuffer m_glyphBuffer;
    int m_from;
    int m_numGlyphs;
    const FloatPoint m_point;
};

}

}

#endif // USE(ACCELERATED_COMPOSITING)

#endif // GraphicsOperation_h