Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / platform / graphics / ReplayingCanvas.h
1 /*
2  * Copyright (C) 2013 Google Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met:
7  *
8  *     * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  *     * Redistributions in binary form must reproduce the above
11  * copyright notice, this list of conditions and the following disclaimer
12  * in the documentation and/or other materials provided with the
13  * distribution.
14  *     * Neither the name of Google Inc. nor the names of its
15  * contributors may be used to endorse or promote products derived from
16  * this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30
31 #ifndef ReplayingCanvas_h
32 #define ReplayingCanvas_h
33
34 #include "platform/graphics/InterceptingCanvas.h"
35 #include "third_party/skia/include/core/SkPictureRecorder.h"
36
37 namespace blink {
38
39 class ReplayingCanvas : public InterceptingCanvas, public SkDrawPictureCallback {
40 public:
41     ReplayingCanvas(SkBitmap, unsigned fromStep, unsigned toStep);
42     void resetStepCount();
43
44     virtual bool abortDrawing() OVERRIDE;
45
46     virtual void clear(SkColor) OVERRIDE;
47     virtual void drawPaint(const SkPaint&) OVERRIDE;
48     virtual void drawPoints(PointMode, size_t count, const SkPoint pts[], const SkPaint&) OVERRIDE;
49     virtual void drawRect(const SkRect&, const SkPaint&) OVERRIDE;
50     virtual void drawOval(const SkRect&, const SkPaint&) OVERRIDE;
51     virtual void drawRRect(const SkRRect&, const SkPaint&) OVERRIDE;
52     virtual void drawPath(const SkPath&, const SkPaint&) OVERRIDE;
53     virtual void drawBitmap(const SkBitmap&, SkScalar left, SkScalar top, const SkPaint* = 0) OVERRIDE;
54     virtual void drawBitmapRectToRect(const SkBitmap&, const SkRect* src, const SkRect& dst, const SkPaint*, DrawBitmapRectFlags) OVERRIDE;
55     virtual void drawBitmapMatrix(const SkBitmap&, const SkMatrix&, const SkPaint* = 0) OVERRIDE;
56     virtual void drawBitmapNine(const SkBitmap&, const SkIRect& center, const SkRect& dst, const SkPaint*) OVERRIDE;
57     virtual void drawSprite(const SkBitmap&, int left, int top, const SkPaint* = 0) OVERRIDE;
58     virtual void drawVertices(VertexMode vmode, int vertexCount, const SkPoint vertices[], const SkPoint texs[],
59         const SkColor colors[], SkXfermode* xmode, const uint16_t indices[], int indexCount, const SkPaint&) OVERRIDE;
60     virtual void drawData(const void* data, size_t length) OVERRIDE;
61     virtual void beginCommentGroup(const char* description) OVERRIDE;
62     virtual void addComment(const char* keyword, const char* value) OVERRIDE;
63     virtual void endCommentGroup() OVERRIDE;
64
65     virtual void onDrawDRRect(const SkRRect& outer, const SkRRect& inner, const SkPaint&) OVERRIDE;
66     virtual void onDrawText(const void* text, size_t byteLength, SkScalar x, SkScalar y, const SkPaint&) OVERRIDE;
67     virtual void onDrawPosText(const void* text, size_t byteLength, const SkPoint pos[], const SkPaint&) OVERRIDE;
68     virtual void onDrawPosTextH(const void* text, size_t byteLength, const SkScalar xpos[], SkScalar constY, const SkPaint&) OVERRIDE;
69     virtual void onDrawTextOnPath(const void* text, size_t byteLength, const SkPath&, const SkMatrix*, const SkPaint&) OVERRIDE;
70     virtual void onPushCull(const SkRect& cullRect) OVERRIDE;
71     virtual void onPopCull() OVERRIDE;
72     virtual void onClipRect(const SkRect&, SkRegion::Op, ClipEdgeStyle) OVERRIDE;
73     virtual void onClipRRect(const SkRRect&, SkRegion::Op, ClipEdgeStyle) OVERRIDE;
74     virtual void onClipPath(const SkPath&, SkRegion::Op, ClipEdgeStyle) OVERRIDE;
75     virtual void onClipRegion(const SkRegion&, SkRegion::Op) OVERRIDE;
76     virtual void onDrawPicture(const SkPicture*, const SkMatrix*, const SkPaint*);
77     virtual void didSetMatrix(const SkMatrix&) OVERRIDE;
78     virtual void didConcat(const SkMatrix&) OVERRIDE;
79     virtual void willSave() OVERRIDE;
80     SaveLayerStrategy willSaveLayer(const SkRect* bounds, const SkPaint*, SaveFlags) OVERRIDE;
81     virtual void willRestore() OVERRIDE;
82
83 private:
84     unsigned m_fromStep;
85     unsigned m_toStep;
86     unsigned m_stepCount;
87     bool m_abortDrawing;
88     void updateInRange();
89     friend class AutoReplayer;
90 };
91
92 } // namespace blink
93
94 #endif // ReplayingCanvas_h