1 : /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 : * ***** BEGIN LICENSE BLOCK *****
3 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 : *
5 : * The contents of this file are subject to the Mozilla Public License Version
6 : * 1.1 (the "License"); you may not use this file except in compliance with
7 : * the License. You may obtain a copy of the License at
8 : * http://www.mozilla.org/MPL/
9 : *
10 : * Software distributed under the License is distributed on an "AS IS" basis,
11 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 : * for the specific language governing rights and limitations under the
13 : * License.
14 : *
15 : * The Original Code is Mozilla Corporation code.
16 : *
17 : * The Initial Developer of the Original Code is Mozilla Foundation.
18 : * Portions created by the Initial Developer are Copyright (C) 2009
19 : * the Initial Developer. All Rights Reserved.
20 : *
21 : * Contributor(s):
22 : * Matt Woodrow <mwoodrow@mozilla.com>
23 : *
24 : * Alternatively, the contents of this file may be used under the terms of
25 : * either the GNU General Public License Version 2 or later (the "GPL"), or
26 : * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 : * in which case the provisions of the GPL or the LGPL are applicable instead
28 : * of those above. If you wish to allow use of your version of this file only
29 : * under the terms of either the GPL or the LGPL, and not to allow others to
30 : * use your version of this file under the terms of the MPL, indicate your
31 : * decision by deleting the provisions above and replace them with the notice
32 : * and other provisions required by the GPL or the LGPL. If you do not delete
33 : * the provisions above, a recipient may use your version of this file under
34 : * the terms of any one of the MPL, the GPL or the LGPL.
35 : *
36 : * ***** END LICENSE BLOCK ***** */
37 :
38 : #pragma once
39 :
40 : #include "skia/SkCanvas.h"
41 : #include "2D.h"
42 : #include "Rect.h"
43 : #include "PathSkia.h"
44 : #include <sstream>
45 : #include <vector>
46 : using namespace std;
47 : #include "gfxImageSurface.h"
48 :
49 : namespace mozilla {
50 : namespace gfx {
51 :
52 : class SourceSurfaceSkia;
53 :
54 : class DrawTargetSkia : public DrawTarget
55 : {
56 : public:
57 : DrawTargetSkia();
58 : virtual ~DrawTargetSkia();
59 :
60 0 : virtual BackendType GetType() const { return BACKEND_SKIA; }
61 : virtual TemporaryRef<SourceSurface> Snapshot();
62 0 : virtual IntSize GetSize() { return mSize; }
63 : virtual void Flush();
64 : virtual void DrawSurface(SourceSurface *aSurface,
65 : const Rect &aDest,
66 : const Rect &aSource,
67 : const DrawSurfaceOptions &aSurfOptions = DrawSurfaceOptions(),
68 : const DrawOptions &aOptions = DrawOptions());
69 : virtual void DrawSurfaceWithShadow(SourceSurface *aSurface,
70 : const Point &aDest,
71 : const Color &aColor,
72 : const Point &aOffset,
73 : Float aSigma,
74 : CompositionOp aOperator);
75 : virtual void ClearRect(const Rect &aRect);
76 : virtual void CopySurface(SourceSurface *aSurface,
77 : const IntRect &aSourceRect,
78 : const IntPoint &aDestination);
79 : virtual void FillRect(const Rect &aRect,
80 : const Pattern &aPattern,
81 : const DrawOptions &aOptions = DrawOptions());
82 : virtual void StrokeRect(const Rect &aRect,
83 : const Pattern &aPattern,
84 : const StrokeOptions &aStrokeOptions = StrokeOptions(),
85 : const DrawOptions &aOptions = DrawOptions());
86 : virtual void StrokeLine(const Point &aStart,
87 : const Point &aEnd,
88 : const Pattern &aPattern,
89 : const StrokeOptions &aStrokeOptions = StrokeOptions(),
90 : const DrawOptions &aOptions = DrawOptions());
91 : virtual void Stroke(const Path *aPath,
92 : const Pattern &aPattern,
93 : const StrokeOptions &aStrokeOptions = StrokeOptions(),
94 : const DrawOptions &aOptions = DrawOptions());
95 : virtual void Fill(const Path *aPath,
96 : const Pattern &aPattern,
97 : const DrawOptions &aOptions = DrawOptions());
98 : virtual void FillGlyphs(ScaledFont *aFont,
99 : const GlyphBuffer &aBuffer,
100 : const Pattern &aPattern,
101 : const DrawOptions &aOptions = DrawOptions());
102 : virtual void Mask(const Pattern &aSource,
103 : const Pattern &aMask,
104 : const DrawOptions &aOptions = DrawOptions());
105 : virtual void PushClip(const Path *aPath);
106 : virtual void PushClipRect(const Rect& aRect);
107 : virtual void PopClip();
108 : virtual TemporaryRef<SourceSurface> CreateSourceSurfaceFromData(unsigned char *aData,
109 : const IntSize &aSize,
110 : int32_t aStride,
111 : SurfaceFormat aFormat) const;
112 : virtual TemporaryRef<SourceSurface> OptimizeSourceSurface(SourceSurface *aSurface) const;
113 : virtual TemporaryRef<SourceSurface>
114 : CreateSourceSurfaceFromNativeSurface(const NativeSurface &aSurface) const;
115 : virtual TemporaryRef<DrawTarget>
116 : CreateSimilarDrawTarget(const IntSize &aSize, SurfaceFormat aFormat) const;
117 : virtual TemporaryRef<PathBuilder> CreatePathBuilder(FillRule aFillRule = FILL_WINDING) const;
118 : virtual TemporaryRef<GradientStops> CreateGradientStops(GradientStop *aStops, uint32_t aNumStops, ExtendMode aExtendMode = EXTEND_CLAMP) const;
119 : virtual void SetTransform(const Matrix &aTransform);
120 :
121 : bool Init(const IntSize &aSize, SurfaceFormat aFormat);
122 : void Init(unsigned char* aData, const IntSize &aSize, int32_t aStride, SurfaceFormat aFormat);
123 :
124 0 : operator std::string() const {
125 0 : std::stringstream stream;
126 0 : stream << "DrawTargetSkia(" << this << ")";
127 0 : return stream.str();
128 : }
129 : private:
130 : friend class SourceSurfaceSkia;
131 : void AppendSnapshot(SourceSurfaceSkia* aSnapshot);
132 : void RemoveSnapshot(SourceSurfaceSkia* aSnapshot);
133 :
134 : void MarkChanged();
135 :
136 : IntSize mSize;
137 : SkBitmap mBitmap;
138 : SkRefPtr<SkCanvas> mCanvas;
139 : SkRefPtr<SkDevice> mDevice;
140 : nsRefPtr<gfxImageSurface> mImageSurface;
141 : vector<SourceSurfaceSkia*> mSnapshots;
142 : };
143 :
144 : }
145 : }
|