Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(236)

Side by Side Diff: third_party/WebKit/Source/modules/canvas2d/CanvasRenderingContext2D.cpp

Issue 2523673004: [NOT FOR COMMIT] Fully replace SkCanvas uses.
Patch Set: Support Android build. Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 #include "modules/canvas2d/HitRegion.h" 54 #include "modules/canvas2d/HitRegion.h"
55 #include "modules/canvas2d/Path2D.h" 55 #include "modules/canvas2d/Path2D.h"
56 #include "platform/fonts/FontCache.h" 56 #include "platform/fonts/FontCache.h"
57 #include "platform/graphics/DrawLooperBuilder.h" 57 #include "platform/graphics/DrawLooperBuilder.h"
58 #include "platform/graphics/ExpensiveCanvasHeuristicParameters.h" 58 #include "platform/graphics/ExpensiveCanvasHeuristicParameters.h"
59 #include "platform/graphics/ImageBuffer.h" 59 #include "platform/graphics/ImageBuffer.h"
60 #include "platform/graphics/StrokeData.h" 60 #include "platform/graphics/StrokeData.h"
61 #include "platform/graphics/skia/SkiaUtils.h" 61 #include "platform/graphics/skia/SkiaUtils.h"
62 #include "platform/text/BidiTextRun.h" 62 #include "platform/text/BidiTextRun.h"
63 #include "public/platform/Platform.h" 63 #include "public/platform/Platform.h"
64 #include "third_party/skia/include/core/SkCanvas.h" 64 #include "skia/ext/cdl_canvas.h"
65 #include "skia/ext/cdl_paint.h"
65 #include "third_party/skia/include/core/SkImageFilter.h" 66 #include "third_party/skia/include/core/SkImageFilter.h"
66 #include "wtf/MathExtras.h" 67 #include "wtf/MathExtras.h"
67 #include "wtf/text/StringBuilder.h" 68 #include "wtf/text/StringBuilder.h"
68 #include "wtf/typed_arrays/ArrayBufferContents.h" 69 #include "wtf/typed_arrays/ArrayBufferContents.h"
69 70
70 namespace blink { 71 namespace blink {
71 72
72 static const char defaultFont[] = "10px sans-serif"; 73 static const char defaultFont[] = "10px sans-serif";
73 static const char inherit[] = "inherit"; 74 static const char inherit[] = "inherit";
74 static const char rtl[] = "rtl"; 75 static const char rtl[] = "rtl";
(...skipping 10 matching lines...) Expand all
85 // overdraw detection substitutes the recording canvas (to discard overdrawn 86 // overdraw detection substitutes the recording canvas (to discard overdrawn
86 // draw calls). 87 // draw calls).
87 class CanvasRenderingContext2DAutoRestoreSkCanvas { 88 class CanvasRenderingContext2DAutoRestoreSkCanvas {
88 STACK_ALLOCATED(); 89 STACK_ALLOCATED();
89 90
90 public: 91 public:
91 explicit CanvasRenderingContext2DAutoRestoreSkCanvas( 92 explicit CanvasRenderingContext2DAutoRestoreSkCanvas(
92 CanvasRenderingContext2D* context) 93 CanvasRenderingContext2D* context)
93 : m_context(context), m_saveCount(0) { 94 : m_context(context), m_saveCount(0) {
94 ASSERT(m_context); 95 ASSERT(m_context);
95 SkCanvas* c = m_context->drawingCanvas(); 96 CdlCanvas* c = m_context->drawingCanvas();
96 if (c) { 97 if (c) {
97 m_saveCount = c->getSaveCount(); 98 m_saveCount = c->getSaveCount();
98 } 99 }
99 } 100 }
100 101
101 ~CanvasRenderingContext2DAutoRestoreSkCanvas() { 102 ~CanvasRenderingContext2DAutoRestoreSkCanvas() {
102 SkCanvas* c = m_context->drawingCanvas(); 103 CdlCanvas* c = m_context->drawingCanvas();
103 if (c) 104 if (c)
104 c->restoreToCount(m_saveCount); 105 c->restoreToCount(m_saveCount);
105 m_context->validateStateStack(); 106 m_context->validateStateStack();
106 } 107 }
107 108
108 private: 109 private:
109 Member<CanvasRenderingContext2D> m_context; 110 Member<CanvasRenderingContext2D> m_context;
110 int m_saveCount; 111 int m_saveCount;
111 }; 112 };
112 113
(...skipping 30 matching lines...) Expand all
143 144
144 CanvasRenderingContext2D::~CanvasRenderingContext2D() {} 145 CanvasRenderingContext2D::~CanvasRenderingContext2D() {}
145 146
146 void CanvasRenderingContext2D::dispose() { 147 void CanvasRenderingContext2D::dispose() {
147 if (m_pruneLocalFontCacheScheduled) 148 if (m_pruneLocalFontCacheScheduled)
148 Platform::current()->currentThread()->removeTaskObserver(this); 149 Platform::current()->currentThread()->removeTaskObserver(this);
149 } 150 }
150 151
151 void CanvasRenderingContext2D::validateStateStack() const { 152 void CanvasRenderingContext2D::validateStateStack() const {
152 #if DCHECK_IS_ON() 153 #if DCHECK_IS_ON()
153 if (SkCanvas* skCanvas = canvas()->existingDrawingCanvas()) { 154 if (CdlCanvas* skCanvas = canvas()->existingDrawingCanvas()) {
154 // The canvas should always have an initial save frame, to support 155 // The canvas should always have an initial save frame, to support
155 // resetting the top level matrix and clip. 156 // resetting the top level matrix and clip.
156 DCHECK_GT(skCanvas->getSaveCount(), 1); 157 DCHECK_GT(skCanvas->getSaveCount(), 1);
157 158
158 if (m_contextLostMode == NotLostContext) { 159 if (m_contextLostMode == NotLostContext) {
159 DCHECK_EQ(static_cast<size_t>(skCanvas->getSaveCount()), 160 DCHECK_EQ(static_cast<size_t>(skCanvas->getSaveCount()),
160 m_stateStack.size() + 1); 161 m_stateStack.size() + 1);
161 } 162 }
162 } 163 }
163 #endif 164 #endif
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 Event* event(Event::create(EventTypeNames::contextrestored)); 269 Event* event(Event::create(EventTypeNames::contextrestored));
269 canvas()->dispatchEvent(event); 270 canvas()->dispatchEvent(event);
270 } 271 }
271 } 272 }
272 273
273 void CanvasRenderingContext2D::reset() { 274 void CanvasRenderingContext2D::reset() {
274 // This is a multiple inherritance bootstrap 275 // This is a multiple inherritance bootstrap
275 BaseRenderingContext2D::reset(); 276 BaseRenderingContext2D::reset();
276 } 277 }
277 278
278 void CanvasRenderingContext2D::restoreCanvasMatrixClipStack(SkCanvas* c) const { 279 void CanvasRenderingContext2D::restoreCanvasMatrixClipStack(
280 CdlCanvas* c) const {
279 restoreMatrixClipStack(c); 281 restoreMatrixClipStack(c);
280 } 282 }
281 283
282 bool CanvasRenderingContext2D::shouldAntialias() const { 284 bool CanvasRenderingContext2D::shouldAntialias() const {
283 return state().shouldAntialias(); 285 return state().shouldAntialias();
284 } 286 }
285 287
286 void CanvasRenderingContext2D::setShouldAntialias(bool doAA) { 288 void CanvasRenderingContext2D::setShouldAntialias(bool doAA) {
287 modifiableState().setShouldAntialias(doAA); 289 modifiableState().setShouldAntialias(doAA);
288 } 290 }
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 362
361 void CanvasRenderingContext2D::snapshotStateForFilter() { 363 void CanvasRenderingContext2D::snapshotStateForFilter() {
362 // The style resolution required for fonts is not available in frame-less 364 // The style resolution required for fonts is not available in frame-less
363 // documents. 365 // documents.
364 if (!canvas()->document().frame()) 366 if (!canvas()->document().frame())
365 return; 367 return;
366 368
367 modifiableState().setFontForFilter(accessFont()); 369 modifiableState().setFontForFilter(accessFont());
368 } 370 }
369 371
370 SkCanvas* CanvasRenderingContext2D::drawingCanvas() const { 372 CdlCanvas* CanvasRenderingContext2D::drawingCanvas() const {
371 if (isContextLost()) 373 if (isContextLost())
372 return nullptr; 374 return nullptr;
373 return canvas()->drawingCanvas(); 375 return canvas()->drawingCanvas();
374 } 376 }
375 377
376 SkCanvas* CanvasRenderingContext2D::existingDrawingCanvas() const { 378 CdlCanvas* CanvasRenderingContext2D::existingDrawingCanvas() const {
377 return canvas()->existingDrawingCanvas(); 379 return canvas()->existingDrawingCanvas();
378 } 380 }
379 381
380 void CanvasRenderingContext2D::disableDeferral(DisableDeferralReason reason) { 382 void CanvasRenderingContext2D::disableDeferral(DisableDeferralReason reason) {
381 canvas()->disableDeferral(reason); 383 canvas()->disableDeferral(reason);
382 } 384 }
383 385
384 AffineTransform CanvasRenderingContext2D::baseTransform() const { 386 AffineTransform CanvasRenderingContext2D::baseTransform() const {
385 return canvas()->baseTransform(); 387 return canvas()->baseTransform();
386 } 388 }
(...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after
804 // The style resolution required for fonts is not available in frame-less 806 // The style resolution required for fonts is not available in frame-less
805 // documents. 807 // documents.
806 if (!canvas()->document().frame()) 808 if (!canvas()->document().frame())
807 return; 809 return;
808 810
809 // accessFont needs the style to be up to date, but updating style can cause 811 // accessFont needs the style to be up to date, but updating style can cause
810 // script to run, (e.g. due to autofocus) which can free the canvas (set size 812 // script to run, (e.g. due to autofocus) which can free the canvas (set size
811 // to 0, for example), so update style before grabbing the drawingCanvas. 813 // to 0, for example), so update style before grabbing the drawingCanvas.
812 canvas()->document().updateStyleAndLayoutTreeForNode(canvas()); 814 canvas()->document().updateStyleAndLayoutTreeForNode(canvas());
813 815
814 SkCanvas* c = drawingCanvas(); 816 CdlCanvas* c = drawingCanvas();
815 if (!c) 817 if (!c)
816 return; 818 return;
817 819
818 if (!std::isfinite(x) || !std::isfinite(y)) 820 if (!std::isfinite(x) || !std::isfinite(y))
819 return; 821 return;
820 if (maxWidth && (!std::isfinite(*maxWidth) || *maxWidth <= 0)) 822 if (maxWidth && (!std::isfinite(*maxWidth) || *maxWidth <= 0))
821 return; 823 return;
822 824
823 // Currently, SkPictureImageFilter does not support subpixel text 825 // Currently, SkPictureImageFilter does not support subpixel text
824 // anti-aliasing, which is expected when !creationAttributes().alpha(), so we 826 // anti-aliasing, which is expected when !creationAttributes().alpha(), so we
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
887 drawingCanvas()->save(); 889 drawingCanvas()->save();
888 drawingCanvas()->translate(location.x(), location.y()); 890 drawingCanvas()->translate(location.x(), location.y());
889 // We draw when fontWidth is 0 so compositing operations (eg, a "copy" op) 891 // We draw when fontWidth is 0 so compositing operations (eg, a "copy" op)
890 // still work. 892 // still work.
891 drawingCanvas()->scale((fontWidth > 0 ? (width / fontWidth) : 0), 1); 893 drawingCanvas()->scale((fontWidth > 0 ? (width / fontWidth) : 0), 1);
892 location = FloatPoint(); 894 location = FloatPoint();
893 } 895 }
894 896
895 draw( 897 draw(
896 [&font, this, &textRunPaintInfo, &location]( 898 [&font, this, &textRunPaintInfo, &location](
897 SkCanvas* c, const SkPaint* paint) // draw lambda 899 CdlCanvas* c, const CdlPaint* paint) // draw lambda
898 { 900 {
901 (void)cDeviceScaleFactor;
899 font.drawBidiText(c, textRunPaintInfo, location, 902 font.drawBidiText(c, textRunPaintInfo, location,
900 Font::UseFallbackIfFontNotReady, cDeviceScaleFactor, 903 Font::UseFallbackIfFontNotReady, cDeviceScaleFactor,
901 *paint); 904 *paint);
902 }, 905 },
903 [](const SkIRect& rect) // overdraw test lambda 906 [](const SkIRect& rect) // overdraw test lambda
904 { return false; }, 907 { return false; },
905 textRunPaintInfo.bounds, paintType); 908 textRunPaintInfo.bounds, paintType);
906 } 909 }
907 910
908 const Font& CanvasRenderingContext2D::accessFont() { 911 const Font& CanvasRenderingContext2D::accessFont() {
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
1065 !canvas()->isSupportedInteractiveCanvasFallback(*options.control())) { 1068 !canvas()->isSupportedInteractiveCanvasFallback(*options.control())) {
1066 exceptionState.throwDOMException(NotSupportedError, 1069 exceptionState.throwDOMException(NotSupportedError,
1067 "The control is neither null nor a " 1070 "The control is neither null nor a "
1068 "supported interactive canvas fallback " 1071 "supported interactive canvas fallback "
1069 "element."); 1072 "element.");
1070 return; 1073 return;
1071 } 1074 }
1072 1075
1073 Path hitRegionPath = options.hasPath() ? options.path()->path() : m_path; 1076 Path hitRegionPath = options.hasPath() ? options.path()->path() : m_path;
1074 1077
1075 SkCanvas* c = drawingCanvas(); 1078 CdlCanvas* c = drawingCanvas();
1076 1079
1077 if (hitRegionPath.isEmpty() || !c || !state().isTransformInvertible() || 1080 if (hitRegionPath.isEmpty() || !c || !state().isTransformInvertible() ||
1078 !c->getClipDeviceBounds(0)) { 1081 !c->getClipDeviceBounds(0)) {
1079 exceptionState.throwDOMException(NotSupportedError, 1082 exceptionState.throwDOMException(NotSupportedError,
1080 "The specified path has no pixels."); 1083 "The specified path has no pixels.");
1081 return; 1084 return;
1082 } 1085 }
1083 1086
1084 hitRegionPath.transform(state().transform()); 1087 hitRegionPath.transform(state().transform());
1085 1088
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
1154 } 1157 }
1155 return true; 1158 return true;
1156 } 1159 }
1157 1160
1158 void CanvasRenderingContext2D::resetUsageTracking() { 1161 void CanvasRenderingContext2D::resetUsageTracking() {
1159 UsageCounters newCounters; 1162 UsageCounters newCounters;
1160 m_usageCounters = newCounters; 1163 m_usageCounters = newCounters;
1161 } 1164 }
1162 1165
1163 } // namespace blink 1166 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698