| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc. | 2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc. |
| 3 * All rights reserved. | 3 * All rights reserved. |
| 4 * Copyright (C) 2008, 2010 Nokia Corporation and/or its subsidiary(-ies) | 4 * Copyright (C) 2008, 2010 Nokia Corporation and/or its subsidiary(-ies) |
| 5 * Copyright (C) 2007 Alp Toker <alp@atoker.com> | 5 * Copyright (C) 2007 Alp Toker <alp@atoker.com> |
| 6 * Copyright (C) 2008 Eric Seidel <eric@webkit.org> | 6 * Copyright (C) 2008 Eric Seidel <eric@webkit.org> |
| 7 * Copyright (C) 2008 Dirk Schulze <krit@webkit.org> | 7 * Copyright (C) 2008 Dirk Schulze <krit@webkit.org> |
| 8 * Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved. | 8 * Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved. |
| 9 * Copyright (C) 2012, 2013 Intel Corporation. All rights reserved. | 9 * Copyright (C) 2012, 2013 Intel Corporation. All rights reserved. |
| 10 * Copyright (C) 2013 Adobe Systems Incorporated. All rights reserved. | 10 * Copyright (C) 2013 Adobe Systems Incorporated. All rights reserved. |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 #include "core/layout/LayoutBox.h" | 50 #include "core/layout/LayoutBox.h" |
| 51 #include "core/layout/LayoutTheme.h" | 51 #include "core/layout/LayoutTheme.h" |
| 52 #include "modules/canvas2d/CanvasStyle.h" | 52 #include "modules/canvas2d/CanvasStyle.h" |
| 53 #include "modules/canvas2d/HitRegion.h" | 53 #include "modules/canvas2d/HitRegion.h" |
| 54 #include "modules/canvas2d/Path2D.h" | 54 #include "modules/canvas2d/Path2D.h" |
| 55 #include "platform/fonts/FontCache.h" | 55 #include "platform/fonts/FontCache.h" |
| 56 #include "platform/graphics/DrawLooperBuilder.h" | 56 #include "platform/graphics/DrawLooperBuilder.h" |
| 57 #include "platform/graphics/ExpensiveCanvasHeuristicParameters.h" | 57 #include "platform/graphics/ExpensiveCanvasHeuristicParameters.h" |
| 58 #include "platform/graphics/ImageBuffer.h" | 58 #include "platform/graphics/ImageBuffer.h" |
| 59 #include "platform/graphics/StrokeData.h" | 59 #include "platform/graphics/StrokeData.h" |
| 60 #include "platform/graphics/paint/PaintCanvas.h" |
| 61 #include "platform/graphics/paint/PaintFlags.h" |
| 60 #include "platform/graphics/skia/SkiaUtils.h" | 62 #include "platform/graphics/skia/SkiaUtils.h" |
| 61 #include "platform/text/BidiTextRun.h" | 63 #include "platform/text/BidiTextRun.h" |
| 62 #include "public/platform/Platform.h" | 64 #include "public/platform/Platform.h" |
| 63 #include "third_party/skia/include/core/SkCanvas.h" | |
| 64 #include "third_party/skia/include/core/SkImageFilter.h" | 65 #include "third_party/skia/include/core/SkImageFilter.h" |
| 65 #include "wtf/MathExtras.h" | 66 #include "wtf/MathExtras.h" |
| 66 #include "wtf/text/StringBuilder.h" | 67 #include "wtf/text/StringBuilder.h" |
| 67 #include "wtf/typed_arrays/ArrayBufferContents.h" | 68 #include "wtf/typed_arrays/ArrayBufferContents.h" |
| 68 | 69 |
| 69 namespace blink { | 70 namespace blink { |
| 70 | 71 |
| 71 static const char defaultFont[] = "10px sans-serif"; | 72 static const char defaultFont[] = "10px sans-serif"; |
| 72 static const char inheritDirectionString[] = "inherit"; | 73 static const char inheritDirectionString[] = "inherit"; |
| 73 static const char rtlDirectionString[] = "rtl"; | 74 static const char rtlDirectionString[] = "rtl"; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 84 // overdraw detection substitutes the recording canvas (to discard overdrawn | 85 // overdraw detection substitutes the recording canvas (to discard overdrawn |
| 85 // draw calls). | 86 // draw calls). |
| 86 class CanvasRenderingContext2DAutoRestoreSkCanvas { | 87 class CanvasRenderingContext2DAutoRestoreSkCanvas { |
| 87 STACK_ALLOCATED(); | 88 STACK_ALLOCATED(); |
| 88 | 89 |
| 89 public: | 90 public: |
| 90 explicit CanvasRenderingContext2DAutoRestoreSkCanvas( | 91 explicit CanvasRenderingContext2DAutoRestoreSkCanvas( |
| 91 CanvasRenderingContext2D* context) | 92 CanvasRenderingContext2D* context) |
| 92 : m_context(context), m_saveCount(0) { | 93 : m_context(context), m_saveCount(0) { |
| 93 DCHECK(m_context); | 94 DCHECK(m_context); |
| 94 SkCanvas* c = m_context->drawingCanvas(); | 95 PaintCanvas* c = m_context->drawingCanvas(); |
| 95 if (c) { | 96 if (c) { |
| 96 m_saveCount = c->getSaveCount(); | 97 m_saveCount = c->getSaveCount(); |
| 97 } | 98 } |
| 98 } | 99 } |
| 99 | 100 |
| 100 ~CanvasRenderingContext2DAutoRestoreSkCanvas() { | 101 ~CanvasRenderingContext2DAutoRestoreSkCanvas() { |
| 101 SkCanvas* c = m_context->drawingCanvas(); | 102 PaintCanvas* c = m_context->drawingCanvas(); |
| 102 if (c) | 103 if (c) |
| 103 c->restoreToCount(m_saveCount); | 104 c->restoreToCount(m_saveCount); |
| 104 m_context->validateStateStack(); | 105 m_context->validateStateStack(); |
| 105 } | 106 } |
| 106 | 107 |
| 107 private: | 108 private: |
| 108 Member<CanvasRenderingContext2D> m_context; | 109 Member<CanvasRenderingContext2D> m_context; |
| 109 int m_saveCount; | 110 int m_saveCount; |
| 110 }; | 111 }; |
| 111 | 112 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 141 | 142 |
| 142 CanvasRenderingContext2D::~CanvasRenderingContext2D() {} | 143 CanvasRenderingContext2D::~CanvasRenderingContext2D() {} |
| 143 | 144 |
| 144 void CanvasRenderingContext2D::dispose() { | 145 void CanvasRenderingContext2D::dispose() { |
| 145 if (m_pruneLocalFontCacheScheduled) | 146 if (m_pruneLocalFontCacheScheduled) |
| 146 Platform::current()->currentThread()->removeTaskObserver(this); | 147 Platform::current()->currentThread()->removeTaskObserver(this); |
| 147 } | 148 } |
| 148 | 149 |
| 149 void CanvasRenderingContext2D::validateStateStack() const { | 150 void CanvasRenderingContext2D::validateStateStack() const { |
| 150 #if DCHECK_IS_ON() | 151 #if DCHECK_IS_ON() |
| 151 if (SkCanvas* skCanvas = canvas()->existingDrawingCanvas()) { | 152 if (PaintCanvas* skCanvas = canvas()->existingDrawingCanvas()) { |
| 152 // The canvas should always have an initial save frame, to support | 153 // The canvas should always have an initial save frame, to support |
| 153 // resetting the top level matrix and clip. | 154 // resetting the top level matrix and clip. |
| 154 DCHECK_GT(skCanvas->getSaveCount(), 1); | 155 DCHECK_GT(skCanvas->getSaveCount(), 1); |
| 155 | 156 |
| 156 if (m_contextLostMode == NotLostContext) { | 157 if (m_contextLostMode == NotLostContext) { |
| 157 DCHECK_EQ(static_cast<size_t>(skCanvas->getSaveCount()), | 158 DCHECK_EQ(static_cast<size_t>(skCanvas->getSaveCount()), |
| 158 m_stateStack.size() + 1); | 159 m_stateStack.size() + 1); |
| 159 } | 160 } |
| 160 } | 161 } |
| 161 #endif | 162 #endif |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 | 275 |
| 275 ColorBehavior CanvasRenderingContext2D::drawImageColorBehavior() const { | 276 ColorBehavior CanvasRenderingContext2D::drawImageColorBehavior() const { |
| 276 return CanvasRenderingContext::colorBehaviorForMediaDrawnToCanvas(); | 277 return CanvasRenderingContext::colorBehaviorForMediaDrawnToCanvas(); |
| 277 } | 278 } |
| 278 | 279 |
| 279 void CanvasRenderingContext2D::reset() { | 280 void CanvasRenderingContext2D::reset() { |
| 280 // This is a multiple inherritance bootstrap | 281 // This is a multiple inherritance bootstrap |
| 281 BaseRenderingContext2D::reset(); | 282 BaseRenderingContext2D::reset(); |
| 282 } | 283 } |
| 283 | 284 |
| 284 void CanvasRenderingContext2D::restoreCanvasMatrixClipStack(SkCanvas* c) const { | 285 void CanvasRenderingContext2D::restoreCanvasMatrixClipStack( |
| 286 PaintCanvas* c) const { |
| 285 restoreMatrixClipStack(c); | 287 restoreMatrixClipStack(c); |
| 286 } | 288 } |
| 287 | 289 |
| 288 bool CanvasRenderingContext2D::shouldAntialias() const { | 290 bool CanvasRenderingContext2D::shouldAntialias() const { |
| 289 return state().shouldAntialias(); | 291 return state().shouldAntialias(); |
| 290 } | 292 } |
| 291 | 293 |
| 292 void CanvasRenderingContext2D::setShouldAntialias(bool doAA) { | 294 void CanvasRenderingContext2D::setShouldAntialias(bool doAA) { |
| 293 modifiableState().setShouldAntialias(doAA); | 295 modifiableState().setShouldAntialias(doAA); |
| 294 } | 296 } |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 366 | 368 |
| 367 void CanvasRenderingContext2D::snapshotStateForFilter() { | 369 void CanvasRenderingContext2D::snapshotStateForFilter() { |
| 368 // The style resolution required for fonts is not available in frame-less | 370 // The style resolution required for fonts is not available in frame-less |
| 369 // documents. | 371 // documents. |
| 370 if (!canvas()->document().frame()) | 372 if (!canvas()->document().frame()) |
| 371 return; | 373 return; |
| 372 | 374 |
| 373 modifiableState().setFontForFilter(accessFont()); | 375 modifiableState().setFontForFilter(accessFont()); |
| 374 } | 376 } |
| 375 | 377 |
| 376 SkCanvas* CanvasRenderingContext2D::drawingCanvas() const { | 378 PaintCanvas* CanvasRenderingContext2D::drawingCanvas() const { |
| 377 if (isContextLost()) | 379 if (isContextLost()) |
| 378 return nullptr; | 380 return nullptr; |
| 379 return canvas()->drawingCanvas(); | 381 return canvas()->drawingCanvas(); |
| 380 } | 382 } |
| 381 | 383 |
| 382 SkCanvas* CanvasRenderingContext2D::existingDrawingCanvas() const { | 384 PaintCanvas* CanvasRenderingContext2D::existingDrawingCanvas() const { |
| 383 return canvas()->existingDrawingCanvas(); | 385 return canvas()->existingDrawingCanvas(); |
| 384 } | 386 } |
| 385 | 387 |
| 386 void CanvasRenderingContext2D::disableDeferral(DisableDeferralReason reason) { | 388 void CanvasRenderingContext2D::disableDeferral(DisableDeferralReason reason) { |
| 387 canvas()->disableDeferral(reason); | 389 canvas()->disableDeferral(reason); |
| 388 } | 390 } |
| 389 | 391 |
| 390 AffineTransform CanvasRenderingContext2D::baseTransform() const { | 392 AffineTransform CanvasRenderingContext2D::baseTransform() const { |
| 391 return canvas()->baseTransform(); | 393 return canvas()->baseTransform(); |
| 392 } | 394 } |
| (...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 813 // The style resolution required for fonts is not available in frame-less | 815 // The style resolution required for fonts is not available in frame-less |
| 814 // documents. | 816 // documents. |
| 815 if (!canvas()->document().frame()) | 817 if (!canvas()->document().frame()) |
| 816 return; | 818 return; |
| 817 | 819 |
| 818 // accessFont needs the style to be up to date, but updating style can cause | 820 // accessFont needs the style to be up to date, but updating style can cause |
| 819 // script to run, (e.g. due to autofocus) which can free the canvas (set size | 821 // script to run, (e.g. due to autofocus) which can free the canvas (set size |
| 820 // to 0, for example), so update style before grabbing the drawingCanvas. | 822 // to 0, for example), so update style before grabbing the drawingCanvas. |
| 821 canvas()->document().updateStyleAndLayoutTreeForNode(canvas()); | 823 canvas()->document().updateStyleAndLayoutTreeForNode(canvas()); |
| 822 | 824 |
| 823 SkCanvas* c = drawingCanvas(); | 825 PaintCanvas* c = drawingCanvas(); |
| 824 if (!c) | 826 if (!c) |
| 825 return; | 827 return; |
| 826 | 828 |
| 827 if (!std::isfinite(x) || !std::isfinite(y)) | 829 if (!std::isfinite(x) || !std::isfinite(y)) |
| 828 return; | 830 return; |
| 829 if (maxWidth && (!std::isfinite(*maxWidth) || *maxWidth <= 0)) | 831 if (maxWidth && (!std::isfinite(*maxWidth) || *maxWidth <= 0)) |
| 830 return; | 832 return; |
| 831 | 833 |
| 832 // Currently, SkPictureImageFilter does not support subpixel text | 834 // Currently, SkPictureImageFilter does not support subpixel text |
| 833 // anti-aliasing, which is expected when !creationAttributes().alpha(), so we | 835 // anti-aliasing, which is expected when !creationAttributes().alpha(), so we |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 897 drawingCanvas()->save(); | 899 drawingCanvas()->save(); |
| 898 drawingCanvas()->translate(location.x(), location.y()); | 900 drawingCanvas()->translate(location.x(), location.y()); |
| 899 // We draw when fontWidth is 0 so compositing operations (eg, a "copy" op) | 901 // We draw when fontWidth is 0 so compositing operations (eg, a "copy" op) |
| 900 // still work. | 902 // still work. |
| 901 drawingCanvas()->scale((fontWidth > 0 ? (width / fontWidth) : 0), 1); | 903 drawingCanvas()->scale((fontWidth > 0 ? (width / fontWidth) : 0), 1); |
| 902 location = FloatPoint(); | 904 location = FloatPoint(); |
| 903 } | 905 } |
| 904 | 906 |
| 905 draw( | 907 draw( |
| 906 [&font, &textRunPaintInfo, &location]( | 908 [&font, &textRunPaintInfo, &location]( |
| 907 SkCanvas* c, const SkPaint* paint) // draw lambda | 909 PaintCanvas* c, const PaintFlags* paint) // draw lambda |
| 908 { | 910 { |
| 909 font.drawBidiText(c, textRunPaintInfo, location, | 911 font.drawBidiText(c, textRunPaintInfo, location, |
| 910 Font::UseFallbackIfFontNotReady, cDeviceScaleFactor, | 912 Font::UseFallbackIfFontNotReady, cDeviceScaleFactor, |
| 911 *paint); | 913 *paint); |
| 912 }, | 914 }, |
| 913 [](const SkIRect& rect) // overdraw test lambda | 915 [](const SkIRect& rect) // overdraw test lambda |
| 914 { return false; }, | 916 { return false; }, |
| 915 textRunPaintInfo.bounds, paintType); | 917 textRunPaintInfo.bounds, paintType); |
| 916 } | 918 } |
| 917 | 919 |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1075 !canvas()->isSupportedInteractiveCanvasFallback(*options.control())) { | 1077 !canvas()->isSupportedInteractiveCanvasFallback(*options.control())) { |
| 1076 exceptionState.throwDOMException(NotSupportedError, | 1078 exceptionState.throwDOMException(NotSupportedError, |
| 1077 "The control is neither null nor a " | 1079 "The control is neither null nor a " |
| 1078 "supported interactive canvas fallback " | 1080 "supported interactive canvas fallback " |
| 1079 "element."); | 1081 "element."); |
| 1080 return; | 1082 return; |
| 1081 } | 1083 } |
| 1082 | 1084 |
| 1083 Path hitRegionPath = options.hasPath() ? options.path()->path() : m_path; | 1085 Path hitRegionPath = options.hasPath() ? options.path()->path() : m_path; |
| 1084 | 1086 |
| 1085 SkCanvas* c = drawingCanvas(); | 1087 PaintCanvas* c = drawingCanvas(); |
| 1086 | 1088 |
| 1087 if (hitRegionPath.isEmpty() || !c || !state().isTransformInvertible() || | 1089 if (hitRegionPath.isEmpty() || !c || !state().isTransformInvertible() || |
| 1088 !c->getClipDeviceBounds(0)) { | 1090 !c->getClipDeviceBounds(0)) { |
| 1089 exceptionState.throwDOMException(NotSupportedError, | 1091 exceptionState.throwDOMException(NotSupportedError, |
| 1090 "The specified path has no pixels."); | 1092 "The specified path has no pixels."); |
| 1091 return; | 1093 return; |
| 1092 } | 1094 } |
| 1093 | 1095 |
| 1094 hitRegionPath.transform(state().transform()); | 1096 hitRegionPath.transform(state().transform()); |
| 1095 | 1097 |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1165 } | 1167 } |
| 1166 return true; | 1168 return true; |
| 1167 } | 1169 } |
| 1168 | 1170 |
| 1169 void CanvasRenderingContext2D::resetUsageTracking() { | 1171 void CanvasRenderingContext2D::resetUsageTracking() { |
| 1170 UsageCounters newCounters; | 1172 UsageCounters newCounters; |
| 1171 m_usageCounters = newCounters; | 1173 m_usageCounters = newCounters; |
| 1172 } | 1174 } |
| 1173 | 1175 |
| 1174 } // namespace blink | 1176 } // namespace blink |
| OLD | NEW |