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 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
131 { | 131 { |
132 // FIXME: Do some tests to determine how many states are typically used, and allocate | 132 // FIXME: Do some tests to determine how many states are typically used, and allocate |
133 // several here. | 133 // several here. |
134 m_paintStateStack.append(GraphicsContextState::create()); | 134 m_paintStateStack.append(GraphicsContextState::create()); |
135 m_paintState = m_paintStateStack.last().get(); | 135 m_paintState = m_paintStateStack.last().get(); |
136 } | 136 } |
137 | 137 |
138 GraphicsContext::~GraphicsContext() | 138 GraphicsContext::~GraphicsContext() |
139 { | 139 { |
140 ASSERT(!m_paintStateIndex); | 140 ASSERT(!m_paintStateIndex); |
141 ASSERT(!m_paintState->m_saveCount); | 141 ASSERT(!m_paintState->saveCount()); |
142 ASSERT(!m_annotationCount); | 142 ASSERT(!m_annotationCount); |
143 ASSERT(!m_layerCount); | 143 ASSERT(!m_layerCount); |
144 ASSERT(m_recordingStateStack.isEmpty()); | 144 ASSERT(m_recordingStateStack.isEmpty()); |
145 } | 145 } |
146 | 146 |
147 const SkBitmap* GraphicsContext::bitmap() const | 147 const SkBitmap* GraphicsContext::bitmap() const |
148 { | 148 { |
149 TRACE_EVENT0("skia", "GraphicsContext::bitmap"); | 149 TRACE_EVENT0("skia", "GraphicsContext::bitmap"); |
150 return &m_canvas->getDevice()->accessBitmap(false); | 150 return &m_canvas->getDevice()->accessBitmap(false); |
151 } | 151 } |
152 | 152 |
153 const SkBitmap& GraphicsContext::layerBitmap(AccessMode access) const | 153 const SkBitmap& GraphicsContext::layerBitmap(AccessMode access) const |
154 { | 154 { |
155 return m_canvas->getTopDevice()->accessBitmap(access == ReadWrite); | 155 return m_canvas->getTopDevice()->accessBitmap(access == ReadWrite); |
156 } | 156 } |
157 | 157 |
158 void GraphicsContext::save() | 158 void GraphicsContext::save() |
159 { | 159 { |
160 if (paintingDisabled()) | 160 if (paintingDisabled()) |
161 return; | 161 return; |
162 | 162 |
163 m_paintState->m_saveCount++; | 163 m_paintState->incrementSaveCount(); |
164 | 164 |
165 m_canvasStateStack.append(CanvasSaveState(m_canvasSaveFlags, m_canvas->getSa veCount())); | 165 m_canvasStateStack.append(CanvasSaveState(m_canvasSaveFlags, m_canvas->getSa veCount())); |
166 m_canvasSaveFlags |= SkCanvas::kMatrixClip_SaveFlag; | 166 m_canvasSaveFlags |= SkCanvas::kMatrixClip_SaveFlag; |
167 } | 167 } |
168 | 168 |
169 void GraphicsContext::restore() | 169 void GraphicsContext::restore() |
170 { | 170 { |
171 if (paintingDisabled()) | 171 if (paintingDisabled()) |
172 return; | 172 return; |
173 | 173 |
174 if (!m_paintStateIndex && !m_paintState->m_saveCount) { | 174 if (!m_paintStateIndex && !m_paintState->saveCount()) { |
175 WTF_LOG_ERROR("ERROR void GraphicsContext::restore() stack is empty"); | 175 WTF_LOG_ERROR("ERROR void GraphicsContext::restore() stack is empty"); |
176 return; | 176 return; |
177 } | 177 } |
178 | 178 |
179 if (m_paintState->m_saveCount) { | 179 if (m_paintState->saveCount()) { |
180 m_paintState->m_saveCount--; | 180 m_paintState->decrementSaveCount(); |
181 } else { | 181 } else { |
182 m_paintStateIndex--; | 182 m_paintStateIndex--; |
183 m_paintState = m_paintStateStack[m_paintStateIndex].get(); | 183 m_paintState = m_paintStateStack[m_paintStateIndex].get(); |
184 } | 184 } |
185 | 185 |
186 CanvasSaveState savedState = m_canvasStateStack.last(); | 186 CanvasSaveState savedState = m_canvasStateStack.last(); |
187 m_canvasStateStack.removeLast(); | 187 m_canvasStateStack.removeLast(); |
188 m_canvasSaveFlags = savedState.m_flags; | 188 m_canvasSaveFlags = savedState.m_flags; |
189 m_canvas->restoreToCount(savedState.m_restoreCount); | 189 m_canvas->restoreToCount(savedState.m_restoreCount); |
190 } | 190 } |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
240 return; | 240 return; |
241 | 241 |
242 canvas()->endCommentGroup(); | 242 canvas()->endCommentGroup(); |
243 | 243 |
244 ASSERT(m_annotationCount > 0); | 244 ASSERT(m_annotationCount > 0); |
245 #if !ASSERT_DISABLED | 245 #if !ASSERT_DISABLED |
246 --m_annotationCount; | 246 --m_annotationCount; |
247 #endif | 247 #endif |
248 } | 248 } |
249 | 249 |
250 void GraphicsContext::setStrokeColor(const Color& color) | |
251 { | |
252 GraphicsContextState* stateToSet = mutableState(); | |
253 stateToSet->m_strokeData.setColor(color); | |
254 stateToSet->m_strokeData.clearGradient(); | |
255 stateToSet->m_strokeData.clearPattern(); | |
256 } | |
257 | |
258 void GraphicsContext::setStrokePattern(PassRefPtr<Pattern> pattern) | 250 void GraphicsContext::setStrokePattern(PassRefPtr<Pattern> pattern) |
259 { | 251 { |
260 if (paintingDisabled()) | 252 if (paintingDisabled()) |
261 return; | 253 return; |
262 | 254 |
263 ASSERT(pattern); | 255 ASSERT(pattern); |
264 if (!pattern) { | 256 if (!pattern) { |
265 setStrokeColor(Color::black); | 257 setStrokeColor(Color::black); |
266 return; | 258 return; |
267 } | 259 } |
268 GraphicsContextState* stateToSet = mutableState(); | 260 mutableState()->setStrokePattern(pattern); |
269 stateToSet->m_strokeData.clearGradient(); | |
270 stateToSet->m_strokeData.setPattern(pattern); | |
271 } | 261 } |
272 | 262 |
273 void GraphicsContext::setStrokeGradient(PassRefPtr<Gradient> gradient) | 263 void GraphicsContext::setStrokeGradient(PassRefPtr<Gradient> gradient) |
274 { | 264 { |
275 if (paintingDisabled()) | 265 if (paintingDisabled()) |
276 return; | 266 return; |
277 | 267 |
278 ASSERT(gradient); | 268 ASSERT(gradient); |
279 if (!gradient) { | 269 if (!gradient) { |
280 setStrokeColor(Color::black); | 270 setStrokeColor(Color::black); |
281 return; | 271 return; |
282 } | 272 } |
283 GraphicsContextState* stateToSet = mutableState(); | 273 mutableState()->setStrokeGradient(gradient); |
284 stateToSet->m_strokeData.setGradient(gradient); | |
285 stateToSet->m_strokeData.clearPattern(); | |
286 } | |
287 | |
288 void GraphicsContext::setFillColor(const Color& color) | |
289 { | |
290 GraphicsContextState* stateToSet = mutableState(); | |
291 stateToSet->m_fillColor = color; | |
292 stateToSet->m_fillGradient.clear(); | |
293 stateToSet->m_fillPattern.clear(); | |
294 } | 274 } |
295 | 275 |
296 void GraphicsContext::setFillPattern(PassRefPtr<Pattern> pattern) | 276 void GraphicsContext::setFillPattern(PassRefPtr<Pattern> pattern) |
297 { | 277 { |
298 if (paintingDisabled()) | 278 if (paintingDisabled()) |
299 return; | 279 return; |
300 | 280 |
301 ASSERT(pattern); | 281 ASSERT(pattern); |
302 if (!pattern) { | 282 if (!pattern) { |
303 setFillColor(Color::black); | 283 setFillColor(Color::black); |
304 return; | 284 return; |
305 } | 285 } |
306 | 286 |
307 GraphicsContextState* stateToSet = mutableState(); | 287 mutableState()->setFillPattern(pattern); |
308 stateToSet->m_fillGradient.clear(); | |
309 stateToSet->m_fillPattern = pattern; | |
310 } | 288 } |
311 | 289 |
312 void GraphicsContext::setFillGradient(PassRefPtr<Gradient> gradient) | 290 void GraphicsContext::setFillGradient(PassRefPtr<Gradient> gradient) |
313 { | 291 { |
314 if (paintingDisabled()) | 292 if (paintingDisabled()) |
315 return; | 293 return; |
316 | 294 |
317 ASSERT(gradient); | 295 ASSERT(gradient); |
318 if (!gradient) { | 296 if (!gradient) { |
319 setFillColor(Color::black); | 297 setFillColor(Color::black); |
320 return; | 298 return; |
321 } | 299 } |
322 | 300 |
323 GraphicsContextState* stateToSet = mutableState(); | 301 mutableState()->setFillGradient(gradient); |
324 stateToSet->m_fillGradient = gradient; | |
325 stateToSet->m_fillPattern.clear(); | |
326 } | 302 } |
327 | 303 |
328 void GraphicsContext::setShadow(const FloatSize& offset, float blur, const Color & color, | 304 void GraphicsContext::setShadow(const FloatSize& offset, float blur, const Color & color, |
329 DrawLooperBuilder::ShadowTransformMode shadowTransformMode, | 305 DrawLooperBuilder::ShadowTransformMode shadowTransformMode, |
330 DrawLooperBuilder::ShadowAlphaMode shadowAlphaMode) | 306 DrawLooperBuilder::ShadowAlphaMode shadowAlphaMode) |
331 { | 307 { |
332 if (paintingDisabled()) | 308 if (paintingDisabled()) |
333 return; | 309 return; |
334 | 310 |
335 if (!color.alpha() || (!offset.width() && !offset.height() && !blur)) { | 311 if (!color.alpha() || (!offset.width() && !offset.height() && !blur)) { |
336 clearShadow(); | 312 clearShadow(); |
337 return; | 313 return; |
338 } | 314 } |
339 | 315 |
340 OwnPtr<DrawLooperBuilder> drawLooperBuilder = DrawLooperBuilder::create(); | 316 OwnPtr<DrawLooperBuilder> drawLooperBuilder = DrawLooperBuilder::create(); |
341 drawLooperBuilder->addShadow(offset, blur, color, shadowTransformMode, shado wAlphaMode); | 317 drawLooperBuilder->addShadow(offset, blur, color, shadowTransformMode, shado wAlphaMode); |
342 drawLooperBuilder->addUnmodifiedContent(); | 318 drawLooperBuilder->addUnmodifiedContent(); |
343 setDrawLooper(drawLooperBuilder.release()); | 319 setDrawLooper(drawLooperBuilder.release()); |
344 } | 320 } |
345 | 321 |
346 void GraphicsContext::setDrawLooper(PassOwnPtr<DrawLooperBuilder> drawLooperBuil der) | 322 void GraphicsContext::setDrawLooper(PassOwnPtr<DrawLooperBuilder> drawLooperBuil der) |
347 { | 323 { |
348 if (paintingDisabled()) | 324 if (paintingDisabled()) |
349 return; | 325 return; |
350 | 326 |
351 mutableState()->m_looper = drawLooperBuilder->detachDrawLooper(); | 327 mutableState()->setDrawLooper(drawLooperBuilder->detachDrawLooper()); |
352 } | 328 } |
353 | 329 |
354 void GraphicsContext::clearDrawLooper() | 330 void GraphicsContext::clearDrawLooper() |
355 { | 331 { |
356 if (paintingDisabled()) | 332 if (paintingDisabled()) |
357 return; | 333 return; |
358 | 334 |
359 mutableState()->m_looper.clear(); | 335 mutableState()->clearDrawLooper(); |
360 } | 336 } |
361 | 337 |
362 bool GraphicsContext::hasShadow() const | 338 bool GraphicsContext::hasShadow() const |
363 { | 339 { |
364 return !!immutableState()->m_looper; | 340 return !!immutableState()->drawLooper(); |
365 } | |
366 | |
367 int GraphicsContext::getNormalizedAlpha() const | |
368 { | |
369 int alpha = roundf(immutableState()->m_alpha * 256); | |
370 if (alpha > 255) | |
371 alpha = 255; | |
372 else if (alpha < 0) | |
373 alpha = 0; | |
374 return alpha; | |
375 } | 341 } |
376 | 342 |
377 FloatRect GraphicsContext::getClipBounds() const | 343 FloatRect GraphicsContext::getClipBounds() const |
378 { | 344 { |
379 if (paintingDisabled()) | 345 if (paintingDisabled()) |
380 return FloatRect(); | 346 return FloatRect(); |
381 SkRect rect; | 347 SkRect rect; |
382 if (!m_canvas->getClipBounds(&rect)) | 348 if (!m_canvas->getClipBounds(&rect)) |
383 return FloatRect(); | 349 return FloatRect(); |
384 return FloatRect(rect); | 350 return FloatRect(rect); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
436 // collapsed. Therefore, subpixel text is disabled when we are drawing | 402 // collapsed. Therefore, subpixel text is disabled when we are drawing |
437 // onto a layer. | 403 // onto a layer. |
438 if (paintingDisabled() || isDrawingToLayer() || !isCertainlyOpaque()) | 404 if (paintingDisabled() || isDrawingToLayer() || !isCertainlyOpaque()) |
439 return false; | 405 return false; |
440 | 406 |
441 return shouldSmoothFonts(); | 407 return shouldSmoothFonts(); |
442 } | 408 } |
443 | 409 |
444 void GraphicsContext::setCompositeOperation(CompositeOperator compositeOperation , WebBlendMode blendMode) | 410 void GraphicsContext::setCompositeOperation(CompositeOperator compositeOperation , WebBlendMode blendMode) |
445 { | 411 { |
446 GraphicsContextState* stateToSet = mutableState(); | 412 mutableState()->setCompositeOperation(compositeOperation, blendMode); |
447 stateToSet->m_compositeOperator = compositeOperation; | |
448 stateToSet->m_blendMode = blendMode; | |
449 stateToSet->m_xferMode = WebCoreCompositeToSkiaComposite(compositeOperation, blendMode); | |
450 } | 413 } |
451 | 414 |
452 SkColorFilter* GraphicsContext::colorFilter() | 415 SkColorFilter* GraphicsContext::colorFilter() |
453 { | 416 { |
454 return immutableState()->m_colorFilter.get(); | 417 return immutableState()->colorFilter(); |
455 } | 418 } |
456 | 419 |
457 void GraphicsContext::setColorFilter(ColorFilter colorFilter) | 420 void GraphicsContext::setColorFilter(ColorFilter colorFilter) |
458 { | 421 { |
459 GraphicsContextState* stateToSet = mutableState(); | 422 GraphicsContextState* stateToSet = mutableState(); |
460 | 423 |
461 // We only support one active color filter at the moment. If (when) this bec omes a problem, | 424 // We only support one active color filter at the moment. If (when) this bec omes a problem, |
462 // we should switch to using color filter chains (Skia work in progress). | 425 // we should switch to using color filter chains (Skia work in progress). |
463 ASSERT(!stateToSet->m_colorFilter); | 426 ASSERT(!stateToSet->colorFilter()); |
464 stateToSet->m_colorFilter = WebCoreColorFilterToSkiaColorFilter(colorFilter) ; | 427 stateToSet->setColorFilter(WebCoreColorFilterToSkiaColorFilter(colorFilter)) ; |
465 } | 428 } |
466 | 429 |
467 bool GraphicsContext::readPixels(SkBitmap* bitmap, int x, int y, SkCanvas::Confi g8888 config8888) | 430 bool GraphicsContext::readPixels(SkBitmap* bitmap, int x, int y, SkCanvas::Confi g8888 config8888) |
468 { | 431 { |
469 if (paintingDisabled()) | 432 if (paintingDisabled()) |
470 return false; | 433 return false; |
471 | 434 |
472 return m_canvas->readPixels(bitmap, x, y, config8888); | 435 return m_canvas->readPixels(bitmap, x, y, config8888); |
473 } | 436 } |
474 | 437 |
(...skipping 16 matching lines...) Expand all Loading... | |
491 if (matrix.isIdentity()) | 454 if (matrix.isIdentity()) |
492 return true; | 455 return true; |
493 | 456 |
494 realizeCanvasSave(SkCanvas::kMatrix_SaveFlag); | 457 realizeCanvasSave(SkCanvas::kMatrix_SaveFlag); |
495 | 458 |
496 return m_canvas->concat(matrix); | 459 return m_canvas->concat(matrix); |
497 } | 460 } |
498 | 461 |
499 void GraphicsContext::beginTransparencyLayer(float opacity, const FloatRect* bou nds) | 462 void GraphicsContext::beginTransparencyLayer(float opacity, const FloatRect* bou nds) |
500 { | 463 { |
501 beginLayer(opacity, immutableState()->m_compositeOperator, bounds); | 464 beginLayer(opacity, immutableState()->compositeOperator(), bounds); |
502 } | 465 } |
503 | 466 |
504 void GraphicsContext::beginLayer(float opacity, CompositeOperator op, const Floa tRect* bounds, ColorFilter colorFilter, ImageFilter* imageFilter) | 467 void GraphicsContext::beginLayer(float opacity, CompositeOperator op, const Floa tRect* bounds, ColorFilter colorFilter, ImageFilter* imageFilter) |
505 { | 468 { |
506 if (paintingDisabled()) | 469 if (paintingDisabled()) |
507 return; | 470 return; |
508 | 471 |
509 // We need the "alpha" layer flag here because the base layer is opaque | 472 // We need the "alpha" layer flag here because the base layer is opaque |
510 // (the surface of the page) but layers on top may have transparent parts. | 473 // (the surface of the page) but layers on top may have transparent parts. |
511 // Without explicitly setting the alpha flag, the layer will inherit the | 474 // Without explicitly setting the alpha flag, the layer will inherit the |
512 // opaque setting of the base and some things won't work properly. | 475 // opaque setting of the base and some things won't work properly. |
513 SkCanvas::SaveFlags saveFlags = static_cast<SkCanvas::SaveFlags>(SkCanvas::k HasAlphaLayer_SaveFlag | SkCanvas::kFullColorLayer_SaveFlag); | 476 SkCanvas::SaveFlags saveFlags = static_cast<SkCanvas::SaveFlags>(SkCanvas::k HasAlphaLayer_SaveFlag | SkCanvas::kFullColorLayer_SaveFlag); |
514 | 477 |
515 SkPaint layerPaint; | 478 SkPaint layerPaint; |
516 layerPaint.setAlpha(static_cast<unsigned char>(opacity * 255)); | 479 layerPaint.setAlpha(static_cast<unsigned char>(opacity * 255)); |
517 layerPaint.setXfermode(WebCoreCompositeToSkiaComposite(op, m_paintState->m_b lendMode).get()); | 480 layerPaint.setXfermode(WebCoreCompositeToSkiaComposite(op, m_paintState->ble ndMode()).get()); |
518 layerPaint.setColorFilter(WebCoreColorFilterToSkiaColorFilter(colorFilter).g et()); | 481 layerPaint.setColorFilter(WebCoreColorFilterToSkiaColorFilter(colorFilter).g et()); |
519 layerPaint.setImageFilter(imageFilter); | 482 layerPaint.setImageFilter(imageFilter); |
520 | 483 |
521 // Filters will adjust the clip to accomodate for filter bounds, but | 484 // Filters will adjust the clip to accomodate for filter bounds, but |
522 // need the kClipToLayer_SaveFlag to do so. We also save the clip here, so | 485 // need the kClipToLayer_SaveFlag to do so. We also save the clip here, so |
523 // it is restored back before the filtered layer is drawn in restore(). | 486 // it is restored back before the filtered layer is drawn in restore(). |
524 // The matrix also needs to be saved, in order to be correctly passed to | 487 // The matrix also needs to be saved, in order to be correctly passed to |
525 // the filter CTM during restore(). | 488 // the filter CTM during restore(). |
526 if (imageFilter) | 489 if (imageFilter) |
527 saveFlags = SkCanvas::kARGB_ClipLayer_SaveFlag; | 490 saveFlags = SkCanvas::kARGB_ClipLayer_SaveFlag; |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
610 | 573 |
611 if (bounds.x() || bounds.y()) | 574 if (bounds.x() || bounds.y()) |
612 m_canvas->translate(-bounds.x(), -bounds.y()); | 575 m_canvas->translate(-bounds.x(), -bounds.y()); |
613 } | 576 } |
614 | 577 |
615 void GraphicsContext::setupPaintForFilling(SkPaint* paint) const | 578 void GraphicsContext::setupPaintForFilling(SkPaint* paint) const |
616 { | 579 { |
617 if (paintingDisabled()) | 580 if (paintingDisabled()) |
618 return; | 581 return; |
619 | 582 |
620 setupPaintCommon(paint); | 583 *paint = immutableState()->fillPaint(); |
621 | |
622 setupShader(paint, immutableState()->m_fillGradient.get(), immutableState()- >m_fillPattern.get(), immutableState()->m_fillColor.rgb()); | |
623 } | 584 } |
624 | 585 |
625 float GraphicsContext::setupPaintForStroking(SkPaint* paint, int length) const | 586 void GraphicsContext::setupPaintForStroking(SkPaint* paint, int length) const |
626 { | 587 { |
627 if (paintingDisabled()) | 588 if (paintingDisabled()) |
628 return 0.0f; | 589 return; |
629 | 590 |
630 setupPaintCommon(paint); | 591 *paint = immutableState()->strokePaint(); |
631 | 592 immutableState()->strokeData().setupPaintDashPathEffect(paint, length); |
Stephen White
2014/03/04 15:24:13
Seems a little surprising not to handle this autom
| |
632 setupShader(paint, immutableState()->m_strokeData.gradient(), immutableState ()->m_strokeData.pattern(), | |
633 immutableState()->m_strokeData.color().rgb()); | |
634 | |
635 return immutableState()->m_strokeData.setupPaint(paint, length); | |
636 } | 593 } |
637 | 594 |
638 void GraphicsContext::drawConvexPolygon(size_t numPoints, const FloatPoint* poin ts, bool shouldAntialias) | 595 void GraphicsContext::drawConvexPolygon(size_t numPoints, const FloatPoint* poin ts, bool shouldAntialias) |
639 { | 596 { |
640 if (paintingDisabled()) | 597 if (paintingDisabled()) |
641 return; | 598 return; |
642 | 599 |
643 if (numPoints <= 1) | 600 if (numPoints <= 1) |
644 return; | 601 return; |
645 | 602 |
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1003 void GraphicsContext::drawRect(const IntRect& rect) | 960 void GraphicsContext::drawRect(const IntRect& rect) |
1004 { | 961 { |
1005 if (paintingDisabled()) | 962 if (paintingDisabled()) |
1006 return; | 963 return; |
1007 | 964 |
1008 ASSERT(!rect.isEmpty()); | 965 ASSERT(!rect.isEmpty()); |
1009 if (rect.isEmpty()) | 966 if (rect.isEmpty()) |
1010 return; | 967 return; |
1011 | 968 |
1012 SkRect skRect = rect; | 969 SkRect skRect = rect; |
1013 SkPaint paint; | 970 int fillcolorNotTransparent = immutableState()->fillColor().rgb() & 0xFF0000 00; |
1014 int fillcolorNotTransparent = m_paintState->m_fillColor.rgb() & 0xFF000000; | 971 if (fillcolorNotTransparent) |
1015 if (fillcolorNotTransparent) { | 972 drawRect(skRect, immutableState()->fillPaint()); |
1016 setupPaintForFilling(&paint); | |
1017 drawRect(skRect, paint); | |
1018 } | |
1019 | 973 |
1020 if (m_paintState->m_strokeData.style() != NoStroke && (m_paintState->m_strok eData.color().rgb() & 0xFF000000)) { | 974 if (immutableState()->strokeData().style() != NoStroke && (immutableState()- >strokeData().color().rgb() & 0xFF000000)) { |
1021 // We do a fill of four rects to simulate the stroke of a border. | 975 // We do a fill of four rects to simulate the stroke of a border. |
1022 paint.reset(); | 976 SkPaint paint; |
1023 setupPaintForFilling(&paint); | 977 setupPaintForFilling(&paint); |
Stephen White
2014/03/04 15:24:13
IIRC, Florin's patch should get rid of this one; m
| |
1024 // need to jam in the strokeColor | 978 // need to jam in the strokeColor |
1025 paint.setColor(this->effectiveStrokeColor()); | 979 paint.setColor(immutableState()->effectiveStrokeColor()); |
1026 | 980 |
1027 SkRect topBorder = { skRect.fLeft, skRect.fTop, skRect.fRight, skRect.fT op + 1 }; | 981 SkRect topBorder = { skRect.fLeft, skRect.fTop, skRect.fRight, skRect.fT op + 1 }; |
1028 drawRect(topBorder, paint); | 982 drawRect(topBorder, paint); |
1029 SkRect bottomBorder = { skRect.fLeft, skRect.fBottom - 1, skRect.fRight, skRect.fBottom }; | 983 SkRect bottomBorder = { skRect.fLeft, skRect.fBottom - 1, skRect.fRight, skRect.fBottom }; |
1030 drawRect(bottomBorder, paint); | 984 drawRect(bottomBorder, paint); |
1031 SkRect leftBorder = { skRect.fLeft, skRect.fTop + 1, skRect.fLeft + 1, s kRect.fBottom - 1 }; | 985 SkRect leftBorder = { skRect.fLeft, skRect.fTop + 1, skRect.fLeft + 1, s kRect.fBottom - 1 }; |
1032 drawRect(leftBorder, paint); | 986 drawRect(leftBorder, paint); |
1033 SkRect rightBorder = { skRect.fRight - 1, skRect.fTop + 1, skRect.fRight , skRect.fBottom - 1 }; | 987 SkRect rightBorder = { skRect.fRight - 1, skRect.fTop + 1, skRect.fRight , skRect.fBottom - 1 }; |
1034 drawRect(rightBorder, paint); | 988 drawRect(rightBorder, paint); |
1035 } | 989 } |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1258 m_opaqueRegion.didDrawRect(this, rect, *paint, &bitmap); | 1212 m_opaqueRegion.didDrawRect(this, rect, *paint, &bitmap); |
1259 } | 1213 } |
1260 } | 1214 } |
1261 | 1215 |
1262 void GraphicsContext::drawBitmapRect(const SkBitmap& bitmap, const SkRect* src, | 1216 void GraphicsContext::drawBitmapRect(const SkBitmap& bitmap, const SkRect* src, |
1263 const SkRect& dst, const SkPaint* paint) | 1217 const SkRect& dst, const SkPaint* paint) |
1264 { | 1218 { |
1265 if (paintingDisabled()) | 1219 if (paintingDisabled()) |
1266 return; | 1220 return; |
1267 | 1221 |
1268 SkCanvas::DrawBitmapRectFlags flags = m_paintState->m_shouldClampToSourceRec t ? SkCanvas::kNone_DrawBitmapRectFlag : SkCanvas::kBleed_DrawBitmapRectFlag; | 1222 SkCanvas::DrawBitmapRectFlags flags = |
1223 immutableState()->shouldClampToSourceRect() ? SkCanvas::kNone_DrawBitmap RectFlag : SkCanvas::kBleed_DrawBitmapRectFlag; | |
1269 | 1224 |
1270 m_canvas->drawBitmapRectToRect(bitmap, src, dst, paint, flags); | 1225 m_canvas->drawBitmapRectToRect(bitmap, src, dst, paint, flags); |
1271 | 1226 |
1272 if (m_trackOpaqueRegion) | 1227 if (m_trackOpaqueRegion) |
1273 m_opaqueRegion.didDrawRect(this, dst, *paint, &bitmap); | 1228 m_opaqueRegion.didDrawRect(this, dst, *paint, &bitmap); |
1274 } | 1229 } |
1275 | 1230 |
1276 void GraphicsContext::drawOval(const SkRect& oval, const SkPaint& paint) | 1231 void GraphicsContext::drawOval(const SkRect& oval, const SkPaint& paint) |
1277 { | 1232 { |
1278 if (paintingDisabled()) | 1233 if (paintingDisabled()) |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1356 | 1311 |
1357 void GraphicsContext::fillPath(const Path& pathToFill) | 1312 void GraphicsContext::fillPath(const Path& pathToFill) |
1358 { | 1313 { |
1359 if (paintingDisabled() || pathToFill.isEmpty()) | 1314 if (paintingDisabled() || pathToFill.isEmpty()) |
1360 return; | 1315 return; |
1361 | 1316 |
1362 // Use const_cast and temporarily modify the fill type instead of copying th e path. | 1317 // Use const_cast and temporarily modify the fill type instead of copying th e path. |
1363 SkPath& path = const_cast<SkPath&>(pathToFill.skPath()); | 1318 SkPath& path = const_cast<SkPath&>(pathToFill.skPath()); |
1364 SkPath::FillType previousFillType = path.getFillType(); | 1319 SkPath::FillType previousFillType = path.getFillType(); |
1365 | 1320 |
1366 SkPath::FillType temporaryFillType = m_paintState->m_fillRule == RULE_EVENOD D ? SkPath::kEvenOdd_FillType : SkPath::kWinding_FillType; | 1321 SkPath::FillType temporaryFillType = |
1322 immutableState()->fillRule() == RULE_EVENODD ? SkPath::kEvenOdd_FillType : SkPath::kWinding_FillType; | |
1367 path.setFillType(temporaryFillType); | 1323 path.setFillType(temporaryFillType); |
1368 | 1324 |
1369 SkPaint paint; | 1325 drawPath(path, immutableState()->fillPaint()); |
1370 setupPaintForFilling(&paint); | |
1371 drawPath(path, paint); | |
1372 | 1326 |
1373 path.setFillType(previousFillType); | 1327 path.setFillType(previousFillType); |
1374 } | 1328 } |
1375 | 1329 |
1376 void GraphicsContext::fillRect(const FloatRect& rect) | 1330 void GraphicsContext::fillRect(const FloatRect& rect) |
1377 { | 1331 { |
1378 if (paintingDisabled()) | 1332 if (paintingDisabled()) |
1379 return; | 1333 return; |
1380 | 1334 |
1381 SkRect r = rect; | 1335 SkRect r = rect; |
1382 | 1336 |
1383 SkPaint paint; | 1337 drawRect(r, immutableState()->fillPaint()); |
1384 setupPaintForFilling(&paint); | |
1385 drawRect(r, paint); | |
1386 } | 1338 } |
1387 | 1339 |
1388 void GraphicsContext::fillRect(const FloatRect& rect, const Color& color) | 1340 void GraphicsContext::fillRect(const FloatRect& rect, const Color& color) |
1389 { | 1341 { |
1390 if (paintingDisabled()) | 1342 if (paintingDisabled()) |
1391 return; | 1343 return; |
1392 | 1344 |
1393 SkRect r = rect; | 1345 SkRect r = rect; |
1394 SkPaint paint; | 1346 SkPaint paint; |
1395 setupPaintCommon(&paint); | 1347 paint.setAntiAlias(immutableState()->shouldAntialias()); |
1348 if (!SkXfermode::IsMode(immutableState()->xferMode(), SkXfermode::kSrcOver_M ode)) | |
1349 paint.setXfermode(immutableState()->xferMode()); | |
1350 if (immutableState()->drawLooper()) | |
1351 paint.setLooper(immutableState()->drawLooper()); | |
1352 paint.setColorFilter(immutableState()->colorFilter()); | |
f(malita)
2014/03/03 22:46:21
Why does this paint need special handling? (why no
Stephen Chennney
2014/03/04 13:20:36
It doesn't (apart from the color at the end). I mu
Stephen Chennney
2014/03/04 14:47:10
Done.
| |
1396 paint.setColor(color.rgb()); | 1353 paint.setColor(color.rgb()); |
1397 drawRect(r, paint); | 1354 drawRect(r, paint); |
1398 } | 1355 } |
1399 | 1356 |
1400 void GraphicsContext::fillRoundedRect(const IntRect& rect, const IntSize& topLef t, const IntSize& topRight, | 1357 void GraphicsContext::fillRoundedRect(const IntRect& rect, const IntSize& topLef t, const IntSize& topRight, |
1401 const IntSize& bottomLeft, const IntSize& bottomRight, const Color& color) | 1358 const IntSize& bottomLeft, const IntSize& bottomRight, const Color& color) |
1402 { | 1359 { |
1403 if (paintingDisabled()) | 1360 if (paintingDisabled()) |
1404 return; | 1361 return; |
1405 | 1362 |
(...skipping 23 matching lines...) Expand all Loading... | |
1429 if (m_trackOpaqueRegion) | 1386 if (m_trackOpaqueRegion) |
1430 m_opaqueRegion.didDrawBounded(this, rr.getBounds(), paint); | 1387 m_opaqueRegion.didDrawBounded(this, rr.getBounds(), paint); |
1431 } | 1388 } |
1432 | 1389 |
1433 void GraphicsContext::fillEllipse(const FloatRect& ellipse) | 1390 void GraphicsContext::fillEllipse(const FloatRect& ellipse) |
1434 { | 1391 { |
1435 if (paintingDisabled()) | 1392 if (paintingDisabled()) |
1436 return; | 1393 return; |
1437 | 1394 |
1438 SkRect rect = ellipse; | 1395 SkRect rect = ellipse; |
1439 SkPaint paint; | 1396 drawOval(rect, immutableState()->fillPaint()); |
1440 setupPaintForFilling(&paint); | |
1441 drawOval(rect, paint); | |
1442 } | 1397 } |
1443 | 1398 |
1444 void GraphicsContext::strokePath(const Path& pathToStroke) | 1399 void GraphicsContext::strokePath(const Path& pathToStroke) |
1445 { | 1400 { |
1446 if (paintingDisabled() || pathToStroke.isEmpty()) | 1401 if (paintingDisabled() || pathToStroke.isEmpty()) |
1447 return; | 1402 return; |
1448 | 1403 |
1449 const SkPath& path = pathToStroke.skPath(); | 1404 const SkPath& path = pathToStroke.skPath(); |
1450 SkPaint paint; | 1405 SkPaint paint; |
1451 setupPaintForStroking(&paint); | 1406 setupPaintForStroking(&paint); |
(...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1833 But webkit can sometimes send us non-convex 4-point values, so we mark t he path's | 1788 But webkit can sometimes send us non-convex 4-point values, so we mark t he path's |
1834 convexity as unknown, so it will get computed by skia at draw time. | 1789 convexity as unknown, so it will get computed by skia at draw time. |
1835 See crbug.com 108605 | 1790 See crbug.com 108605 |
1836 */ | 1791 */ |
1837 SkPath::Convexity convexity = SkPath::kConvex_Convexity; | 1792 SkPath::Convexity convexity = SkPath::kConvex_Convexity; |
1838 if (numPoints == 4) | 1793 if (numPoints == 4) |
1839 convexity = SkPath::kUnknown_Convexity; | 1794 convexity = SkPath::kUnknown_Convexity; |
1840 path->setConvexity(convexity); | 1795 path->setConvexity(convexity); |
1841 } | 1796 } |
1842 | 1797 |
1843 void GraphicsContext::setupPaintCommon(SkPaint* paint) const | |
1844 { | |
1845 #if defined(SK_DEBUG) | |
1846 { | |
1847 SkPaint defaultPaint; | |
1848 SkASSERT(*paint == defaultPaint); | |
1849 } | |
1850 #endif | |
1851 | |
1852 paint->setAntiAlias(m_paintState->m_shouldAntialias); | |
1853 | |
1854 if (!SkXfermode::IsMode(m_paintState->m_xferMode.get(), SkXfermode::kSrcOver _Mode)) | |
1855 paint->setXfermode(m_paintState->m_xferMode.get()); | |
1856 | |
1857 if (m_paintState->m_looper) | |
1858 paint->setLooper(m_paintState->m_looper.get()); | |
1859 | |
1860 paint->setColorFilter(m_paintState->m_colorFilter.get()); | |
1861 } | |
1862 | |
1863 void GraphicsContext::drawOuterPath(const SkPath& path, SkPaint& paint, int widt h) | 1798 void GraphicsContext::drawOuterPath(const SkPath& path, SkPaint& paint, int widt h) |
1864 { | 1799 { |
1865 #if OS(MACOSX) | 1800 #if OS(MACOSX) |
1866 paint.setAlpha(64); | 1801 paint.setAlpha(64); |
1867 paint.setStrokeWidth(width); | 1802 paint.setStrokeWidth(width); |
1868 paint.setPathEffect(new SkCornerPathEffect((width - 1) * 0.5f))->unref(); | 1803 paint.setPathEffect(new SkCornerPathEffect((width - 1) * 0.5f))->unref(); |
1869 #else | 1804 #else |
1870 paint.setStrokeWidth(1); | 1805 paint.setStrokeWidth(1); |
1871 paint.setPathEffect(new SkCornerPathEffect(1))->unref(); | 1806 paint.setPathEffect(new SkCornerPathEffect(1))->unref(); |
1872 #endif | 1807 #endif |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2004 { | 1939 { |
2005 static const SkPMColor colors[] = { | 1940 static const SkPMColor colors[] = { |
2006 SkPreMultiplyARGB(0x60, 0xFF, 0x00, 0x00), // More transparent red | 1941 SkPreMultiplyARGB(0x60, 0xFF, 0x00, 0x00), // More transparent red |
2007 SkPreMultiplyARGB(0x60, 0xC0, 0xC0, 0xC0) // More transparent gray | 1942 SkPreMultiplyARGB(0x60, 0xC0, 0xC0, 0xC0) // More transparent gray |
2008 }; | 1943 }; |
2009 | 1944 |
2010 return colors[index]; | 1945 return colors[index]; |
2011 } | 1946 } |
2012 #endif | 1947 #endif |
2013 | 1948 |
2014 void GraphicsContext::setupShader(SkPaint* paint, Gradient* grad, Pattern* pat, SkColor color) const | |
2015 { | |
2016 RefPtr<SkShader> shader; | |
2017 | |
2018 if (grad) { | |
2019 shader = grad->shader(); | |
2020 color = SK_ColorBLACK; | |
2021 } else if (pat) { | |
2022 shader = pat->shader(); | |
2023 color = SK_ColorBLACK; | |
2024 paint->setFilterBitmap(imageInterpolationQuality() != InterpolationNone) ; | |
2025 } | |
2026 | |
2027 paint->setColor(m_paintState->applyAlpha(color)); | |
2028 | |
2029 if (!shader) | |
2030 return; | |
2031 | |
2032 paint->setShader(shader.get()); | |
2033 } | |
2034 | |
2035 void GraphicsContext::didDrawTextInRect(const SkRect& textRect) | 1949 void GraphicsContext::didDrawTextInRect(const SkRect& textRect) |
2036 { | 1950 { |
2037 if (m_trackTextRegion) { | 1951 if (m_trackTextRegion) { |
2038 TRACE_EVENT0("skia", "PlatformContextSkia::trackTextRegion"); | 1952 TRACE_EVENT0("skia", "PlatformContextSkia::trackTextRegion"); |
2039 m_textRegion.join(textRect); | 1953 m_textRegion.join(textRect); |
2040 } | 1954 } |
2041 } | 1955 } |
2042 | 1956 |
2043 } | 1957 } |
OLD | NEW |