- a/WebCore/ChangeLog +21 lines
Lines 1-3 a/WebCore/ChangeLog_sec1
1
2010-09-27  Alejandro G. Castro  <alex@igalia.com>
2
3
        Reviewed by NOBODY (OOPS!).
4
5
        [cairo] Move some cairo functions to the CairoUtilities
6
        https://bugs.webkit.org/show_bug.cgi?id=47076
7
8
        Moved some cairo functions to the CairoUtilities so we can use
9
        them outside GraphicsContextCairo.
10
11
        * platform/graphics/cairo/CairoUtilities.cpp:
12
        (WebCore::appendPathToCairoContext):
13
        (WebCore::setPathOnCairoContext):
14
        (WebCore::appendWebCorePathToCairoContext):
15
        (WebCore::toCairoOperator):
16
        (WebCore::drawPatternCairo):
17
        * platform/graphics/cairo/CairoUtilities.h:
18
        * platform/graphics/cairo/GraphicsContextCairo.cpp:
19
        * platform/graphics/cairo/ImageCairo.cpp:
20
        (WebCore::Image::drawPattern):
21
1
2010-10-03  Kent Tamura  <tkent@chromium.org>
22
2010-10-03  Kent Tamura  <tkent@chromium.org>
2
23
3
        Unreviewed, build fix for r68996.
24
        Unreviewed, build fix for r68996.
- a/WebCore/platform/graphics/cairo/CairoUtilities.cpp -1 / +102 lines
Lines 26-33 a/WebCore/platform/graphics/cairo/CairoUtilities.cpp_sec1
26
#include "config.h"
26
#include "config.h"
27
#include "CairoUtilities.h"
27
#include "CairoUtilities.h"
28
28
29
#include "AffineTransform.h"
30
#include "CairoPath.h"
29
#include "Color.h"
31
#include "Color.h"
30
#include <cairo.h>
32
#include "FloatPoint.h"
33
#include "FloatRect.h"
34
#include "IntRect.h"
35
#include "Path.h"
36
#include "PlatformRefPtrCairo.h"
31
#include <wtf/Vector.h>
37
#include <wtf/Vector.h>
32
38
33
namespace WebCore {
39
namespace WebCore {
Lines 56-59 void setSourceRGBAFromColor(cairo_t* context, const Color& color) a/WebCore/platform/graphics/cairo/CairoUtilities.cpp_sec2
56
    cairo_set_source_rgba(context, red, green, blue, alpha);
62
    cairo_set_source_rgba(context, red, green, blue, alpha);
57
}
63
}
58
64
65
void appendPathToCairoContext(cairo_t* to, cairo_t* from)
66
{
67
    OwnPtr<cairo_path_t> cairoPath(cairo_copy_path(from));
68
    cairo_append_path(to, cairoPath.get());
69
}
70
71
// We apply the pending path built via addPath to the Cairo context
72
// lazily. This prevents interaction between the path and other routines
73
// such as fillRect.
74
void setPathOnCairoContext(cairo_t* to, cairo_t* from)
75
{
76
    cairo_new_path(to);
77
    appendPathToCairoContext(to, from);
78
}
79
80
void appendWebCorePathToCairoContext(cairo_t* context, const Path& path)
81
{
82
    appendPathToCairoContext(context, path.platformPath()->context());
83
}
84
85
cairo_operator_t toCairoOperator(CompositeOperator op)
86
{
87
    switch (op) {
88
    case CompositeClear:
89
        return CAIRO_OPERATOR_CLEAR;
90
    case CompositeCopy:
91
        return CAIRO_OPERATOR_SOURCE;
92
    case CompositeSourceOver:
93
        return CAIRO_OPERATOR_OVER;
94
    case CompositeSourceIn:
95
        return CAIRO_OPERATOR_IN;
96
    case CompositeSourceOut:
97
        return CAIRO_OPERATOR_OUT;
98
    case CompositeSourceAtop:
99
        return CAIRO_OPERATOR_ATOP;
100
    case CompositeDestinationOver:
101
        return CAIRO_OPERATOR_DEST_OVER;
102
    case CompositeDestinationIn:
103
        return CAIRO_OPERATOR_DEST_IN;
104
    case CompositeDestinationOut:
105
        return CAIRO_OPERATOR_DEST_OUT;
106
    case CompositeDestinationAtop:
107
        return CAIRO_OPERATOR_DEST_ATOP;
108
    case CompositeXOR:
109
        return CAIRO_OPERATOR_XOR;
110
    case CompositePlusDarker:
111
        return CAIRO_OPERATOR_SATURATE;
112
    case CompositeHighlight:
113
        // There is no Cairo equivalent for CompositeHighlight.
114
        return CAIRO_OPERATOR_OVER;
115
    case CompositePlusLighter:
116
        return CAIRO_OPERATOR_ADD;
117
    default:
118
        return CAIRO_OPERATOR_SOURCE;
119
    }
120
}
121
122
void drawPatternCairo(cairo_t* cr, cairo_surface_t* image, const IntSize& imageSize, const FloatRect& tileRect,
123
                      const AffineTransform& patternTransform, const FloatPoint& phase, cairo_operator_t op, const FloatRect& destRect)
124
{
125
    // Avoid NaN
126
    if (!isfinite(phase.x()) || !isfinite(phase.y()))
127
       return;
128
129
    cairo_save(cr);
130
131
    PlatformRefPtr<cairo_surface_t> clippedImageSurface = 0;
132
    if (tileRect.size() != imageSize) {
133
        IntRect imageRect = enclosingIntRect(tileRect);
134
        clippedImageSurface = adoptPlatformRef(cairo_image_surface_create(CAIRO_FORMAT_ARGB32, imageRect.width(), imageRect.height()));
135
        PlatformRefPtr<cairo_t> clippedImageContext(cairo_create(clippedImageSurface.get()));
136
        cairo_set_source_surface(clippedImageContext.get(), image, -tileRect.x(), -tileRect.y());
137
        cairo_paint(clippedImageContext.get());
138
        image = clippedImageSurface.get();
139
    }
140
141
    cairo_pattern_t* pattern = cairo_pattern_create_for_surface(image);
142
    cairo_pattern_set_extend(pattern, CAIRO_EXTEND_REPEAT);
143
144
    cairo_matrix_t patternMatrix = cairo_matrix_t(patternTransform);
145
    cairo_matrix_t phaseMatrix = {1, 0, 0, 1, phase.x() + tileRect.x() * patternTransform.a(), phase.y() + tileRect.y() * patternTransform.d()};
146
    cairo_matrix_t combined;
147
    cairo_matrix_multiply(&combined, &patternMatrix, &phaseMatrix);
148
    cairo_matrix_invert(&combined);
149
    cairo_pattern_set_matrix(pattern, &combined);
150
151
    cairo_set_operator(cr, op);
152
    cairo_set_source(cr, pattern);
153
    cairo_pattern_destroy(pattern);
154
    cairo_rectangle(cr, destRect.x(), destRect.y(), destRect.width(), destRect.height());
155
    cairo_fill(cr);
156
157
    cairo_restore(cr);
158
}
159
59
} // namespace WebCore
160
} // namespace WebCore
- a/WebCore/platform/graphics/cairo/CairoUtilities.h -1 / +13 lines
Lines 26-38 a/WebCore/platform/graphics/cairo/CairoUtilities.h_sec1
26
#ifndef CairoUtilities_h
26
#ifndef CairoUtilities_h
27
#define CairoUtilities_h
27
#define CairoUtilities_h
28
28
29
typedef struct _cairo cairo_t;
29
#include <GraphicsTypes.h>
30
#include <cairo.h>
30
31
31
namespace WebCore {
32
namespace WebCore {
33
class AffineTransform;
32
class Color;
34
class Color;
35
class FloatRect;
36
class FloatPoint;
37
class IntSize;
38
class Path;
33
39
34
void copyContextProperties(cairo_t* srcCr, cairo_t* dstCr);
40
void copyContextProperties(cairo_t* srcCr, cairo_t* dstCr);
35
void setSourceRGBAFromColor(cairo_t*, const Color&);
41
void setSourceRGBAFromColor(cairo_t*, const Color&);
42
void appendPathToCairoContext(cairo_t* to, cairo_t* from);
43
void setPathOnCairoContext(cairo_t* to, cairo_t* from);
44
void appendWebCorePathToCairoContext(cairo_t* context, const Path& path);
45
cairo_operator_t toCairoOperator(CompositeOperator op);
46
void drawPatternCairo(cairo_t* cr, cairo_surface_t* image, const IntSize& imageSize, const FloatRect& tileRect,
47
                      const AffineTransform& patternTransform, const FloatPoint& phase, cairo_operator_t op, const FloatRect& destRect);
36
48
37
} // namespace WebCore
49
} // namespace WebCore
38
50
- a/WebCore/platform/graphics/cairo/GraphicsContextCairo.cpp -57 lines
Lines 132-157 static inline void fillRectSourceOver(cairo_t* cr, const FloatRect& rect, const a/WebCore/platform/graphics/cairo/GraphicsContextCairo.cpp_sec1
132
    cairo_fill(cr);
132
    cairo_fill(cr);
133
}
133
}
134
134
135
static void appendPathToCairoContext(cairo_t* to, cairo_t* from)
136
{
137
    OwnPtr<cairo_path_t> cairoPath(cairo_copy_path(from));
138
    cairo_append_path(to, cairoPath.get());
139
}
140
141
// We apply the pending path built via addPath to the Cairo context
142
// lazily. This prevents interaction between the path and other routines
143
// such as fillRect.
144
static void setPathOnCairoContext(cairo_t* to, cairo_t* from)
145
{
146
    cairo_new_path(to);
147
    appendPathToCairoContext(to, from);
148
}
149
150
static void appendWebCorePathToCairoContext(cairo_t* context, const Path& path)
151
{
152
    appendPathToCairoContext(context, path.platformPath()->context());
153
}
154
155
static void addConvexPolygonToContext(cairo_t* context, size_t numPoints, const FloatPoint* points)
135
static void addConvexPolygonToContext(cairo_t* context, size_t numPoints, const FloatPoint* points)
156
{
136
{
157
    cairo_move_to(context, points[0].x(), points[0].y());
137
    cairo_move_to(context, points[0].x(), points[0].y());
Lines 1095-1137 float GraphicsContext::getAlpha() a/WebCore/platform/graphics/cairo/GraphicsContextCairo.cpp_sec2
1095
    return m_common->state.globalAlpha;
1075
    return m_common->state.globalAlpha;
1096
}
1076
}
1097
1077
1098
static inline cairo_operator_t toCairoOperator(CompositeOperator op)
1099
{
1100
    switch (op) {
1101
    case CompositeClear:
1102
        return CAIRO_OPERATOR_CLEAR;
1103
    case CompositeCopy:
1104
        return CAIRO_OPERATOR_SOURCE;
1105
    case CompositeSourceOver:
1106
        return CAIRO_OPERATOR_OVER;
1107
    case CompositeSourceIn:
1108
        return CAIRO_OPERATOR_IN;
1109
    case CompositeSourceOut:
1110
        return CAIRO_OPERATOR_OUT;
1111
    case CompositeSourceAtop:
1112
        return CAIRO_OPERATOR_ATOP;
1113
    case CompositeDestinationOver:
1114
        return CAIRO_OPERATOR_DEST_OVER;
1115
    case CompositeDestinationIn:
1116
        return CAIRO_OPERATOR_DEST_IN;
1117
    case CompositeDestinationOut:
1118
        return CAIRO_OPERATOR_DEST_OUT;
1119
    case CompositeDestinationAtop:
1120
        return CAIRO_OPERATOR_DEST_ATOP;
1121
    case CompositeXOR:
1122
        return CAIRO_OPERATOR_XOR;
1123
    case CompositePlusDarker:
1124
        return CAIRO_OPERATOR_SATURATE;
1125
    case CompositeHighlight:
1126
        // There is no Cairo equivalent for CompositeHighlight.
1127
        return CAIRO_OPERATOR_OVER;
1128
    case CompositePlusLighter:
1129
        return CAIRO_OPERATOR_ADD;
1130
    default:
1131
        return CAIRO_OPERATOR_SOURCE;
1132
    }
1133
}
1134
1135
void GraphicsContext::setCompositeOperation(CompositeOperator op)
1078
void GraphicsContext::setCompositeOperation(CompositeOperator op)
1136
{
1079
{
1137
    if (paintingDisabled())
1080
    if (paintingDisabled())
- a/WebCore/platform/graphics/cairo/ImageCairo.cpp -33 / +3 lines
Lines 31-36 a/WebCore/platform/graphics/cairo/ImageCairo.cpp_sec1
31
#if PLATFORM(CAIRO)
31
#if PLATFORM(CAIRO)
32
32
33
#include "AffineTransform.h"
33
#include "AffineTransform.h"
34
#include "CairoUtilities.h"
34
#include "Color.h"
35
#include "Color.h"
35
#include "FloatRect.h"
36
#include "FloatRect.h"
36
#include "PlatformRefPtrCairo.h"
37
#include "PlatformRefPtrCairo.h"
Lines 172-217 void BitmapImage::draw(GraphicsContext* context, const FloatRect& dst, const Flo a/WebCore/platform/graphics/cairo/ImageCairo.cpp_sec2
172
}
173
}
173
174
174
void Image::drawPattern(GraphicsContext* context, const FloatRect& tileRect, const AffineTransform& patternTransform,
175
void Image::drawPattern(GraphicsContext* context, const FloatRect& tileRect, const AffineTransform& patternTransform,
175
                        const FloatPoint& phase, ColorSpace, CompositeOperator op, const FloatRect& destRect)
176
                        const FloatPoint& phase, ColorSpace colorSpace, CompositeOperator op, const FloatRect& destRect)
176
{
177
{
177
    cairo_surface_t* image = nativeImageForCurrentFrame();
178
    cairo_surface_t* image = nativeImageForCurrentFrame();
178
    if (!image) // If it's too early we won't have an image yet.
179
    if (!image) // If it's too early we won't have an image yet.
179
        return;
180
        return;
180
181
181
    // Avoid NaN
182
    if (!isfinite(phase.x()) || !isfinite(phase.y()))
183
       return;
184
185
    cairo_t* cr = context->platformContext();
182
    cairo_t* cr = context->platformContext();
186
    context->save();
187
188
    PlatformRefPtr<cairo_surface_t> clippedImageSurface = 0;
189
    if (tileRect.size() != size()) {
190
        IntRect imageSize = enclosingIntRect(tileRect);
191
        clippedImageSurface = adoptPlatformRef(cairo_image_surface_create(CAIRO_FORMAT_ARGB32, imageSize.width(), imageSize.height()));
192
        PlatformRefPtr<cairo_t> clippedImageContext(cairo_create(clippedImageSurface.get()));
193
        cairo_set_source_surface(clippedImageContext.get(), image, -tileRect.x(), -tileRect.y());
194
        cairo_paint(clippedImageContext.get());
195
        image = clippedImageSurface.get();
196
    }
197
198
    cairo_pattern_t* pattern = cairo_pattern_create_for_surface(image);
199
    cairo_pattern_set_extend(pattern, CAIRO_EXTEND_REPEAT);
200
183
201
    cairo_matrix_t pattern_matrix = cairo_matrix_t(patternTransform);
184
    drawPatternCairo(cr, image, size(), tileRect, patternTransform, phase, toCairoOperator(op), destRect);
202
    cairo_matrix_t phase_matrix = {1, 0, 0, 1, phase.x() + tileRect.x() * patternTransform.a(), phase.y() + tileRect.y() * patternTransform.d()};
203
    cairo_matrix_t combined;
204
    cairo_matrix_multiply(&combined, &pattern_matrix, &phase_matrix);
205
    cairo_matrix_invert(&combined);
206
    cairo_pattern_set_matrix(pattern, &combined);
207
208
    context->setCompositeOperation(op);
209
    cairo_set_source(cr, pattern);
210
    cairo_pattern_destroy(pattern);
211
    cairo_rectangle(cr, destRect.x(), destRect.y(), destRect.width(), destRect.height());
212
    cairo_fill(cr);
213
214
    context->restore();
215
185
216
    if (imageObserver())
186
    if (imageObserver())
217
        imageObserver()->didDraw(this);
187
        imageObserver()->didDraw(this);

Return to Bug 47076