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 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 m_paintStateIndex--; | 172 m_paintStateIndex--; |
173 m_paintState = m_paintStateStack[m_paintStateIndex].get(); | 173 m_paintState = m_paintStateStack[m_paintStateIndex].get(); |
174 } | 174 } |
175 | 175 |
176 CanvasSaveState savedState = m_canvasStateStack.last(); | 176 CanvasSaveState savedState = m_canvasStateStack.last(); |
177 m_canvasStateStack.removeLast(); | 177 m_canvasStateStack.removeLast(); |
178 m_canvasSaveFlags = savedState.m_flags; | 178 m_canvasSaveFlags = savedState.m_flags; |
179 m_canvas->restoreToCount(savedState.m_restoreCount); | 179 m_canvas->restoreToCount(savedState.m_restoreCount); |
180 } | 180 } |
181 | 181 |
182 void GraphicsContext::saveLayer(const SkRect* bounds, const SkPaint* paint, SkCa
nvas::SaveFlags saveFlags) | 182 void GraphicsContext::saveLayer(const SkRect* bounds, const SkPaint* paint) |
183 { | 183 { |
184 if (paintingDisabled()) | 184 if (paintingDisabled()) |
185 return; | 185 return; |
186 | 186 |
187 realizeCanvasSave(SkCanvas::kMatrixClip_SaveFlag); | 187 realizeCanvasSave(SkCanvas::kMatrixClip_SaveFlag); |
188 | 188 |
189 // We should always save the matrix and clip to match upcoming Skia behavior
. | 189 m_canvas->saveLayer(bounds, paint); |
190 ASSERT(saveFlags & SkCanvas::kMatrix_SaveFlag); | |
191 ASSERT(saveFlags & SkCanvas::kClip_SaveFlag); | |
192 | |
193 m_canvas->saveLayer(bounds, paint, saveFlags); | |
194 if (bounds) | |
195 m_canvas->clipRect(*bounds); | |
196 if (m_trackOpaqueRegion) | 190 if (m_trackOpaqueRegion) |
197 m_opaqueRegion.pushCanvasLayer(paint); | 191 m_opaqueRegion.pushCanvasLayer(paint); |
198 } | 192 } |
199 | 193 |
200 void GraphicsContext::restoreLayer() | 194 void GraphicsContext::restoreLayer() |
201 { | 195 { |
202 if (paintingDisabled()) | 196 if (paintingDisabled()) |
203 return; | 197 return; |
204 | 198 |
205 m_canvas->restore(); | 199 m_canvas->restore(); |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
448 void GraphicsContext::beginTransparencyLayer(float opacity, const FloatRect* bou
nds) | 442 void GraphicsContext::beginTransparencyLayer(float opacity, const FloatRect* bou
nds) |
449 { | 443 { |
450 beginLayer(opacity, immutableState()->compositeOperator(), bounds); | 444 beginLayer(opacity, immutableState()->compositeOperator(), bounds); |
451 } | 445 } |
452 | 446 |
453 void GraphicsContext::beginLayer(float opacity, CompositeOperator op, const Floa
tRect* bounds, ColorFilter colorFilter, ImageFilter* imageFilter) | 447 void GraphicsContext::beginLayer(float opacity, CompositeOperator op, const Floa
tRect* bounds, ColorFilter colorFilter, ImageFilter* imageFilter) |
454 { | 448 { |
455 if (paintingDisabled()) | 449 if (paintingDisabled()) |
456 return; | 450 return; |
457 | 451 |
458 // We need the "alpha" layer flag here because the base layer is opaque | |
459 // (the surface of the page) but layers on top may have transparent parts. | |
460 // Without explicitly setting the alpha flag, the layer will inherit the | |
461 // opaque setting of the base and some things won't work properly. | |
462 SkCanvas::SaveFlags saveFlags = static_cast<SkCanvas::SaveFlags>( | |
463 SkCanvas::kMatrixClip_SaveFlag | SkCanvas::kHasAlphaLayer_SaveFlag | SkC
anvas::kFullColorLayer_SaveFlag); | |
464 | |
465 SkPaint layerPaint; | 452 SkPaint layerPaint; |
466 layerPaint.setAlpha(static_cast<unsigned char>(opacity * 255)); | 453 layerPaint.setAlpha(static_cast<unsigned char>(opacity * 255)); |
467 layerPaint.setXfermode(WebCoreCompositeToSkiaComposite(op, m_paintState->ble
ndMode()).get()); | 454 layerPaint.setXfermode(WebCoreCompositeToSkiaComposite(op, m_paintState->ble
ndMode()).get()); |
468 layerPaint.setColorFilter(WebCoreColorFilterToSkiaColorFilter(colorFilter).g
et()); | 455 layerPaint.setColorFilter(WebCoreColorFilterToSkiaColorFilter(colorFilter).g
et()); |
469 layerPaint.setImageFilter(imageFilter); | 456 layerPaint.setImageFilter(imageFilter); |
470 | 457 |
471 // Filters will adjust the clip to accomodate for filter bounds, but | |
472 // need the kClipToLayer_SaveFlag to do so. We also save the clip here, so | |
473 // it is restored back before the filtered layer is drawn in restore(). | |
474 // The matrix also needs to be saved, in order to be correctly passed to | |
475 // the filter CTM during restore(). | |
476 if (imageFilter) | |
477 saveFlags = SkCanvas::kARGB_ClipLayer_SaveFlag; | |
478 | |
479 if (bounds) { | 458 if (bounds) { |
480 SkRect skBounds = WebCoreFloatRectToSKRect(*bounds); | 459 SkRect skBounds = WebCoreFloatRectToSKRect(*bounds); |
481 saveLayer(&skBounds, &layerPaint, saveFlags); | 460 saveLayer(&skBounds, &layerPaint); |
482 } else { | 461 } else { |
483 saveLayer(0, &layerPaint, saveFlags); | 462 saveLayer(0, &layerPaint); |
484 } | 463 } |
485 | 464 |
486 #if !ASSERT_DISABLED | 465 #if !ASSERT_DISABLED |
487 ++m_layerCount; | 466 ++m_layerCount; |
488 #endif | 467 #endif |
489 } | 468 } |
490 | 469 |
491 void GraphicsContext::endLayer() | 470 void GraphicsContext::endLayer() |
492 { | 471 { |
493 if (paintingDisabled()) | 472 if (paintingDisabled()) |
(...skipping 1396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1890 | 1869 |
1891 void GraphicsContext::didDrawTextInRect(const SkRect& textRect) | 1870 void GraphicsContext::didDrawTextInRect(const SkRect& textRect) |
1892 { | 1871 { |
1893 if (m_trackTextRegion) { | 1872 if (m_trackTextRegion) { |
1894 TRACE_EVENT0("skia", "PlatformContextSkia::trackTextRegion"); | 1873 TRACE_EVENT0("skia", "PlatformContextSkia::trackTextRegion"); |
1895 m_textRegion.join(textRect); | 1874 m_textRegion.join(textRect); |
1896 } | 1875 } |
1897 } | 1876 } |
1898 | 1877 |
1899 } | 1878 } |
OLD | NEW |