OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2003, 2004, 2005, 2006, 2009 Apple Inc. All rights reserved. | 2 * Copyright (C) 2003, 2004, 2005, 2006, 2009 Apple Inc. All rights reserved. |
3 * Copyright (C) 2013 Google Inc. All rights reserved. | 3 * Copyright (C) 2013 Google Inc. All rights reserved. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
7 * are met: | 7 * are met: |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 #include "third_party/skia/include/core/SkRefCnt.h" | 46 #include "third_party/skia/include/core/SkRefCnt.h" |
47 #include "third_party/skia/include/core/SkSurface.h" | 47 #include "third_party/skia/include/core/SkSurface.h" |
48 #include "third_party/skia/include/effects/SkBlurMaskFilter.h" | 48 #include "third_party/skia/include/effects/SkBlurMaskFilter.h" |
49 #include "third_party/skia/include/effects/SkCornerPathEffect.h" | 49 #include "third_party/skia/include/effects/SkCornerPathEffect.h" |
50 #include "third_party/skia/include/effects/SkDropShadowImageFilter.h" | 50 #include "third_party/skia/include/effects/SkDropShadowImageFilter.h" |
51 #include "third_party/skia/include/effects/SkLumaColorFilter.h" | 51 #include "third_party/skia/include/effects/SkLumaColorFilter.h" |
52 #include "third_party/skia/include/effects/SkMatrixImageFilter.h" | 52 #include "third_party/skia/include/effects/SkMatrixImageFilter.h" |
53 #include "third_party/skia/include/effects/SkPictureImageFilter.h" | 53 #include "third_party/skia/include/effects/SkPictureImageFilter.h" |
54 #include "third_party/skia/include/gpu/GrRenderTarget.h" | 54 #include "third_party/skia/include/gpu/GrRenderTarget.h" |
55 #include "third_party/skia/include/gpu/GrTexture.h" | 55 #include "third_party/skia/include/gpu/GrTexture.h" |
56 #include "third_party/skia/include/utils/SkNullCanvas.h" | |
57 #include "wtf/Assertions.h" | 56 #include "wtf/Assertions.h" |
58 #include "wtf/MathExtras.h" | 57 #include "wtf/MathExtras.h" |
59 | 58 |
60 namespace blink { | 59 namespace blink { |
61 | 60 |
62 class GraphicsContext::RecordingState { | 61 class GraphicsContext::RecordingState { |
63 WTF_MAKE_FAST_ALLOCATED; | 62 WTF_MAKE_FAST_ALLOCATED; |
64 WTF_MAKE_NONCOPYABLE(RecordingState); | 63 WTF_MAKE_NONCOPYABLE(RecordingState); |
65 public: | 64 public: |
66 static PassOwnPtr<RecordingState> Create(SkCanvas* canvas, const SkMatrix& m
atrix) | 65 static PassOwnPtr<RecordingState> Create(SkCanvas* canvas, const SkMatrix& m
atrix) |
67 { | 66 { |
68 return adoptPtr(new RecordingState(canvas, matrix)); | 67 return adoptPtr(new RecordingState(canvas, matrix)); |
69 } | 68 } |
70 | 69 |
71 SkPictureRecorder& recorder() { return m_recorder; } | 70 SkPictureRecorder& recorder() { return m_recorder; } |
72 SkCanvas* canvas() const { return m_savedCanvas; } | 71 SkCanvas* canvas() const { return m_savedCanvas; } |
73 const SkMatrix& matrix() const { return m_savedMatrix; } | 72 const SkMatrix& matrix() const { return m_savedMatrix; } |
74 | 73 |
75 private: | 74 private: |
76 explicit RecordingState(SkCanvas* canvas, const SkMatrix& matrix) | 75 explicit RecordingState(SkCanvas* canvas, const SkMatrix& matrix) |
77 : m_savedCanvas(canvas) | 76 : m_savedCanvas(canvas) |
78 , m_savedMatrix(matrix) | 77 , m_savedMatrix(matrix) |
79 { } | 78 { } |
80 | 79 |
81 SkPictureRecorder m_recorder; | 80 SkPictureRecorder m_recorder; |
82 SkCanvas* m_savedCanvas; | 81 SkCanvas* m_savedCanvas; |
83 const SkMatrix m_savedMatrix; | 82 const SkMatrix m_savedMatrix; |
84 }; | 83 }; |
85 | 84 |
86 static SkCanvas* nullCanvas() | |
87 { | |
88 DEFINE_STATIC_LOCAL(RefPtr<SkCanvas>, nullCanvas, (adoptRef(SkCreateNullCanv
as()))); | |
89 return nullCanvas.get(); | |
90 } | |
91 | |
92 GraphicsContext::GraphicsContext(SkCanvas* canvas, DisplayItemList* displayItemL
ist, DisabledMode disableContextOrPainting) | 85 GraphicsContext::GraphicsContext(SkCanvas* canvas, DisplayItemList* displayItemL
ist, DisabledMode disableContextOrPainting) |
93 : m_canvas(canvas) | 86 : m_canvas(canvas) |
94 , m_displayItemList(displayItemList) | 87 , m_displayItemList(displayItemList) |
95 , m_clipRecorderStack(0) | 88 , m_clipRecorderStack(0) |
96 , m_paintStateStack() | 89 , m_paintStateStack() |
97 , m_paintStateIndex(0) | 90 , m_paintStateIndex(0) |
98 , m_annotationMode(0) | 91 , m_annotationMode(0) |
99 , m_layerCount(0) | 92 , m_layerCount(0) |
100 #if ENABLE(ASSERT) | 93 #if ENABLE(ASSERT) |
101 , m_annotationCount(0) | 94 , m_annotationCount(0) |
(...skipping 27 matching lines...) Expand all Loading... |
129 #endif | 122 #endif |
130 } | 123 } |
131 | 124 |
132 void GraphicsContext::resetCanvas(SkCanvas* canvas) | 125 void GraphicsContext::resetCanvas(SkCanvas* canvas) |
133 { | 126 { |
134 m_canvas = canvas; | 127 m_canvas = canvas; |
135 } | 128 } |
136 | 129 |
137 void GraphicsContext::save() | 130 void GraphicsContext::save() |
138 { | 131 { |
| 132 if (contextDisabled()) |
| 133 return; |
| 134 |
139 m_paintState->incrementSaveCount(); | 135 m_paintState->incrementSaveCount(); |
140 | 136 |
141 ASSERT(m_canvas); | 137 ASSERT(m_canvas); |
142 m_canvas->save(); | 138 m_canvas->save(); |
143 } | 139 } |
144 | 140 |
145 void GraphicsContext::restore() | 141 void GraphicsContext::restore() |
146 { | 142 { |
| 143 if (contextDisabled()) |
| 144 return; |
| 145 |
147 if (!m_paintStateIndex && !m_paintState->saveCount()) { | 146 if (!m_paintStateIndex && !m_paintState->saveCount()) { |
148 WTF_LOG_ERROR("ERROR void GraphicsContext::restore() stack is empty"); | 147 WTF_LOG_ERROR("ERROR void GraphicsContext::restore() stack is empty"); |
149 return; | 148 return; |
150 } | 149 } |
151 | 150 |
152 if (m_paintState->saveCount()) { | 151 if (m_paintState->saveCount()) { |
153 m_paintState->decrementSaveCount(); | 152 m_paintState->decrementSaveCount(); |
154 } else { | 153 } else { |
155 m_paintStateIndex--; | 154 m_paintStateIndex--; |
156 m_paintState = m_paintStateStack[m_paintStateIndex].get(); | 155 m_paintState = m_paintStateStack[m_paintStateIndex].get(); |
(...skipping 12 matching lines...) Expand all Loading... |
169 ASSERT(m_paintStateStack.size() > m_paintStateIndex); | 168 ASSERT(m_paintStateStack.size() > m_paintStateIndex); |
170 for (unsigned i = 0; i <= m_paintStateIndex; ++i) | 169 for (unsigned i = 0; i <= m_paintStateIndex; ++i) |
171 count += m_paintStateStack[i]->saveCount(); | 170 count += m_paintStateStack[i]->saveCount(); |
172 | 171 |
173 return count; | 172 return count; |
174 } | 173 } |
175 #endif | 174 #endif |
176 | 175 |
177 void GraphicsContext::saveLayer(const SkRect* bounds, const SkPaint* paint) | 176 void GraphicsContext::saveLayer(const SkRect* bounds, const SkPaint* paint) |
178 { | 177 { |
| 178 if (contextDisabled()) |
| 179 return; |
| 180 |
179 ASSERT(m_canvas); | 181 ASSERT(m_canvas); |
| 182 |
180 m_canvas->saveLayer(bounds, paint); | 183 m_canvas->saveLayer(bounds, paint); |
181 } | 184 } |
182 | 185 |
183 void GraphicsContext::restoreLayer() | 186 void GraphicsContext::restoreLayer() |
184 { | 187 { |
| 188 if (contextDisabled()) |
| 189 return; |
| 190 |
185 ASSERT(m_canvas); | 191 ASSERT(m_canvas); |
| 192 |
186 m_canvas->restore(); | 193 m_canvas->restore(); |
187 } | 194 } |
188 | 195 |
189 void GraphicsContext::beginAnnotation(const AnnotationList& annotations) | 196 void GraphicsContext::beginAnnotation(const AnnotationList& annotations) |
190 { | 197 { |
| 198 if (contextDisabled()) |
| 199 return; |
| 200 |
191 ASSERT(m_canvas); | 201 ASSERT(m_canvas); |
192 | 202 |
193 canvas()->beginCommentGroup("GraphicsContextAnnotation"); | 203 canvas()->beginCommentGroup("GraphicsContextAnnotation"); |
194 | 204 |
195 AnnotationList::const_iterator end = annotations.end(); | 205 AnnotationList::const_iterator end = annotations.end(); |
196 for (AnnotationList::const_iterator it = annotations.begin(); it != end; ++i
t) | 206 for (AnnotationList::const_iterator it = annotations.begin(); it != end; ++i
t) |
197 canvas()->addComment(it->first, it->second.ascii().data()); | 207 canvas()->addComment(it->first, it->second.ascii().data()); |
198 | 208 |
199 #if ENABLE(ASSERT) | 209 #if ENABLE(ASSERT) |
200 ++m_annotationCount; | 210 ++m_annotationCount; |
201 #endif | 211 #endif |
202 } | 212 } |
203 | 213 |
204 void GraphicsContext::endAnnotation() | 214 void GraphicsContext::endAnnotation() |
205 { | 215 { |
| 216 if (contextDisabled()) |
| 217 return; |
| 218 |
206 ASSERT(m_canvas); | 219 ASSERT(m_canvas); |
207 ASSERT(m_annotationCount > 0); | 220 ASSERT(m_annotationCount > 0); |
208 canvas()->endCommentGroup(); | 221 canvas()->endCommentGroup(); |
209 | 222 |
210 #if ENABLE(ASSERT) | 223 #if ENABLE(ASSERT) |
211 --m_annotationCount; | 224 --m_annotationCount; |
212 #endif | 225 #endif |
213 } | 226 } |
214 | 227 |
215 #if ENABLE(ASSERT) | 228 #if ENABLE(ASSERT) |
216 void GraphicsContext::setInDrawingRecorder(bool val) | 229 void GraphicsContext::setInDrawingRecorder(bool val) |
217 { | 230 { |
218 // Nested drawing recorers are not allowed. | 231 // Nested drawing recorers are not allowed. |
219 ASSERT(!val || !m_inDrawingRecorder); | 232 ASSERT(!val || !m_inDrawingRecorder); |
220 m_inDrawingRecorder = val; | 233 m_inDrawingRecorder = val; |
221 } | 234 } |
222 #endif | 235 #endif |
223 | 236 |
224 void GraphicsContext::setStrokePattern(PassRefPtr<Pattern> pattern, float alpha) | 237 void GraphicsContext::setStrokePattern(PassRefPtr<Pattern> pattern, float alpha) |
225 { | 238 { |
| 239 if (contextDisabled()) |
| 240 return; |
| 241 |
226 ASSERT(pattern); | 242 ASSERT(pattern); |
227 if (!pattern) { | 243 if (!pattern) { |
228 setStrokeColor(Color::black); | 244 setStrokeColor(Color::black); |
229 return; | 245 return; |
230 } | 246 } |
231 | 247 |
232 mutableState()->setStrokePattern(pattern, alpha); | 248 mutableState()->setStrokePattern(pattern, alpha); |
233 } | 249 } |
234 | 250 |
235 void GraphicsContext::setStrokeGradient(PassRefPtr<Gradient> gradient, float alp
ha) | 251 void GraphicsContext::setStrokeGradient(PassRefPtr<Gradient> gradient, float alp
ha) |
236 { | 252 { |
| 253 if (contextDisabled()) |
| 254 return; |
| 255 |
237 ASSERT(gradient); | 256 ASSERT(gradient); |
238 if (!gradient) { | 257 if (!gradient) { |
239 setStrokeColor(Color::black); | 258 setStrokeColor(Color::black); |
240 return; | 259 return; |
241 } | 260 } |
242 mutableState()->setStrokeGradient(gradient, alpha); | 261 mutableState()->setStrokeGradient(gradient, alpha); |
243 } | 262 } |
244 | 263 |
245 void GraphicsContext::setFillPattern(PassRefPtr<Pattern> pattern, float alpha) | 264 void GraphicsContext::setFillPattern(PassRefPtr<Pattern> pattern, float alpha) |
246 { | 265 { |
| 266 if (contextDisabled()) |
| 267 return; |
| 268 |
247 ASSERT(pattern); | 269 ASSERT(pattern); |
248 if (!pattern) { | 270 if (!pattern) { |
249 setFillColor(Color::black); | 271 setFillColor(Color::black); |
250 return; | 272 return; |
251 } | 273 } |
252 | 274 |
253 mutableState()->setFillPattern(pattern, alpha); | 275 mutableState()->setFillPattern(pattern, alpha); |
254 } | 276 } |
255 | 277 |
256 void GraphicsContext::setFillGradient(PassRefPtr<Gradient> gradient, float alpha
) | 278 void GraphicsContext::setFillGradient(PassRefPtr<Gradient> gradient, float alpha
) |
257 { | 279 { |
| 280 if (contextDisabled()) |
| 281 return; |
| 282 |
258 ASSERT(gradient); | 283 ASSERT(gradient); |
259 if (!gradient) { | 284 if (!gradient) { |
260 setFillColor(Color::black); | 285 setFillColor(Color::black); |
261 return; | 286 return; |
262 } | 287 } |
263 | 288 |
264 mutableState()->setFillGradient(gradient, alpha); | 289 mutableState()->setFillGradient(gradient, alpha); |
265 } | 290 } |
266 | 291 |
267 void GraphicsContext::setShadow(const FloatSize& offset, float blur, const Color
& color, | 292 void GraphicsContext::setShadow(const FloatSize& offset, float blur, const Color
& color, |
268 DrawLooperBuilder::ShadowTransformMode shadowTransformMode, | 293 DrawLooperBuilder::ShadowTransformMode shadowTransformMode, |
269 DrawLooperBuilder::ShadowAlphaMode shadowAlphaMode, ShadowMode shadowMode) | 294 DrawLooperBuilder::ShadowAlphaMode shadowAlphaMode, ShadowMode shadowMode) |
270 { | 295 { |
| 296 if (contextDisabled()) |
| 297 return; |
| 298 |
271 OwnPtr<DrawLooperBuilder> drawLooperBuilder = DrawLooperBuilder::create(); | 299 OwnPtr<DrawLooperBuilder> drawLooperBuilder = DrawLooperBuilder::create(); |
272 if (!color.alpha()) { | 300 if (!color.alpha()) { |
273 if (shadowMode == DrawShadowOnly) { | 301 if (shadowMode == DrawShadowOnly) { |
274 // shadow only, but there is no shadow: use an empty draw looper to
disable rendering of the source primitive | 302 // shadow only, but there is no shadow: use an empty draw looper to
disable rendering of the source primitive |
275 setDrawLooper(drawLooperBuilder.release()); | 303 setDrawLooper(drawLooperBuilder.release()); |
276 return; | 304 return; |
277 } | 305 } |
278 clearShadow(); | 306 clearShadow(); |
279 return; | 307 return; |
280 } | 308 } |
(...skipping 12 matching lines...) Expand all Loading... |
293 // These constants are from RadiusToSigma() from DrawLooperBuilder.cpp. | 321 // These constants are from RadiusToSigma() from DrawLooperBuilder.cpp. |
294 const SkScalar sigma = 0.288675f * blur + 0.5f; | 322 const SkScalar sigma = 0.288675f * blur + 0.5f; |
295 SkDropShadowImageFilter::ShadowMode dropShadowMode = shadowMode == DrawS
hadowAndForeground ? SkDropShadowImageFilter::kDrawShadowAndForeground_ShadowMod
e : SkDropShadowImageFilter::kDrawShadowOnly_ShadowMode; | 323 SkDropShadowImageFilter::ShadowMode dropShadowMode = shadowMode == DrawS
hadowAndForeground ? SkDropShadowImageFilter::kDrawShadowAndForeground_ShadowMod
e : SkDropShadowImageFilter::kDrawShadowOnly_ShadowMode; |
296 RefPtr<SkImageFilter> filter = adoptRef(SkDropShadowImageFilter::Create(
offset.width(), offset.height(), sigma, sigma, skColor, dropShadowMode)); | 324 RefPtr<SkImageFilter> filter = adoptRef(SkDropShadowImageFilter::Create(
offset.width(), offset.height(), sigma, sigma, skColor, dropShadowMode)); |
297 setDropShadowImageFilter(filter); | 325 setDropShadowImageFilter(filter); |
298 } | 326 } |
299 } | 327 } |
300 | 328 |
301 void GraphicsContext::setDrawLooper(PassOwnPtr<DrawLooperBuilder> drawLooperBuil
der) | 329 void GraphicsContext::setDrawLooper(PassOwnPtr<DrawLooperBuilder> drawLooperBuil
der) |
302 { | 330 { |
| 331 if (contextDisabled()) |
| 332 return; |
| 333 |
303 mutableState()->setDrawLooper(drawLooperBuilder->detachDrawLooper()); | 334 mutableState()->setDrawLooper(drawLooperBuilder->detachDrawLooper()); |
304 } | 335 } |
305 | 336 |
306 void GraphicsContext::clearDrawLooper() | 337 void GraphicsContext::clearDrawLooper() |
307 { | 338 { |
| 339 if (contextDisabled()) |
| 340 return; |
| 341 |
308 mutableState()->clearDrawLooper(); | 342 mutableState()->clearDrawLooper(); |
309 } | 343 } |
310 | 344 |
311 void GraphicsContext::setDropShadowImageFilter(PassRefPtr<SkImageFilter> imageFi
lter) | 345 void GraphicsContext::setDropShadowImageFilter(PassRefPtr<SkImageFilter> imageFi
lter) |
312 { | 346 { |
| 347 if (contextDisabled()) |
| 348 return; |
| 349 |
313 mutableState()->setDropShadowImageFilter(imageFilter); | 350 mutableState()->setDropShadowImageFilter(imageFilter); |
314 } | 351 } |
315 | 352 |
316 void GraphicsContext::clearDropShadowImageFilter() | 353 void GraphicsContext::clearDropShadowImageFilter() |
317 { | 354 { |
| 355 if (contextDisabled()) |
| 356 return; |
| 357 |
318 mutableState()->clearDropShadowImageFilter(); | 358 mutableState()->clearDropShadowImageFilter(); |
319 } | 359 } |
320 | 360 |
321 bool GraphicsContext::hasShadow() const | 361 bool GraphicsContext::hasShadow() const |
322 { | 362 { |
323 return !!immutableState()->drawLooper() || !!immutableState()->dropShadowIma
geFilter(); | 363 return !!immutableState()->drawLooper() || !!immutableState()->dropShadowIma
geFilter(); |
324 } | 364 } |
325 | 365 |
326 bool GraphicsContext::getTransformedClipBounds(FloatRect* bounds) const | 366 bool GraphicsContext::getTransformedClipBounds(FloatRect* bounds) const |
327 { | 367 { |
| 368 if (contextDisabled()) |
| 369 return false; |
328 ASSERT(m_canvas); | 370 ASSERT(m_canvas); |
329 SkIRect skIBounds; | 371 SkIRect skIBounds; |
330 if (!m_canvas->getClipDeviceBounds(&skIBounds)) | 372 if (!m_canvas->getClipDeviceBounds(&skIBounds)) |
331 return false; | 373 return false; |
332 SkRect skBounds = SkRect::Make(skIBounds); | 374 SkRect skBounds = SkRect::Make(skIBounds); |
333 *bounds = FloatRect(skBounds); | 375 *bounds = FloatRect(skBounds); |
334 return true; | 376 return true; |
335 } | 377 } |
336 | 378 |
337 SkMatrix GraphicsContext::getTotalMatrix() const | 379 SkMatrix GraphicsContext::getTotalMatrix() const |
338 { | 380 { |
339 // FIXME: this is a hack to avoid changing all call sites of getTotalMatrix(
) to not use this method. | 381 // FIXME: this is a hack to avoid changing all call sites of getTotalMatrix(
) to not use this method. |
340 // The code needs to be cleand up after Slimming Paint is launched. | 382 // The code needs to be cleand up after Slimming Paint is launched. |
341 if (RuntimeEnabledFeatures::slimmingPaintEnabled()) | 383 if (RuntimeEnabledFeatures::slimmingPaintEnabled()) |
342 return SkMatrix::I(); | 384 return SkMatrix::I(); |
343 | 385 |
344 if (!m_canvas) | 386 if (contextDisabled() || !m_canvas) |
345 return SkMatrix::I(); | 387 return SkMatrix::I(); |
346 | 388 |
347 ASSERT(m_canvas); | 389 ASSERT(m_canvas); |
348 | 390 |
349 if (!isRecording()) | 391 if (!isRecording()) |
350 return m_canvas->getTotalMatrix(); | 392 return m_canvas->getTotalMatrix(); |
351 | 393 |
352 SkMatrix totalMatrix = m_recordingStateStack.last()->matrix(); | 394 SkMatrix totalMatrix = m_recordingStateStack.last()->matrix(); |
353 totalMatrix.preConcat(m_canvas->getTotalMatrix()); | 395 totalMatrix.preConcat(m_canvas->getTotalMatrix()); |
354 | 396 |
355 return totalMatrix; | 397 return totalMatrix; |
356 } | 398 } |
357 | 399 |
358 void GraphicsContext::setCompositeOperation(SkXfermode::Mode xferMode) | 400 void GraphicsContext::setCompositeOperation(SkXfermode::Mode xferMode) |
359 { | 401 { |
| 402 if (contextDisabled()) |
| 403 return; |
360 mutableState()->setCompositeOperation(xferMode); | 404 mutableState()->setCompositeOperation(xferMode); |
361 } | 405 } |
362 | 406 |
363 SkXfermode::Mode GraphicsContext::compositeOperation() const | 407 SkXfermode::Mode GraphicsContext::compositeOperation() const |
364 { | 408 { |
365 return immutableState()->compositeOperation(); | 409 return immutableState()->compositeOperation(); |
366 } | 410 } |
367 | 411 |
368 CompositeOperator GraphicsContext::compositeOperationDeprecated() const | 412 CompositeOperator GraphicsContext::compositeOperationDeprecated() const |
369 { | 413 { |
(...skipping 10 matching lines...) Expand all Loading... |
380 GraphicsContextState* stateToSet = mutableState(); | 424 GraphicsContextState* stateToSet = mutableState(); |
381 | 425 |
382 // We only support one active color filter at the moment. If (when) this bec
omes a problem, | 426 // We only support one active color filter at the moment. If (when) this bec
omes a problem, |
383 // we should switch to using color filter chains (Skia work in progress). | 427 // we should switch to using color filter chains (Skia work in progress). |
384 ASSERT(!stateToSet->colorFilter()); | 428 ASSERT(!stateToSet->colorFilter()); |
385 stateToSet->setColorFilter(WebCoreColorFilterToSkiaColorFilter(colorFilter))
; | 429 stateToSet->setColorFilter(WebCoreColorFilterToSkiaColorFilter(colorFilter))
; |
386 } | 430 } |
387 | 431 |
388 bool GraphicsContext::readPixels(const SkImageInfo& info, void* pixels, size_t r
owBytes, int x, int y) | 432 bool GraphicsContext::readPixels(const SkImageInfo& info, void* pixels, size_t r
owBytes, int x, int y) |
389 { | 433 { |
| 434 if (contextDisabled()) |
| 435 return false; |
| 436 |
390 ASSERT(m_canvas); | 437 ASSERT(m_canvas); |
391 return m_canvas->readPixels(info, pixels, rowBytes, x, y); | 438 return m_canvas->readPixels(info, pixels, rowBytes, x, y); |
392 } | 439 } |
393 | 440 |
394 void GraphicsContext::setMatrix(const SkMatrix& matrix) | 441 void GraphicsContext::setMatrix(const SkMatrix& matrix) |
395 { | 442 { |
| 443 if (contextDisabled()) |
| 444 return; |
| 445 |
396 ASSERT(m_canvas); | 446 ASSERT(m_canvas); |
| 447 |
397 m_canvas->setMatrix(matrix); | 448 m_canvas->setMatrix(matrix); |
398 } | 449 } |
399 | 450 |
400 void GraphicsContext::concat(const SkMatrix& matrix) | 451 void GraphicsContext::concat(const SkMatrix& matrix) |
401 { | 452 { |
| 453 if (contextDisabled()) |
| 454 return; |
| 455 |
402 if (matrix.isIdentity()) | 456 if (matrix.isIdentity()) |
403 return; | 457 return; |
404 | 458 |
405 ASSERT(m_canvas); | 459 ASSERT(m_canvas); |
406 | 460 |
407 m_canvas->concat(matrix); | 461 m_canvas->concat(matrix); |
408 } | 462 } |
409 | 463 |
410 void GraphicsContext::beginTransparencyLayer(float opacity, const FloatRect* bou
nds) | 464 void GraphicsContext::beginTransparencyLayer(float opacity, const FloatRect* bou
nds) |
411 { | 465 { |
412 beginLayer(opacity, immutableState()->compositeOperation(), bounds); | 466 beginLayer(opacity, immutableState()->compositeOperation(), bounds); |
413 } | 467 } |
414 | 468 |
415 void GraphicsContext::beginLayer(float opacity, SkXfermode::Mode xfermode, const
FloatRect* bounds, ColorFilter colorFilter, SkImageFilter* imageFilter) | 469 void GraphicsContext::beginLayer(float opacity, SkXfermode::Mode xfermode, const
FloatRect* bounds, ColorFilter colorFilter, SkImageFilter* imageFilter) |
416 { | 470 { |
| 471 if (contextDisabled()) |
| 472 return; |
| 473 |
417 SkPaint layerPaint; | 474 SkPaint layerPaint; |
418 layerPaint.setAlpha(static_cast<unsigned char>(opacity * 255)); | 475 layerPaint.setAlpha(static_cast<unsigned char>(opacity * 255)); |
419 layerPaint.setXfermodeMode(xfermode); | 476 layerPaint.setXfermodeMode(xfermode); |
420 layerPaint.setColorFilter(WebCoreColorFilterToSkiaColorFilter(colorFilter).g
et()); | 477 layerPaint.setColorFilter(WebCoreColorFilterToSkiaColorFilter(colorFilter).g
et()); |
421 layerPaint.setImageFilter(imageFilter); | 478 layerPaint.setImageFilter(imageFilter); |
422 | 479 |
423 if (bounds) { | 480 if (bounds) { |
424 SkRect skBounds = WebCoreFloatRectToSKRect(*bounds); | 481 SkRect skBounds = WebCoreFloatRectToSKRect(*bounds); |
425 saveLayer(&skBounds, &layerPaint); | 482 saveLayer(&skBounds, &layerPaint); |
426 } else { | 483 } else { |
427 saveLayer(0, &layerPaint); | 484 saveLayer(0, &layerPaint); |
428 } | 485 } |
429 | 486 |
430 ++m_layerCount; | 487 ++m_layerCount; |
431 } | 488 } |
432 | 489 |
433 void GraphicsContext::endLayer() | 490 void GraphicsContext::endLayer() |
434 { | 491 { |
| 492 if (contextDisabled()) |
| 493 return; |
| 494 |
435 restoreLayer(); | 495 restoreLayer(); |
436 | 496 |
437 ASSERT(m_layerCount > 0); | 497 ASSERT(m_layerCount > 0); |
438 --m_layerCount; | 498 --m_layerCount; |
439 } | 499 } |
440 | 500 |
441 void GraphicsContext::beginRecording(const FloatRect& bounds, uint32_t recordFla
gs) | 501 void GraphicsContext::beginRecording(const FloatRect& bounds, uint32_t recordFla
gs) |
442 { | 502 { |
| 503 if (contextDisabled()) |
| 504 return; |
| 505 |
443 m_recordingStateStack.append( | 506 m_recordingStateStack.append( |
444 RecordingState::Create(m_canvas, getTotalMatrix())); | 507 RecordingState::Create(m_canvas, getTotalMatrix())); |
445 m_canvas = contextDisabled() ? nullCanvas() : m_recordingStateStack.last()->
recorder().beginRecording(bounds, 0, recordFlags); | 508 m_canvas = m_recordingStateStack.last()->recorder().beginRecording(bounds, 0
, recordFlags); |
446 } | 509 } |
447 | 510 |
448 PassRefPtr<const SkPicture> GraphicsContext::endRecording() | 511 PassRefPtr<const SkPicture> GraphicsContext::endRecording() |
449 { | 512 { |
| 513 if (contextDisabled()) |
| 514 return nullptr; |
| 515 |
450 ASSERT(!m_recordingStateStack.isEmpty()); | 516 ASSERT(!m_recordingStateStack.isEmpty()); |
451 RecordingState* recording = m_recordingStateStack.last().get(); | 517 RecordingState* recording = m_recordingStateStack.last().get(); |
452 RefPtr<const SkPicture> picture; | 518 RefPtr<const SkPicture> picture = adoptRef(recording->recorder().endRecordin
gAsPicture()); |
453 if (!contextDisabled()) { | 519 m_canvas = recording->canvas(); |
454 picture = adoptRef(recording->recorder().endRecordingAsPicture()); | |
455 ASSERT(picture); | |
456 } | |
457 | 520 |
458 m_canvas = recording->canvas(); | |
459 m_recordingStateStack.removeLast(); | 521 m_recordingStateStack.removeLast(); |
460 | 522 |
| 523 ASSERT(picture); |
461 return picture.release(); | 524 return picture.release(); |
462 } | 525 } |
463 | 526 |
464 bool GraphicsContext::isRecording() const | 527 bool GraphicsContext::isRecording() const |
465 { | 528 { |
466 return !m_recordingStateStack.isEmpty(); | 529 return !m_recordingStateStack.isEmpty(); |
467 } | 530 } |
468 | 531 |
469 void GraphicsContext::drawPicture(const SkPicture* picture) | 532 void GraphicsContext::drawPicture(const SkPicture* picture) |
470 { | 533 { |
471 ASSERT(m_canvas); | 534 ASSERT(m_canvas); |
472 | 535 |
473 // FIXME: SP currently builds empty-bounds pictures in some cases. This is a
temp | 536 // FIXME: SP currently builds empty-bounds pictures in some cases. This is a
temp |
474 // workaround, but the problem should be fixed: empty-bounds pictures are go
ing to be culled | 537 // workaround, but the problem should be fixed: empty-bounds pictures are go
ing to be culled |
475 // on playback anyway. | 538 // on playback anyway. |
476 bool cullEmptyPictures = !RuntimeEnabledFeatures::slimmingPaintEnabled(); | 539 bool cullEmptyPictures = !RuntimeEnabledFeatures::slimmingPaintEnabled(); |
477 if (!picture || (picture->cullRect().isEmpty() && cullEmptyPictures)) | 540 if (contextDisabled() || !picture || (picture->cullRect().isEmpty() && cullE
mptyPictures)) |
478 return; | 541 return; |
479 | 542 |
480 m_canvas->drawPicture(picture); | 543 m_canvas->drawPicture(picture); |
481 } | 544 } |
482 | 545 |
483 void GraphicsContext::compositePicture(SkPicture* picture, const FloatRect& dest
, const FloatRect& src, SkXfermode::Mode op) | 546 void GraphicsContext::compositePicture(SkPicture* picture, const FloatRect& dest
, const FloatRect& src, SkXfermode::Mode op) |
484 { | 547 { |
485 ASSERT(m_canvas); | 548 ASSERT(m_canvas); |
486 if (!picture) | 549 if (contextDisabled() || !picture) |
487 return; | 550 return; |
488 | 551 |
489 SkPaint picturePaint; | 552 SkPaint picturePaint; |
490 picturePaint.setXfermodeMode(op); | 553 picturePaint.setXfermodeMode(op); |
491 m_canvas->save(); | 554 m_canvas->save(); |
492 SkRect sourceBounds = WebCoreFloatRectToSKRect(src); | 555 SkRect sourceBounds = WebCoreFloatRectToSKRect(src); |
493 SkRect skBounds = WebCoreFloatRectToSKRect(dest); | 556 SkRect skBounds = WebCoreFloatRectToSKRect(dest); |
494 SkMatrix pictureTransform; | 557 SkMatrix pictureTransform; |
495 pictureTransform.setRectToRect(sourceBounds, skBounds, SkMatrix::kFill_Scale
ToFit); | 558 pictureTransform.setRectToRect(sourceBounds, skBounds, SkMatrix::kFill_Scale
ToFit); |
496 m_canvas->concat(pictureTransform); | 559 m_canvas->concat(pictureTransform); |
497 RefPtr<SkPictureImageFilter> pictureFilter = adoptRef(SkPictureImageFilter::
CreateForLocalSpace(picture, sourceBounds, static_cast<SkPaint::FilterLevel>(ima
geInterpolationQuality()))); | 560 RefPtr<SkPictureImageFilter> pictureFilter = adoptRef(SkPictureImageFilter::
CreateForLocalSpace(picture, sourceBounds, static_cast<SkPaint::FilterLevel>(ima
geInterpolationQuality()))); |
498 picturePaint.setImageFilter(pictureFilter.get()); | 561 picturePaint.setImageFilter(pictureFilter.get()); |
499 m_canvas->saveLayer(&sourceBounds, &picturePaint); | 562 m_canvas->saveLayer(&sourceBounds, &picturePaint); |
500 m_canvas->restore(); | 563 m_canvas->restore(); |
501 m_canvas->restore(); | 564 m_canvas->restore(); |
502 } | 565 } |
503 | 566 |
504 void GraphicsContext::fillPolygon(size_t numPoints, const FloatPoint* points, co
nst Color& color, | 567 void GraphicsContext::fillPolygon(size_t numPoints, const FloatPoint* points, co
nst Color& color, |
505 bool shouldAntialias) | 568 bool shouldAntialias) |
506 { | 569 { |
| 570 if (contextDisabled()) |
| 571 return; |
| 572 |
507 ASSERT(numPoints > 2); | 573 ASSERT(numPoints > 2); |
508 | 574 |
509 SkPath path; | 575 SkPath path; |
510 setPathFromPoints(&path, numPoints, points); | 576 setPathFromPoints(&path, numPoints, points); |
511 | 577 |
512 SkPaint paint(immutableState()->fillPaint()); | 578 SkPaint paint(immutableState()->fillPaint()); |
513 paint.setAntiAlias(shouldAntialias); | 579 paint.setAntiAlias(shouldAntialias); |
514 paint.setColor(color.rgb()); | 580 paint.setColor(color.rgb()); |
515 | 581 |
516 drawPath(path, paint); | 582 drawPath(path, paint); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
564 // Inner rect | 630 // Inner rect |
565 paint.setAlpha(128); | 631 paint.setAlpha(128); |
566 paint.setStrokeWidth(paint.getStrokeWidth() * 0.5f); | 632 paint.setStrokeWidth(paint.getStrokeWidth() * 0.5f); |
567 drawRRect(rrect, paint); | 633 drawRRect(rrect, paint); |
568 #endif | 634 #endif |
569 } | 635 } |
570 | 636 |
571 void GraphicsContext::drawFocusRing(const Path& focusRingPath, int width, int of
fset, const Color& color) | 637 void GraphicsContext::drawFocusRing(const Path& focusRingPath, int width, int of
fset, const Color& color) |
572 { | 638 { |
573 // FIXME: Implement support for offset. | 639 // FIXME: Implement support for offset. |
| 640 if (contextDisabled()) |
| 641 return; |
| 642 |
574 drawFocusRingPath(focusRingPath.skPath(), color, width); | 643 drawFocusRingPath(focusRingPath.skPath(), color, width); |
575 } | 644 } |
576 | 645 |
577 void GraphicsContext::drawFocusRing(const Vector<IntRect>& rects, int width, int
offset, const Color& color) | 646 void GraphicsContext::drawFocusRing(const Vector<IntRect>& rects, int width, int
offset, const Color& color) |
578 { | 647 { |
| 648 if (contextDisabled()) |
| 649 return; |
| 650 |
579 unsigned rectCount = rects.size(); | 651 unsigned rectCount = rects.size(); |
580 if (!rectCount) | 652 if (!rectCount) |
581 return; | 653 return; |
582 | 654 |
583 SkRegion focusRingRegion; | 655 SkRegion focusRingRegion; |
584 const int outset = focusRingOutset(offset); | 656 const int outset = focusRingOutset(offset); |
585 for (unsigned i = 0; i < rectCount; i++) { | 657 for (unsigned i = 0; i < rectCount; i++) { |
586 SkIRect r = rects[i]; | 658 SkIRect r = rects[i]; |
587 r.inset(-outset, -outset); | 659 r.inset(-outset, -outset); |
588 focusRingRegion.op(r, SkRegion::kUnion_Op); | 660 focusRingRegion.op(r, SkRegion::kUnion_Op); |
(...skipping 17 matching lines...) Expand all Loading... |
606 if (shadowSpread < 0) | 678 if (shadowSpread < 0) |
607 bounds.inflate(-shadowSpread); | 679 bounds.inflate(-shadowSpread); |
608 | 680 |
609 IntRect offsetBounds = bounds; | 681 IntRect offsetBounds = bounds; |
610 offsetBounds.move(-shadowOffset); | 682 offsetBounds.move(-shadowOffset); |
611 return unionRect(bounds, offsetBounds); | 683 return unionRect(bounds, offsetBounds); |
612 } | 684 } |
613 | 685 |
614 void GraphicsContext::drawInnerShadow(const FloatRoundedRect& rect, const Color&
shadowColor, const IntSize shadowOffset, int shadowBlur, int shadowSpread, Edge
s clippedEdges) | 686 void GraphicsContext::drawInnerShadow(const FloatRoundedRect& rect, const Color&
shadowColor, const IntSize shadowOffset, int shadowBlur, int shadowSpread, Edge
s clippedEdges) |
615 { | 687 { |
| 688 if (contextDisabled()) |
| 689 return; |
| 690 |
616 FloatRect holeRect(rect.rect()); | 691 FloatRect holeRect(rect.rect()); |
617 holeRect.inflate(-shadowSpread); | 692 holeRect.inflate(-shadowSpread); |
618 | 693 |
619 if (holeRect.isEmpty()) { | 694 if (holeRect.isEmpty()) { |
620 if (rect.isRounded()) | 695 if (rect.isRounded()) |
621 fillRoundedRect(rect, shadowColor); | 696 fillRoundedRect(rect, shadowColor); |
622 else | 697 else |
623 fillRect(rect.rect(), shadowColor); | 698 fillRect(rect.rect(), shadowColor); |
624 return; | 699 return; |
625 } | 700 } |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
660 DrawLooperBuilder::ShadowRespectsTransforms, DrawLooperBuilder::ShadowIg
noresAlpha); | 735 DrawLooperBuilder::ShadowRespectsTransforms, DrawLooperBuilder::ShadowIg
noresAlpha); |
661 setDrawLooper(drawLooperBuilder.release()); | 736 setDrawLooper(drawLooperBuilder.release()); |
662 fillRectWithRoundedHole(outerRect, roundedHole, fillColor); | 737 fillRectWithRoundedHole(outerRect, roundedHole, fillColor); |
663 restore(); | 738 restore(); |
664 clearDrawLooper(); | 739 clearDrawLooper(); |
665 } | 740 } |
666 | 741 |
667 void GraphicsContext::drawLine(const IntPoint& point1, const IntPoint& point2) | 742 void GraphicsContext::drawLine(const IntPoint& point1, const IntPoint& point2) |
668 { | 743 { |
669 ASSERT(m_canvas); | 744 ASSERT(m_canvas); |
| 745 if (contextDisabled()) |
| 746 return; |
670 | 747 |
671 StrokeStyle penStyle = strokeStyle(); | 748 StrokeStyle penStyle = strokeStyle(); |
672 if (penStyle == NoStroke) | 749 if (penStyle == NoStroke) |
673 return; | 750 return; |
674 | 751 |
675 FloatPoint p1 = point1; | 752 FloatPoint p1 = point1; |
676 FloatPoint p2 = point2; | 753 FloatPoint p2 = point2; |
677 bool isVerticalLine = (p1.x() == p2.x()); | 754 bool isVerticalLine = (p1.x() == p2.x()); |
678 int width = roundf(strokeThickness()); | 755 int width = roundf(strokeThickness()); |
679 | 756 |
(...skipping 25 matching lines...) Expand all Loading... |
705 } | 782 } |
706 | 783 |
707 adjustLineToPixelBoundaries(p1, p2, width, penStyle); | 784 adjustLineToPixelBoundaries(p1, p2, width, penStyle); |
708 SkPoint pts[2] = { p1.data(), p2.data() }; | 785 SkPoint pts[2] = { p1.data(), p2.data() }; |
709 | 786 |
710 m_canvas->drawPoints(SkCanvas::kLines_PointMode, 2, pts, paint); | 787 m_canvas->drawPoints(SkCanvas::kLines_PointMode, 2, pts, paint); |
711 } | 788 } |
712 | 789 |
713 void GraphicsContext::drawLineForDocumentMarker(const FloatPoint& pt, float widt
h, DocumentMarkerLineStyle style) | 790 void GraphicsContext::drawLineForDocumentMarker(const FloatPoint& pt, float widt
h, DocumentMarkerLineStyle style) |
714 { | 791 { |
| 792 if (contextDisabled()) |
| 793 return; |
| 794 |
715 // Use 2x resources for a device scale factor of 1.5 or above. | 795 // Use 2x resources for a device scale factor of 1.5 or above. |
716 int deviceScaleFactor = m_deviceScaleFactor > 1.5f ? 2 : 1; | 796 int deviceScaleFactor = m_deviceScaleFactor > 1.5f ? 2 : 1; |
717 | 797 |
718 // Create the pattern we'll use to draw the underline. | 798 // Create the pattern we'll use to draw the underline. |
719 int index = style == DocumentMarkerGrammarLineStyle ? 1 : 0; | 799 int index = style == DocumentMarkerGrammarLineStyle ? 1 : 0; |
720 static SkBitmap* misspellBitmap1x[2] = { 0, 0 }; | 800 static SkBitmap* misspellBitmap1x[2] = { 0, 0 }; |
721 static SkBitmap* misspellBitmap2x[2] = { 0, 0 }; | 801 static SkBitmap* misspellBitmap2x[2] = { 0, 0 }; |
722 SkBitmap** misspellBitmap = deviceScaleFactor == 2 ? misspellBitmap2x : miss
pellBitmap1x; | 802 SkBitmap** misspellBitmap = deviceScaleFactor == 2 ? misspellBitmap2x : miss
pellBitmap1x; |
723 if (!misspellBitmap[index]) { | 803 if (!misspellBitmap[index]) { |
724 #if OS(MACOSX) | 804 #if OS(MACOSX) |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
832 save(); | 912 save(); |
833 scale(0.5, 0.5); | 913 scale(0.5, 0.5); |
834 } | 914 } |
835 drawRect(rect, paint); | 915 drawRect(rect, paint); |
836 if (deviceScaleFactor == 2) | 916 if (deviceScaleFactor == 2) |
837 restore(); | 917 restore(); |
838 } | 918 } |
839 | 919 |
840 void GraphicsContext::drawLineForText(const FloatPoint& pt, float width, bool pr
inting) | 920 void GraphicsContext::drawLineForText(const FloatPoint& pt, float width, bool pr
inting) |
841 { | 921 { |
| 922 if (contextDisabled()) |
| 923 return; |
| 924 |
842 if (width <= 0) | 925 if (width <= 0) |
843 return; | 926 return; |
844 | 927 |
845 SkPaint paint; | 928 SkPaint paint; |
846 switch (strokeStyle()) { | 929 switch (strokeStyle()) { |
847 case NoStroke: | 930 case NoStroke: |
848 case SolidStroke: | 931 case SolidStroke: |
849 case DoubleStroke: | 932 case DoubleStroke: |
850 case WavyStroke: { | 933 case WavyStroke: { |
851 int thickness = SkMax32(static_cast<int>(strokeThickness()), 1); | 934 int thickness = SkMax32(static_cast<int>(strokeThickness()), 1); |
(...skipping 17 matching lines...) Expand all Loading... |
869 return; | 952 return; |
870 } | 953 } |
871 } | 954 } |
872 | 955 |
873 ASSERT_NOT_REACHED(); | 956 ASSERT_NOT_REACHED(); |
874 } | 957 } |
875 | 958 |
876 // Draws a filled rectangle with a stroked border. | 959 // Draws a filled rectangle with a stroked border. |
877 void GraphicsContext::drawRect(const IntRect& rect) | 960 void GraphicsContext::drawRect(const IntRect& rect) |
878 { | 961 { |
| 962 if (contextDisabled()) |
| 963 return; |
| 964 |
879 ASSERT(!rect.isEmpty()); | 965 ASSERT(!rect.isEmpty()); |
880 if (rect.isEmpty()) | 966 if (rect.isEmpty()) |
881 return; | 967 return; |
882 | 968 |
883 SkRect skRect = rect; | 969 SkRect skRect = rect; |
884 int fillcolorNotTransparent = immutableState()->fillColor().rgb() & 0xFF0000
00; | 970 int fillcolorNotTransparent = immutableState()->fillColor().rgb() & 0xFF0000
00; |
885 if (fillcolorNotTransparent) | 971 if (fillcolorNotTransparent) |
886 drawRect(skRect, immutableState()->fillPaint()); | 972 drawRect(skRect, immutableState()->fillPaint()); |
887 | 973 |
888 if (immutableState()->strokeData().style() != NoStroke | 974 if (immutableState()->strokeData().style() != NoStroke |
889 && immutableState()->strokeColor().alpha()) { | 975 && immutableState()->strokeColor().alpha()) { |
890 // Stroke a width: 1 inset border | 976 // Stroke a width: 1 inset border |
891 SkPaint paint(immutableState()->fillPaint()); | 977 SkPaint paint(immutableState()->fillPaint()); |
892 paint.setColor(effectiveStrokeColor()); | 978 paint.setColor(effectiveStrokeColor()); |
893 paint.setStyle(SkPaint::kStroke_Style); | 979 paint.setStyle(SkPaint::kStroke_Style); |
894 paint.setStrokeWidth(1); | 980 paint.setStrokeWidth(1); |
895 | 981 |
896 skRect.inset(0.5f, 0.5f); | 982 skRect.inset(0.5f, 0.5f); |
897 drawRect(skRect, paint); | 983 drawRect(skRect, paint); |
898 } | 984 } |
899 } | 985 } |
900 | 986 |
901 void GraphicsContext::drawText(const Font& font, const TextRunPaintInfo& runInfo
, const FloatPoint& point) | 987 void GraphicsContext::drawText(const Font& font, const TextRunPaintInfo& runInfo
, const FloatPoint& point) |
902 { | 988 { |
| 989 if (contextDisabled()) |
| 990 return; |
| 991 |
903 font.drawText(this, runInfo, point); | 992 font.drawText(this, runInfo, point); |
904 } | 993 } |
905 | 994 |
906 void GraphicsContext::drawEmphasisMarks(const Font& font, const TextRunPaintInfo
& runInfo, const AtomicString& mark, const FloatPoint& point) | 995 void GraphicsContext::drawEmphasisMarks(const Font& font, const TextRunPaintInfo
& runInfo, const AtomicString& mark, const FloatPoint& point) |
907 { | 996 { |
| 997 if (contextDisabled()) |
| 998 return; |
| 999 |
908 font.drawEmphasisMarks(this, runInfo, mark, point); | 1000 font.drawEmphasisMarks(this, runInfo, mark, point); |
909 } | 1001 } |
910 | 1002 |
911 void GraphicsContext::drawBidiText(const Font& font, const TextRunPaintInfo& run
Info, const FloatPoint& point, Font::CustomFontNotReadyAction customFontNotReady
Action) | 1003 void GraphicsContext::drawBidiText(const Font& font, const TextRunPaintInfo& run
Info, const FloatPoint& point, Font::CustomFontNotReadyAction customFontNotReady
Action) |
912 { | 1004 { |
| 1005 if (contextDisabled()) |
| 1006 return; |
| 1007 |
913 font.drawBidiText(this, runInfo, point, customFontNotReadyAction); | 1008 font.drawBidiText(this, runInfo, point, customFontNotReadyAction); |
914 } | 1009 } |
915 | 1010 |
916 void GraphicsContext::drawHighlightForText(const Font& font, const TextRun& run,
const FloatPoint& point, int h, const Color& backgroundColor, int from, int to) | 1011 void GraphicsContext::drawHighlightForText(const Font& font, const TextRun& run,
const FloatPoint& point, int h, const Color& backgroundColor, int from, int to) |
917 { | 1012 { |
| 1013 if (contextDisabled()) |
| 1014 return; |
| 1015 |
918 fillRect(font.selectionRectForText(run, point, h, from, to), backgroundColor
); | 1016 fillRect(font.selectionRectForText(run, point, h, from, to), backgroundColor
); |
919 } | 1017 } |
920 | 1018 |
921 void GraphicsContext::drawImage(Image* image, const IntPoint& p, SkXfermode::Mod
e op, RespectImageOrientationEnum shouldRespectImageOrientation) | 1019 void GraphicsContext::drawImage(Image* image, const IntPoint& p, SkXfermode::Mod
e op, RespectImageOrientationEnum shouldRespectImageOrientation) |
922 { | 1020 { |
923 if (!image) | 1021 if (!image) |
924 return; | 1022 return; |
925 drawImage(image, FloatRect(IntRect(p, image->size())), FloatRect(FloatPoint(
), FloatSize(image->size())), op, shouldRespectImageOrientation); | 1023 drawImage(image, FloatRect(IntRect(p, image->size())), FloatRect(FloatPoint(
), FloatSize(image->size())), op, shouldRespectImageOrientation); |
926 } | 1024 } |
927 | 1025 |
928 void GraphicsContext::drawImage(Image* image, const IntRect& r, SkXfermode::Mode
op, RespectImageOrientationEnum shouldRespectImageOrientation) | 1026 void GraphicsContext::drawImage(Image* image, const IntRect& r, SkXfermode::Mode
op, RespectImageOrientationEnum shouldRespectImageOrientation) |
929 { | 1027 { |
930 if (!image) | 1028 if (!image) |
931 return; | 1029 return; |
932 drawImage(image, FloatRect(r), FloatRect(FloatPoint(), FloatSize(image->size
())), op, shouldRespectImageOrientation); | 1030 drawImage(image, FloatRect(r), FloatRect(FloatPoint(), FloatSize(image->size
())), op, shouldRespectImageOrientation); |
933 } | 1031 } |
934 | 1032 |
935 void GraphicsContext::drawImage(Image* image, const FloatRect& dest) | 1033 void GraphicsContext::drawImage(Image* image, const FloatRect& dest) |
936 { | 1034 { |
937 if (!image) | 1035 if (!image) |
938 return; | 1036 return; |
939 drawImage(image, dest, FloatRect(IntRect(IntPoint(), image->size()))); | 1037 drawImage(image, dest, FloatRect(IntRect(IntPoint(), image->size()))); |
940 } | 1038 } |
941 | 1039 |
942 void GraphicsContext::drawImage(Image* image, const FloatRect& dest, const Float
Rect& src, SkXfermode::Mode op, RespectImageOrientationEnum shouldRespectImageOr
ientation) | 1040 void GraphicsContext::drawImage(Image* image, const FloatRect& dest, const Float
Rect& src, SkXfermode::Mode op, RespectImageOrientationEnum shouldRespectImageOr
ientation) |
943 { | 1041 { |
944 if (!image) | 1042 if (contextDisabled() || !image) |
945 return; | 1043 return; |
946 image->draw(this, dest, src, op, shouldRespectImageOrientation); | 1044 image->draw(this, dest, src, op, shouldRespectImageOrientation); |
947 } | 1045 } |
948 | 1046 |
949 void GraphicsContext::drawTiledImage(Image* image, const IntRect& destRect, cons
t IntPoint& srcPoint, const IntSize& tileSize, SkXfermode::Mode op, const IntSiz
e& repeatSpacing) | 1047 void GraphicsContext::drawTiledImage(Image* image, const IntRect& destRect, cons
t IntPoint& srcPoint, const IntSize& tileSize, SkXfermode::Mode op, const IntSiz
e& repeatSpacing) |
950 { | 1048 { |
951 if (!image) | 1049 if (contextDisabled() || !image) |
952 return; | 1050 return; |
953 image->drawTiled(this, destRect, srcPoint, tileSize, op, repeatSpacing); | 1051 image->drawTiled(this, destRect, srcPoint, tileSize, op, repeatSpacing); |
954 } | 1052 } |
955 | 1053 |
956 void GraphicsContext::drawTiledImage(Image* image, const IntRect& dest, const In
tRect& srcRect, | 1054 void GraphicsContext::drawTiledImage(Image* image, const IntRect& dest, const In
tRect& srcRect, |
957 const FloatSize& tileScaleFactor, Image::TileRule hRule, Image::TileRule vRu
le, SkXfermode::Mode op) | 1055 const FloatSize& tileScaleFactor, Image::TileRule hRule, Image::TileRule vRu
le, SkXfermode::Mode op) |
958 { | 1056 { |
959 if (!image) | 1057 if (contextDisabled() || !image) |
960 return; | 1058 return; |
961 | 1059 |
962 if (hRule == Image::StretchTile && vRule == Image::StretchTile) { | 1060 if (hRule == Image::StretchTile && vRule == Image::StretchTile) { |
963 // Just do a scale. | 1061 // Just do a scale. |
964 drawImage(image, dest, srcRect, op); | 1062 drawImage(image, dest, srcRect, op); |
965 return; | 1063 return; |
966 } | 1064 } |
967 | 1065 |
968 image->drawTiled(this, dest, srcRect, tileScaleFactor, hRule, vRule, op); | 1066 image->drawTiled(this, dest, srcRect, tileScaleFactor, hRule, vRule, op); |
969 } | 1067 } |
970 | 1068 |
971 void GraphicsContext::drawImageBuffer(ImageBuffer* image, const FloatRect& dest, | 1069 void GraphicsContext::drawImageBuffer(ImageBuffer* image, const FloatRect& dest, |
972 const FloatRect* src, SkXfermode::Mode op) | 1070 const FloatRect* src, SkXfermode::Mode op) |
973 { | 1071 { |
974 if (!image) | 1072 if (contextDisabled() || !image) |
975 return; | 1073 return; |
976 | 1074 |
977 image->draw(this, dest, src, op); | 1075 image->draw(this, dest, src, op); |
978 } | 1076 } |
979 | 1077 |
980 void GraphicsContext::writePixels(const SkImageInfo& info, const void* pixels, s
ize_t rowBytes, int x, int y) | 1078 void GraphicsContext::writePixels(const SkImageInfo& info, const void* pixels, s
ize_t rowBytes, int x, int y) |
981 { | 1079 { |
982 ASSERT(m_canvas); | 1080 ASSERT(m_canvas); |
| 1081 if (contextDisabled()) |
| 1082 return; |
983 | 1083 |
984 m_canvas->writePixels(info, pixels, rowBytes, x, y); | 1084 m_canvas->writePixels(info, pixels, rowBytes, x, y); |
985 } | 1085 } |
986 | 1086 |
987 void GraphicsContext::drawBitmapRect(const SkBitmap& bitmap, const SkRect* src, | 1087 void GraphicsContext::drawBitmapRect(const SkBitmap& bitmap, const SkRect* src, |
988 const SkRect& dst, const SkPaint* paint) | 1088 const SkRect& dst, const SkPaint* paint) |
989 { | 1089 { |
990 ASSERT(m_canvas); | 1090 ASSERT(m_canvas); |
991 // Textures are bound to the blink main-thread GrContext, which can not be | 1091 // Textures are bound to the blink main-thread GrContext, which can not be |
992 // used on the compositor raster thread. | 1092 // used on the compositor raster thread. |
993 // FIXME: Mailbox support would make this possible in the GPU-raster case. | 1093 // FIXME: Mailbox support would make this possible in the GPU-raster case. |
994 ASSERT(!isRecording() || !bitmap.getTexture()); | 1094 ASSERT(!isRecording() || !bitmap.getTexture()); |
| 1095 if (contextDisabled()) |
| 1096 return; |
995 | 1097 |
996 SkCanvas::DrawBitmapRectFlags flags = | 1098 SkCanvas::DrawBitmapRectFlags flags = |
997 immutableState()->shouldClampToSourceRect() ? SkCanvas::kNone_DrawBitmap
RectFlag : SkCanvas::kBleed_DrawBitmapRectFlag; | 1099 immutableState()->shouldClampToSourceRect() ? SkCanvas::kNone_DrawBitmap
RectFlag : SkCanvas::kBleed_DrawBitmapRectFlag; |
998 | 1100 |
999 m_canvas->drawBitmapRectToRect(bitmap, src, dst, paint, flags); | 1101 m_canvas->drawBitmapRectToRect(bitmap, src, dst, paint, flags); |
1000 } | 1102 } |
1001 | 1103 |
1002 void GraphicsContext::drawImage(const SkImage* image, SkScalar left, SkScalar to
p, const SkPaint* paint) | 1104 void GraphicsContext::drawImage(const SkImage* image, SkScalar left, SkScalar to
p, const SkPaint* paint) |
1003 { | 1105 { |
1004 ASSERT(m_canvas); | 1106 ASSERT(m_canvas); |
| 1107 if (contextDisabled()) |
| 1108 return; |
| 1109 |
1005 m_canvas->drawImage(image, left, top, paint); | 1110 m_canvas->drawImage(image, left, top, paint); |
1006 } | 1111 } |
1007 | 1112 |
1008 void GraphicsContext::drawImageRect(const SkImage* image, const SkRect* src, con
st SkRect& dst, const SkPaint* paint) | 1113 void GraphicsContext::drawImageRect(const SkImage* image, const SkRect* src, con
st SkRect& dst, const SkPaint* paint) |
1009 { | 1114 { |
1010 ASSERT(m_canvas); | 1115 ASSERT(m_canvas); |
| 1116 if (contextDisabled()) |
| 1117 return; |
| 1118 |
1011 m_canvas->drawImageRect(image, src, dst, paint); | 1119 m_canvas->drawImageRect(image, src, dst, paint); |
1012 } | 1120 } |
1013 | 1121 |
1014 void GraphicsContext::drawOval(const SkRect& oval, const SkPaint& paint) | 1122 void GraphicsContext::drawOval(const SkRect& oval, const SkPaint& paint) |
1015 { | 1123 { |
1016 ASSERT(m_canvas); | 1124 ASSERT(m_canvas); |
| 1125 if (contextDisabled()) |
| 1126 return; |
| 1127 |
1017 m_canvas->drawOval(oval, paint); | 1128 m_canvas->drawOval(oval, paint); |
1018 } | 1129 } |
1019 | 1130 |
1020 void GraphicsContext::drawPath(const SkPath& path, const SkPaint& paint) | 1131 void GraphicsContext::drawPath(const SkPath& path, const SkPaint& paint) |
1021 { | 1132 { |
1022 ASSERT(m_canvas); | 1133 ASSERT(m_canvas); |
| 1134 if (contextDisabled()) |
| 1135 return; |
| 1136 |
1023 m_canvas->drawPath(path, paint); | 1137 m_canvas->drawPath(path, paint); |
1024 } | 1138 } |
1025 | 1139 |
1026 void GraphicsContext::drawRect(const SkRect& rect, const SkPaint& paint) | 1140 void GraphicsContext::drawRect(const SkRect& rect, const SkPaint& paint) |
1027 { | 1141 { |
1028 ASSERT(m_canvas); | 1142 ASSERT(m_canvas); |
| 1143 if (contextDisabled()) |
| 1144 return; |
| 1145 |
1029 m_canvas->drawRect(rect, paint); | 1146 m_canvas->drawRect(rect, paint); |
1030 } | 1147 } |
1031 | 1148 |
1032 void GraphicsContext::drawRRect(const SkRRect& rrect, const SkPaint& paint) | 1149 void GraphicsContext::drawRRect(const SkRRect& rrect, const SkPaint& paint) |
1033 { | 1150 { |
1034 ASSERT(m_canvas); | 1151 ASSERT(m_canvas); |
| 1152 if (contextDisabled()) |
| 1153 return; |
| 1154 |
1035 m_canvas->drawRRect(rrect, paint); | 1155 m_canvas->drawRRect(rrect, paint); |
1036 } | 1156 } |
1037 | 1157 |
1038 void GraphicsContext::drawPosText(const void* text, size_t byteLength, | 1158 void GraphicsContext::drawPosText(const void* text, size_t byteLength, |
1039 const SkPoint pos[], const SkRect& textRect, const SkPaint& paint) | 1159 const SkPoint pos[], const SkRect& textRect, const SkPaint& paint) |
1040 { | 1160 { |
1041 ASSERT(m_canvas); | 1161 ASSERT(m_canvas); |
| 1162 if (contextDisabled()) |
| 1163 return; |
| 1164 |
1042 m_canvas->drawPosText(text, byteLength, pos, paint); | 1165 m_canvas->drawPosText(text, byteLength, pos, paint); |
1043 didDrawTextInRect(textRect); | 1166 didDrawTextInRect(textRect); |
1044 } | 1167 } |
1045 | 1168 |
1046 void GraphicsContext::drawPosTextH(const void* text, size_t byteLength, | 1169 void GraphicsContext::drawPosTextH(const void* text, size_t byteLength, |
1047 const SkScalar xpos[], SkScalar constY, const SkRect& textRect, const SkPain
t& paint) | 1170 const SkScalar xpos[], SkScalar constY, const SkRect& textRect, const SkPain
t& paint) |
1048 { | 1171 { |
1049 ASSERT(m_canvas); | 1172 ASSERT(m_canvas); |
| 1173 if (contextDisabled()) |
| 1174 return; |
| 1175 |
1050 m_canvas->drawPosTextH(text, byteLength, xpos, constY, paint); | 1176 m_canvas->drawPosTextH(text, byteLength, xpos, constY, paint); |
1051 didDrawTextInRect(textRect); | 1177 didDrawTextInRect(textRect); |
1052 } | 1178 } |
1053 | 1179 |
1054 void GraphicsContext::drawTextBlob(const SkTextBlob* blob, const SkPoint& origin
, const SkPaint& paint) | 1180 void GraphicsContext::drawTextBlob(const SkTextBlob* blob, const SkPoint& origin
, const SkPaint& paint) |
1055 { | 1181 { |
1056 ASSERT(m_canvas); | 1182 ASSERT(m_canvas); |
| 1183 if (contextDisabled()) |
| 1184 return; |
| 1185 |
1057 m_canvas->drawTextBlob(blob, origin.x(), origin.y(), paint); | 1186 m_canvas->drawTextBlob(blob, origin.x(), origin.y(), paint); |
1058 | 1187 |
1059 SkRect bounds = blob->bounds(); | 1188 SkRect bounds = blob->bounds(); |
1060 bounds.offset(origin); | 1189 bounds.offset(origin); |
1061 didDrawTextInRect(bounds); | 1190 didDrawTextInRect(bounds); |
1062 } | 1191 } |
1063 | 1192 |
1064 void GraphicsContext::fillPath(const Path& pathToFill) | 1193 void GraphicsContext::fillPath(const Path& pathToFill) |
1065 { | 1194 { |
1066 if (pathToFill.isEmpty()) | 1195 if (contextDisabled() || pathToFill.isEmpty()) |
1067 return; | 1196 return; |
1068 | 1197 |
1069 // Use const_cast and temporarily modify the fill type instead of copying th
e path. | 1198 // Use const_cast and temporarily modify the fill type instead of copying th
e path. |
1070 SkPath& path = const_cast<SkPath&>(pathToFill.skPath()); | 1199 SkPath& path = const_cast<SkPath&>(pathToFill.skPath()); |
1071 SkPath::FillType previousFillType = path.getFillType(); | 1200 SkPath::FillType previousFillType = path.getFillType(); |
1072 | 1201 |
1073 SkPath::FillType temporaryFillType = WebCoreWindRuleToSkFillType(immutableSt
ate()->fillRule()); | 1202 SkPath::FillType temporaryFillType = WebCoreWindRuleToSkFillType(immutableSt
ate()->fillRule()); |
1074 path.setFillType(temporaryFillType); | 1203 path.setFillType(temporaryFillType); |
1075 | 1204 |
1076 drawPath(path, immutableState()->fillPaint()); | 1205 drawPath(path, immutableState()->fillPaint()); |
1077 | 1206 |
1078 path.setFillType(previousFillType); | 1207 path.setFillType(previousFillType); |
1079 } | 1208 } |
1080 | 1209 |
1081 void GraphicsContext::fillRect(const FloatRect& rect) | 1210 void GraphicsContext::fillRect(const FloatRect& rect) |
1082 { | 1211 { |
| 1212 if (contextDisabled()) |
| 1213 return; |
| 1214 |
1083 SkRect r = rect; | 1215 SkRect r = rect; |
1084 | 1216 |
1085 drawRect(r, immutableState()->fillPaint()); | 1217 drawRect(r, immutableState()->fillPaint()); |
1086 } | 1218 } |
1087 | 1219 |
1088 void GraphicsContext::fillRect(const FloatRect& rect, const Color& color) | 1220 void GraphicsContext::fillRect(const FloatRect& rect, const Color& color) |
1089 { | 1221 { |
| 1222 if (contextDisabled()) |
| 1223 return; |
| 1224 |
1090 SkRect r = rect; | 1225 SkRect r = rect; |
1091 SkPaint paint = immutableState()->fillPaint(); | 1226 SkPaint paint = immutableState()->fillPaint(); |
1092 paint.setColor(color.rgb()); | 1227 paint.setColor(color.rgb()); |
1093 drawRect(r, paint); | 1228 drawRect(r, paint); |
1094 } | 1229 } |
1095 | 1230 |
1096 void GraphicsContext::fillBetweenRoundedRects(const FloatRect& outer, const Floa
tSize& outerTopLeft, const FloatSize& outerTopRight, const FloatSize& outerBotto
mLeft, const FloatSize& outerBottomRight, | 1231 void GraphicsContext::fillBetweenRoundedRects(const FloatRect& outer, const Floa
tSize& outerTopLeft, const FloatSize& outerTopRight, const FloatSize& outerBotto
mLeft, const FloatSize& outerBottomRight, |
1097 const FloatRect& inner, const FloatSize& innerTopLeft, const FloatSize& inne
rTopRight, const FloatSize& innerBottomLeft, const FloatSize& innerBottomRight,
const Color& color) | 1232 const FloatRect& inner, const FloatSize& innerTopLeft, const FloatSize& inne
rTopRight, const FloatSize& innerBottomLeft, const FloatSize& innerBottomRight,
const Color& color) |
1098 { | 1233 { |
1099 ASSERT(m_canvas); | 1234 ASSERT(m_canvas); |
| 1235 if (contextDisabled()) |
| 1236 return; |
1100 | 1237 |
1101 SkVector outerRadii[4]; | 1238 SkVector outerRadii[4]; |
1102 SkVector innerRadii[4]; | 1239 SkVector innerRadii[4]; |
1103 setRadii(outerRadii, outerTopLeft, outerTopRight, outerBottomRight, outerBot
tomLeft); | 1240 setRadii(outerRadii, outerTopLeft, outerTopRight, outerBottomRight, outerBot
tomLeft); |
1104 setRadii(innerRadii, innerTopLeft, innerTopRight, innerBottomRight, innerBot
tomLeft); | 1241 setRadii(innerRadii, innerTopLeft, innerTopRight, innerBottomRight, innerBot
tomLeft); |
1105 | 1242 |
1106 SkRRect rrOuter; | 1243 SkRRect rrOuter; |
1107 SkRRect rrInner; | 1244 SkRRect rrInner; |
1108 rrOuter.setRectRadii(outer, outerRadii); | 1245 rrOuter.setRectRadii(outer, outerRadii); |
1109 rrInner.setRectRadii(inner, innerRadii); | 1246 rrInner.setRectRadii(inner, innerRadii); |
1110 | 1247 |
1111 SkPaint paint(immutableState()->fillPaint()); | 1248 SkPaint paint(immutableState()->fillPaint()); |
1112 paint.setColor(color.rgb()); | 1249 paint.setColor(color.rgb()); |
1113 | 1250 |
1114 m_canvas->drawDRRect(rrOuter, rrInner, paint); | 1251 m_canvas->drawDRRect(rrOuter, rrInner, paint); |
1115 } | 1252 } |
1116 | 1253 |
1117 void GraphicsContext::fillBetweenRoundedRects(const FloatRoundedRect& outer, con
st FloatRoundedRect& inner, const Color& color) | 1254 void GraphicsContext::fillBetweenRoundedRects(const FloatRoundedRect& outer, con
st FloatRoundedRect& inner, const Color& color) |
1118 { | 1255 { |
1119 fillBetweenRoundedRects(outer.rect(), outer.radii().topLeft(), outer.radii()
.topRight(), outer.radii().bottomLeft(), outer.radii().bottomRight(), | 1256 fillBetweenRoundedRects(outer.rect(), outer.radii().topLeft(), outer.radii()
.topRight(), outer.radii().bottomLeft(), outer.radii().bottomRight(), |
1120 inner.rect(), inner.radii().topLeft(), inner.radii().topRight(), inner.r
adii().bottomLeft(), inner.radii().bottomRight(), color); | 1257 inner.rect(), inner.radii().topLeft(), inner.radii().topRight(), inner.r
adii().bottomLeft(), inner.radii().bottomRight(), color); |
1121 } | 1258 } |
1122 | 1259 |
1123 void GraphicsContext::fillRoundedRect(const FloatRect& rect, const FloatSize& to
pLeft, const FloatSize& topRight, | 1260 void GraphicsContext::fillRoundedRect(const FloatRect& rect, const FloatSize& to
pLeft, const FloatSize& topRight, |
1124 const FloatSize& bottomLeft, const FloatSize& bottomRight, const Color& colo
r) | 1261 const FloatSize& bottomLeft, const FloatSize& bottomRight, const Color& colo
r) |
1125 { | 1262 { |
1126 ASSERT(m_canvas); | 1263 ASSERT(m_canvas); |
| 1264 if (contextDisabled()) |
| 1265 return; |
1127 | 1266 |
1128 if (topLeft.width() + topRight.width() > rect.width() | 1267 if (topLeft.width() + topRight.width() > rect.width() |
1129 || bottomLeft.width() + bottomRight.width() > rect.width() | 1268 || bottomLeft.width() + bottomRight.width() > rect.width() |
1130 || topLeft.height() + bottomLeft.height() > rect.height() | 1269 || topLeft.height() + bottomLeft.height() > rect.height() |
1131 || topRight.height() + bottomRight.height() > rect.height()) { | 1270 || topRight.height() + bottomRight.height() > rect.height()) { |
1132 // Not all the radii fit, return a rect. This matches the behavior of | 1271 // Not all the radii fit, return a rect. This matches the behavior of |
1133 // Path::createRoundedRectangle. Without this we attempt to draw a round | 1272 // Path::createRoundedRectangle. Without this we attempt to draw a round |
1134 // shadow for a square box. | 1273 // shadow for a square box. |
1135 // FIXME: this fallback code is wrong, and also duplicates related code
in FloatRoundedRect::constrainRadii, Path and SKRRect. | 1274 // FIXME: this fallback code is wrong, and also duplicates related code
in FloatRoundedRect::constrainRadii, Path and SKRRect. |
1136 fillRect(rect, color); | 1275 fillRect(rect, color); |
1137 return; | 1276 return; |
1138 } | 1277 } |
1139 | 1278 |
1140 SkVector radii[4]; | 1279 SkVector radii[4]; |
1141 setRadii(radii, topLeft, topRight, bottomRight, bottomLeft); | 1280 setRadii(radii, topLeft, topRight, bottomRight, bottomLeft); |
1142 | 1281 |
1143 SkRRect rr; | 1282 SkRRect rr; |
1144 rr.setRectRadii(rect, radii); | 1283 rr.setRectRadii(rect, radii); |
1145 | 1284 |
1146 SkPaint paint(immutableState()->fillPaint()); | 1285 SkPaint paint(immutableState()->fillPaint()); |
1147 paint.setColor(color.rgb()); | 1286 paint.setColor(color.rgb()); |
1148 | 1287 |
1149 m_canvas->drawRRect(rr, paint); | 1288 m_canvas->drawRRect(rr, paint); |
1150 } | 1289 } |
1151 | 1290 |
1152 void GraphicsContext::fillEllipse(const FloatRect& ellipse) | 1291 void GraphicsContext::fillEllipse(const FloatRect& ellipse) |
1153 { | 1292 { |
| 1293 if (contextDisabled()) |
| 1294 return; |
| 1295 |
1154 SkRect rect = ellipse; | 1296 SkRect rect = ellipse; |
1155 drawOval(rect, immutableState()->fillPaint()); | 1297 drawOval(rect, immutableState()->fillPaint()); |
1156 } | 1298 } |
1157 | 1299 |
1158 void GraphicsContext::strokePath(const Path& pathToStroke) | 1300 void GraphicsContext::strokePath(const Path& pathToStroke) |
1159 { | 1301 { |
1160 if (pathToStroke.isEmpty()) | 1302 if (contextDisabled() || pathToStroke.isEmpty()) |
1161 return; | 1303 return; |
1162 | 1304 |
1163 const SkPath& path = pathToStroke.skPath(); | 1305 const SkPath& path = pathToStroke.skPath(); |
1164 drawPath(path, immutableState()->strokePaint()); | 1306 drawPath(path, immutableState()->strokePaint()); |
1165 } | 1307 } |
1166 | 1308 |
1167 void GraphicsContext::strokeRect(const FloatRect& rect) | 1309 void GraphicsContext::strokeRect(const FloatRect& rect) |
1168 { | 1310 { |
1169 strokeRect(rect, strokeThickness()); | 1311 strokeRect(rect, strokeThickness()); |
1170 } | 1312 } |
1171 | 1313 |
1172 void GraphicsContext::strokeRect(const FloatRect& rect, float lineWidth) | 1314 void GraphicsContext::strokeRect(const FloatRect& rect, float lineWidth) |
1173 { | 1315 { |
| 1316 if (contextDisabled()) |
| 1317 return; |
| 1318 |
1174 SkPaint paint(immutableState()->strokePaint()); | 1319 SkPaint paint(immutableState()->strokePaint()); |
1175 paint.setStrokeWidth(WebCoreFloatToSkScalar(lineWidth)); | 1320 paint.setStrokeWidth(WebCoreFloatToSkScalar(lineWidth)); |
1176 // Reset the dash effect to account for the width | 1321 // Reset the dash effect to account for the width |
1177 immutableState()->strokeData().setupPaintDashPathEffect(&paint, 0); | 1322 immutableState()->strokeData().setupPaintDashPathEffect(&paint, 0); |
1178 // strokerect has special rules for CSS when the rect is degenerate: | 1323 // strokerect has special rules for CSS when the rect is degenerate: |
1179 // if width==0 && height==0, do nothing | 1324 // if width==0 && height==0, do nothing |
1180 // if width==0 || height==0, then just draw line for the other dimension | 1325 // if width==0 || height==0, then just draw line for the other dimension |
1181 SkRect r(rect); | 1326 SkRect r(rect); |
1182 bool validW = r.width() > 0; | 1327 bool validW = r.width() > 0; |
1183 bool validH = r.height() > 0; | 1328 bool validH = r.height() > 0; |
1184 if (validW && validH) { | 1329 if (validW && validH) { |
1185 drawRect(r, paint); | 1330 drawRect(r, paint); |
1186 } else if (validW || validH) { | 1331 } else if (validW || validH) { |
1187 // we are expected to respect the lineJoin, so we can't just call | 1332 // we are expected to respect the lineJoin, so we can't just call |
1188 // drawLine -- we have to create a path that doubles back on itself. | 1333 // drawLine -- we have to create a path that doubles back on itself. |
1189 SkPath path; | 1334 SkPath path; |
1190 path.moveTo(r.fLeft, r.fTop); | 1335 path.moveTo(r.fLeft, r.fTop); |
1191 path.lineTo(r.fRight, r.fBottom); | 1336 path.lineTo(r.fRight, r.fBottom); |
1192 path.close(); | 1337 path.close(); |
1193 drawPath(path, paint); | 1338 drawPath(path, paint); |
1194 } | 1339 } |
1195 } | 1340 } |
1196 | 1341 |
1197 void GraphicsContext::strokeEllipse(const FloatRect& ellipse) | 1342 void GraphicsContext::strokeEllipse(const FloatRect& ellipse) |
1198 { | 1343 { |
| 1344 if (contextDisabled()) |
| 1345 return; |
| 1346 |
1199 drawOval(ellipse, immutableState()->strokePaint()); | 1347 drawOval(ellipse, immutableState()->strokePaint()); |
1200 } | 1348 } |
1201 | 1349 |
1202 void GraphicsContext::clipRoundedRect(const FloatRoundedRect& rect, SkRegion::Op
regionOp) | 1350 void GraphicsContext::clipRoundedRect(const FloatRoundedRect& rect, SkRegion::Op
regionOp) |
1203 { | 1351 { |
| 1352 if (contextDisabled()) |
| 1353 return; |
| 1354 |
1204 if (!rect.isRounded()) { | 1355 if (!rect.isRounded()) { |
1205 clipRect(rect.rect(), NotAntiAliased, regionOp); | 1356 clipRect(rect.rect(), NotAntiAliased, regionOp); |
1206 return; | 1357 return; |
1207 } | 1358 } |
1208 | 1359 |
1209 SkVector radii[4]; | 1360 SkVector radii[4]; |
1210 FloatRoundedRect::Radii wkRadii = rect.radii(); | 1361 FloatRoundedRect::Radii wkRadii = rect.radii(); |
1211 setRadii(radii, wkRadii.topLeft(), wkRadii.topRight(), wkRadii.bottomRight()
, wkRadii.bottomLeft()); | 1362 setRadii(radii, wkRadii.topLeft(), wkRadii.topRight(), wkRadii.bottomRight()
, wkRadii.bottomLeft()); |
1212 | 1363 |
1213 SkRRect r; | 1364 SkRRect r; |
1214 r.setRectRadii(rect.rect(), radii); | 1365 r.setRectRadii(rect.rect(), radii); |
1215 | 1366 |
1216 clipRRect(r, AntiAliased, regionOp); | 1367 clipRRect(r, AntiAliased, regionOp); |
1217 } | 1368 } |
1218 | 1369 |
1219 void GraphicsContext::clipOut(const Path& pathToClip) | 1370 void GraphicsContext::clipOut(const Path& pathToClip) |
1220 { | 1371 { |
| 1372 if (contextDisabled()) |
| 1373 return; |
| 1374 |
1221 // Use const_cast and temporarily toggle the inverse fill type instead of co
pying the path. | 1375 // Use const_cast and temporarily toggle the inverse fill type instead of co
pying the path. |
1222 SkPath& path = const_cast<SkPath&>(pathToClip.skPath()); | 1376 SkPath& path = const_cast<SkPath&>(pathToClip.skPath()); |
1223 path.toggleInverseFillType(); | 1377 path.toggleInverseFillType(); |
1224 clipPath(path, AntiAliased); | 1378 clipPath(path, AntiAliased); |
1225 path.toggleInverseFillType(); | 1379 path.toggleInverseFillType(); |
1226 } | 1380 } |
1227 | 1381 |
1228 void GraphicsContext::clipPath(const Path& pathToClip, WindRule clipRule, AntiAl
iasingMode antiAliasingMode) | 1382 void GraphicsContext::clipPath(const Path& pathToClip, WindRule clipRule, AntiAl
iasingMode antiAliasingMode) |
1229 { | 1383 { |
| 1384 if (contextDisabled()) |
| 1385 return; |
| 1386 |
1230 // Use const_cast and temporarily modify the fill type instead of copying th
e path. | 1387 // Use const_cast and temporarily modify the fill type instead of copying th
e path. |
1231 SkPath& path = const_cast<SkPath&>(pathToClip.skPath()); | 1388 SkPath& path = const_cast<SkPath&>(pathToClip.skPath()); |
1232 SkPath::FillType previousFillType = path.getFillType(); | 1389 SkPath::FillType previousFillType = path.getFillType(); |
1233 | 1390 |
1234 SkPath::FillType temporaryFillType = WebCoreWindRuleToSkFillType(clipRule); | 1391 SkPath::FillType temporaryFillType = WebCoreWindRuleToSkFillType(clipRule); |
1235 path.setFillType(temporaryFillType); | 1392 path.setFillType(temporaryFillType); |
1236 clipPath(path, antiAliasingMode); | 1393 clipPath(path, antiAliasingMode); |
1237 | 1394 |
1238 path.setFillType(previousFillType); | 1395 path.setFillType(previousFillType); |
1239 } | 1396 } |
1240 | 1397 |
1241 void GraphicsContext::clipPolygon(size_t numPoints, const FloatPoint* points, bo
ol antialiased) | 1398 void GraphicsContext::clipPolygon(size_t numPoints, const FloatPoint* points, bo
ol antialiased) |
1242 { | 1399 { |
| 1400 if (contextDisabled()) |
| 1401 return; |
| 1402 |
1243 ASSERT(numPoints > 2); | 1403 ASSERT(numPoints > 2); |
1244 | 1404 |
1245 SkPath path; | 1405 SkPath path; |
1246 setPathFromPoints(&path, numPoints, points); | 1406 setPathFromPoints(&path, numPoints, points); |
1247 clipPath(path, antialiased ? AntiAliased : NotAntiAliased); | 1407 clipPath(path, antialiased ? AntiAliased : NotAntiAliased); |
1248 } | 1408 } |
1249 | 1409 |
1250 void GraphicsContext::clipOutRoundedRect(const FloatRoundedRect& rect) | 1410 void GraphicsContext::clipOutRoundedRect(const FloatRoundedRect& rect) |
1251 { | 1411 { |
| 1412 if (contextDisabled()) |
| 1413 return; |
| 1414 |
1252 clipRoundedRect(rect, SkRegion::kDifference_Op); | 1415 clipRoundedRect(rect, SkRegion::kDifference_Op); |
1253 } | 1416 } |
1254 | 1417 |
1255 void GraphicsContext::clipRect(const SkRect& rect, AntiAliasingMode aa, SkRegion
::Op op) | 1418 void GraphicsContext::clipRect(const SkRect& rect, AntiAliasingMode aa, SkRegion
::Op op) |
1256 { | 1419 { |
1257 ASSERT(m_canvas); | 1420 ASSERT(m_canvas); |
| 1421 if (contextDisabled()) |
| 1422 return; |
| 1423 |
1258 m_canvas->clipRect(rect, op, aa == AntiAliased); | 1424 m_canvas->clipRect(rect, op, aa == AntiAliased); |
1259 } | 1425 } |
1260 | 1426 |
1261 void GraphicsContext::clipPath(const SkPath& path, AntiAliasingMode aa, SkRegion
::Op op) | 1427 void GraphicsContext::clipPath(const SkPath& path, AntiAliasingMode aa, SkRegion
::Op op) |
1262 { | 1428 { |
1263 ASSERT(m_canvas); | 1429 ASSERT(m_canvas); |
| 1430 if (contextDisabled()) |
| 1431 return; |
| 1432 |
1264 m_canvas->clipPath(path, op, aa == AntiAliased); | 1433 m_canvas->clipPath(path, op, aa == AntiAliased); |
1265 } | 1434 } |
1266 | 1435 |
1267 void GraphicsContext::clipRRect(const SkRRect& rect, AntiAliasingMode aa, SkRegi
on::Op op) | 1436 void GraphicsContext::clipRRect(const SkRRect& rect, AntiAliasingMode aa, SkRegi
on::Op op) |
1268 { | 1437 { |
1269 ASSERT(m_canvas); | 1438 ASSERT(m_canvas); |
| 1439 if (contextDisabled()) |
| 1440 return; |
| 1441 |
1270 m_canvas->clipRRect(rect, op, aa == AntiAliased); | 1442 m_canvas->clipRRect(rect, op, aa == AntiAliased); |
1271 } | 1443 } |
1272 | 1444 |
1273 void GraphicsContext::rotate(float angleInRadians) | 1445 void GraphicsContext::rotate(float angleInRadians) |
1274 { | 1446 { |
1275 ASSERT(m_canvas); | 1447 ASSERT(m_canvas); |
| 1448 if (contextDisabled()) |
| 1449 return; |
| 1450 |
1276 m_canvas->rotate(WebCoreFloatToSkScalar(angleInRadians * (180.0f / 3.1415926
5f))); | 1451 m_canvas->rotate(WebCoreFloatToSkScalar(angleInRadians * (180.0f / 3.1415926
5f))); |
1277 } | 1452 } |
1278 | 1453 |
1279 void GraphicsContext::translate(float x, float y) | 1454 void GraphicsContext::translate(float x, float y) |
1280 { | 1455 { |
1281 ASSERT(m_canvas); | 1456 ASSERT(m_canvas); |
| 1457 if (contextDisabled()) |
| 1458 return; |
1282 | 1459 |
1283 if (!x && !y) | 1460 if (!x && !y) |
1284 return; | 1461 return; |
1285 | 1462 |
1286 m_canvas->translate(WebCoreFloatToSkScalar(x), WebCoreFloatToSkScalar(y)); | 1463 m_canvas->translate(WebCoreFloatToSkScalar(x), WebCoreFloatToSkScalar(y)); |
1287 } | 1464 } |
1288 | 1465 |
1289 void GraphicsContext::scale(float x, float y) | 1466 void GraphicsContext::scale(float x, float y) |
1290 { | 1467 { |
1291 ASSERT(m_canvas); | 1468 ASSERT(m_canvas); |
| 1469 if (contextDisabled()) |
| 1470 return; |
1292 | 1471 |
1293 if (x == 1.0f && y == 1.0f) | 1472 if (x == 1.0f && y == 1.0f) |
1294 return; | 1473 return; |
1295 | 1474 |
1296 m_canvas->scale(WebCoreFloatToSkScalar(x), WebCoreFloatToSkScalar(y)); | 1475 m_canvas->scale(WebCoreFloatToSkScalar(x), WebCoreFloatToSkScalar(y)); |
1297 } | 1476 } |
1298 | 1477 |
1299 void GraphicsContext::setURLForRect(const KURL& link, const IntRect& destRect) | 1478 void GraphicsContext::setURLForRect(const KURL& link, const IntRect& destRect) |
1300 { | 1479 { |
1301 ASSERT(m_canvas); | 1480 ASSERT(m_canvas); |
| 1481 if (contextDisabled()) |
| 1482 return; |
1302 | 1483 |
1303 SkAutoDataUnref url(SkData::NewWithCString(link.string().utf8().data())); | 1484 SkAutoDataUnref url(SkData::NewWithCString(link.string().utf8().data())); |
1304 SkAnnotateRectWithURL(m_canvas, destRect, url.get()); | 1485 SkAnnotateRectWithURL(m_canvas, destRect, url.get()); |
1305 } | 1486 } |
1306 | 1487 |
1307 void GraphicsContext::setURLFragmentForRect(const String& destName, const IntRec
t& rect) | 1488 void GraphicsContext::setURLFragmentForRect(const String& destName, const IntRec
t& rect) |
1308 { | 1489 { |
1309 ASSERT(m_canvas); | 1490 ASSERT(m_canvas); |
| 1491 if (contextDisabled()) |
| 1492 return; |
1310 | 1493 |
1311 SkAutoDataUnref skDestName(SkData::NewWithCString(destName.utf8().data())); | 1494 SkAutoDataUnref skDestName(SkData::NewWithCString(destName.utf8().data())); |
1312 SkAnnotateLinkToDestination(m_canvas, rect, skDestName.get()); | 1495 SkAnnotateLinkToDestination(m_canvas, rect, skDestName.get()); |
1313 } | 1496 } |
1314 | 1497 |
1315 void GraphicsContext::addURLTargetAtPoint(const String& name, const IntPoint& po
s) | 1498 void GraphicsContext::addURLTargetAtPoint(const String& name, const IntPoint& po
s) |
1316 { | 1499 { |
1317 ASSERT(m_canvas); | 1500 ASSERT(m_canvas); |
| 1501 if (contextDisabled()) |
| 1502 return; |
1318 | 1503 |
1319 SkAutoDataUnref nameData(SkData::NewWithCString(name.utf8().data())); | 1504 SkAutoDataUnref nameData(SkData::NewWithCString(name.utf8().data())); |
1320 SkAnnotateNamedDestination(m_canvas, SkPoint::Make(pos.x(), pos.y()), nameDa
ta); | 1505 SkAnnotateNamedDestination(m_canvas, SkPoint::Make(pos.x(), pos.y()), nameDa
ta); |
1321 } | 1506 } |
1322 | 1507 |
1323 AffineTransform GraphicsContext::getCTM() const | 1508 AffineTransform GraphicsContext::getCTM() const |
1324 { | 1509 { |
| 1510 if (contextDisabled()) |
| 1511 return AffineTransform(); |
| 1512 |
1325 SkMatrix m = getTotalMatrix(); | 1513 SkMatrix m = getTotalMatrix(); |
1326 return AffineTransform(SkScalarToDouble(m.getScaleX()), | 1514 return AffineTransform(SkScalarToDouble(m.getScaleX()), |
1327 SkScalarToDouble(m.getSkewY()), | 1515 SkScalarToDouble(m.getSkewY()), |
1328 SkScalarToDouble(m.getSkewX()), | 1516 SkScalarToDouble(m.getSkewX()), |
1329 SkScalarToDouble(m.getScaleY()), | 1517 SkScalarToDouble(m.getScaleY()), |
1330 SkScalarToDouble(m.getTranslateX()), | 1518 SkScalarToDouble(m.getTranslateX()), |
1331 SkScalarToDouble(m.getTranslateY())); | 1519 SkScalarToDouble(m.getTranslateY())); |
1332 } | 1520 } |
1333 | 1521 |
1334 void GraphicsContext::concatCTM(const AffineTransform& affine) | 1522 void GraphicsContext::concatCTM(const AffineTransform& affine) |
1335 { | 1523 { |
1336 concat(affineTransformToSkMatrix(affine)); | 1524 concat(affineTransformToSkMatrix(affine)); |
1337 } | 1525 } |
1338 | 1526 |
1339 void GraphicsContext::setCTM(const AffineTransform& affine) | 1527 void GraphicsContext::setCTM(const AffineTransform& affine) |
1340 { | 1528 { |
1341 setMatrix(affineTransformToSkMatrix(affine)); | 1529 setMatrix(affineTransformToSkMatrix(affine)); |
1342 } | 1530 } |
1343 | 1531 |
1344 void GraphicsContext::fillRect(const FloatRect& rect, const Color& color, SkXfer
mode::Mode op) | 1532 void GraphicsContext::fillRect(const FloatRect& rect, const Color& color, SkXfer
mode::Mode op) |
1345 { | 1533 { |
| 1534 if (contextDisabled()) |
| 1535 return; |
| 1536 |
1346 SkXfermode::Mode previousOperation = compositeOperation(); | 1537 SkXfermode::Mode previousOperation = compositeOperation(); |
1347 setCompositeOperation(op); | 1538 setCompositeOperation(op); |
1348 fillRect(rect, color); | 1539 fillRect(rect, color); |
1349 setCompositeOperation(previousOperation); | 1540 setCompositeOperation(previousOperation); |
1350 } | 1541 } |
1351 | 1542 |
1352 void GraphicsContext::fillRoundedRect(const FloatRoundedRect& rect, const Color&
color) | 1543 void GraphicsContext::fillRoundedRect(const FloatRoundedRect& rect, const Color&
color) |
1353 { | 1544 { |
| 1545 if (contextDisabled()) |
| 1546 return; |
| 1547 |
1354 if (rect.isRounded()) | 1548 if (rect.isRounded()) |
1355 fillRoundedRect(rect.rect(), rect.radii().topLeft(), rect.radii().topRig
ht(), rect.radii().bottomLeft(), rect.radii().bottomRight(), color); | 1549 fillRoundedRect(rect.rect(), rect.radii().topLeft(), rect.radii().topRig
ht(), rect.radii().bottomLeft(), rect.radii().bottomRight(), color); |
1356 else | 1550 else |
1357 fillRect(rect.rect(), color); | 1551 fillRect(rect.rect(), color); |
1358 } | 1552 } |
1359 | 1553 |
1360 void GraphicsContext::fillRectWithRoundedHole(const FloatRect& rect, const Float
RoundedRect& roundedHoleRect, const Color& color) | 1554 void GraphicsContext::fillRectWithRoundedHole(const FloatRect& rect, const Float
RoundedRect& roundedHoleRect, const Color& color) |
1361 { | 1555 { |
| 1556 if (contextDisabled()) |
| 1557 return; |
| 1558 |
1362 Path path; | 1559 Path path; |
1363 path.addRect(rect); | 1560 path.addRect(rect); |
1364 | 1561 |
1365 if (!roundedHoleRect.radii().isZero()) | 1562 if (!roundedHoleRect.radii().isZero()) |
1366 path.addRoundedRect(roundedHoleRect); | 1563 path.addRoundedRect(roundedHoleRect); |
1367 else | 1564 else |
1368 path.addRect(roundedHoleRect.rect()); | 1565 path.addRect(roundedHoleRect.rect()); |
1369 | 1566 |
1370 WindRule oldFillRule = fillRule(); | 1567 WindRule oldFillRule = fillRule(); |
1371 Color oldFillColor = fillColor(); | 1568 Color oldFillColor = fillColor(); |
1372 | 1569 |
1373 setFillRule(RULE_EVENODD); | 1570 setFillRule(RULE_EVENODD); |
1374 setFillColor(color); | 1571 setFillColor(color); |
1375 | 1572 |
1376 fillPath(path); | 1573 fillPath(path); |
1377 | 1574 |
1378 setFillRule(oldFillRule); | 1575 setFillRule(oldFillRule); |
1379 setFillColor(oldFillColor); | 1576 setFillColor(oldFillColor); |
1380 } | 1577 } |
1381 | 1578 |
1382 void GraphicsContext::clearRect(const FloatRect& rect) | 1579 void GraphicsContext::clearRect(const FloatRect& rect) |
1383 { | 1580 { |
| 1581 if (contextDisabled()) |
| 1582 return; |
| 1583 |
1384 SkRect r = rect; | 1584 SkRect r = rect; |
1385 SkPaint paint(immutableState()->fillPaint()); | 1585 SkPaint paint(immutableState()->fillPaint()); |
1386 paint.setXfermodeMode(SkXfermode::kClear_Mode); | 1586 paint.setXfermodeMode(SkXfermode::kClear_Mode); |
1387 drawRect(r, paint); | 1587 drawRect(r, paint); |
1388 } | 1588 } |
1389 | 1589 |
1390 void GraphicsContext::adjustLineToPixelBoundaries(FloatPoint& p1, FloatPoint& p2
, float strokeWidth, StrokeStyle penStyle) | 1590 void GraphicsContext::adjustLineToPixelBoundaries(FloatPoint& p1, FloatPoint& p2
, float strokeWidth, StrokeStyle penStyle) |
1391 { | 1591 { |
1392 // For odd widths, we add in 0.5 to the appropriate x/y so that the float ar
ithmetic | 1592 // For odd widths, we add in 0.5 to the appropriate x/y so that the float ar
ithmetic |
1393 // works out. For example, with a border width of 3, WebKit will pass us (y
1+y2)/2, e.g., | 1593 // works out. For example, with a border width of 3, WebKit will pass us (y
1+y2)/2, e.g., |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1629 // being returned from computeInterpolationQuality. | 1829 // being returned from computeInterpolationQuality. |
1630 resampling = InterpolationLow; | 1830 resampling = InterpolationLow; |
1631 } | 1831 } |
1632 resampling = limitInterpolationQuality(this, resampling); | 1832 resampling = limitInterpolationQuality(this, resampling); |
1633 paint->setFilterLevel(static_cast<SkPaint::FilterLevel>(resampling)); | 1833 paint->setFilterLevel(static_cast<SkPaint::FilterLevel>(resampling)); |
1634 | 1834 |
1635 return initialSaveCount; | 1835 return initialSaveCount; |
1636 } | 1836 } |
1637 | 1837 |
1638 } // namespace blink | 1838 } // namespace blink |
OLD | NEW |