1/*
2 * Copyright (C) 2011 Igalia S.L.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 *    notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 *    notice, this list of conditions and the following disclaimer in the
11 *    documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26#ifndef PlatformContextCairo_h
27#define PlatformContextCairo_h
28
29#include "GraphicsContext.h"
30#include "RefPtrCairo.h"
31#include "ShadowBlur.h"
32
33namespace WebCore {
34
35struct GraphicsContextState;
36
37// Much like PlatformContextSkia in the Skia port, this class holds information that
38// would normally be private to GraphicsContext, except that we want to allow access
39// to it in Font and Image code. This allows us to separate the concerns of Cairo-specific
40// code from the platform-independent GraphicsContext.
41
42class PlatformContextCairo {
43    WTF_MAKE_NONCOPYABLE(PlatformContextCairo);
44public:
45    PlatformContextCairo(cairo_t*);
46    ~PlatformContextCairo();
47
48    cairo_t* cr() { return m_cr.get(); }
49    void setCr(cairo_t* cr) { m_cr = cr; }
50
51    ShadowBlur& shadowBlur() { return m_shadowBlur; }
52
53    void save();
54    void restore();
55    void setGlobalAlpha(float);
56    float globalAlpha() const;
57
58    void pushImageMask(cairo_surface_t*, const FloatRect&);
59    void drawSurfaceToContext(cairo_surface_t*, const FloatRect& destRect, const FloatRect& srcRect, GraphicsContext*);
60
61    void setImageInterpolationQuality(InterpolationQuality);
62    InterpolationQuality imageInterpolationQuality() const;
63
64    enum PatternAdjustment { NoAdjustment, AdjustPatternForGlobalAlpha };
65    void prepareForFilling(const GraphicsContextState&, PatternAdjustment);
66
67    enum AlphaPreservation { DoNotPreserveAlpha, PreserveAlpha };
68    void prepareForStroking(const GraphicsContextState&, AlphaPreservation = PreserveAlpha);
69
70private:
71    void clipForPatternFilling(const GraphicsContextState&);
72
73    RefPtr<cairo_t> m_cr;
74
75    class State;
76    State* m_state;
77    WTF::Vector<State> m_stateStack;
78
79    // GraphicsContext is responsible for managing the state of the ShadowBlur,
80    // so it does not need to be on the state stack.
81    ShadowBlur m_shadowBlur;
82
83};
84
85} // namespace WebCore
86
87#endif // PlatformContextCairo_h
88