|
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 |