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

Side by Side Diff: Source/core/html/canvas/CanvasRenderingContext2D.cpp

Issue 365653002: Oilpan: move 2D Canvas and WebGL objects to the heap. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Smaller adjustments Created 6 years, 5 months 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. All rights reserved. 2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc. All rights reserved.
3 * Copyright (C) 2008, 2010 Nokia Corporation and/or its subsidiary(-ies) 3 * Copyright (C) 2008, 2010 Nokia Corporation and/or its subsidiary(-ies)
4 * Copyright (C) 2007 Alp Toker <alp@atoker.com> 4 * Copyright (C) 2007 Alp Toker <alp@atoker.com>
5 * Copyright (C) 2008 Eric Seidel <eric@webkit.org> 5 * Copyright (C) 2008 Eric Seidel <eric@webkit.org>
6 * Copyright (C) 2008 Dirk Schulze <krit@webkit.org> 6 * Copyright (C) 2008 Dirk Schulze <krit@webkit.org>
7 * Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved. 7 * Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved.
8 * Copyright (C) 2012, 2013 Intel Corporation. All rights reserved. 8 * Copyright (C) 2012, 2013 Intel Corporation. All rights reserved.
9 * Copyright (C) 2013 Adobe Systems Incorporated. All rights reserved. 9 * Copyright (C) 2013 Adobe Systems Incorporated. All rights reserved.
10 * 10 *
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 } 345 }
346 346
347 void CanvasRenderingContext2D::State::fontsNeedUpdate(CSSFontSelector* fontSelec tor) 347 void CanvasRenderingContext2D::State::fontsNeedUpdate(CSSFontSelector* fontSelec tor)
348 { 348 {
349 ASSERT_ARG(fontSelector, fontSelector == m_font.fontSelector()); 349 ASSERT_ARG(fontSelector, fontSelector == m_font.fontSelector());
350 ASSERT(m_realizedFont); 350 ASSERT(m_realizedFont);
351 351
352 m_font.update(fontSelector); 352 m_font.update(fontSelector);
353 } 353 }
354 354
355 void CanvasRenderingContext2D::State::trace(Visitor* visitor)
356 {
357 visitor->trace(m_strokeStyle);
358 visitor->trace(m_fillStyle);
359 CSSFontSelectorClient::trace(visitor);
360 }
361
355 void CanvasRenderingContext2D::realizeSaves() 362 void CanvasRenderingContext2D::realizeSaves()
356 { 363 {
357 validateStateStack(); 364 validateStateStack();
358 if (state().m_unrealizedSaveCount) { 365 if (state().m_unrealizedSaveCount) {
359 ASSERT(m_stateStack.size() >= 1); 366 ASSERT(m_stateStack.size() >= 1);
360 // Reduce the current state's unrealized count by one now, 367 // Reduce the current state's unrealized count by one now,
361 // to reflect the fact we are saving one state. 368 // to reflect the fact we are saving one state.
362 m_stateStack.last()->m_unrealizedSaveCount--; 369 m_stateStack.last()->m_unrealizedSaveCount--;
363 m_stateStack.append(adoptPtrWillBeNoop(new State(state()))); 370 m_stateStack.append(adoptPtrWillBeNoop(new State(state())));
364 // Set the new state's unrealized count to 0, because it has no outstand ing saves. 371 // Set the new state's unrealized count to 0, because it has no outstand ing saves.
(...skipping 26 matching lines...) Expand all
391 if (c) 398 if (c)
392 c->restore(); 399 c->restore();
393 validateStateStack(); 400 validateStateStack();
394 } 401 }
395 402
396 CanvasStyle* CanvasRenderingContext2D::strokeStyle() const 403 CanvasStyle* CanvasRenderingContext2D::strokeStyle() const
397 { 404 {
398 return state().m_strokeStyle.get(); 405 return state().m_strokeStyle.get();
399 } 406 }
400 407
401 void CanvasRenderingContext2D::setStrokeStyle(PassRefPtr<CanvasStyle> prpStyle) 408 void CanvasRenderingContext2D::setStrokeStyle(PassRefPtrWillBeRawPtr<CanvasStyle > prpStyle)
402 { 409 {
403 RefPtr<CanvasStyle> style = prpStyle; 410 RefPtrWillBeRawPtr<CanvasStyle> style = prpStyle;
404 411
405 if (!style) 412 if (!style)
406 return; 413 return;
407 414
408 if (state().m_strokeStyle && state().m_strokeStyle->isEquivalentColor(*style )) 415 if (state().m_strokeStyle && state().m_strokeStyle->isEquivalentColor(*style ))
409 return; 416 return;
410 417
411 if (style->isCurrentColor()) { 418 if (style->isCurrentColor()) {
412 if (style->hasOverrideAlpha()) 419 if (style->hasOverrideAlpha())
413 style = CanvasStyle::createFromRGBA(colorWithOverrideAlpha(currentCo lor(canvas()), style->overrideAlpha())); 420 style = CanvasStyle::createFromRGBA(colorWithOverrideAlpha(currentCo lor(canvas()), style->overrideAlpha()));
(...skipping 10 matching lines...) Expand all
424 return; 431 return;
425 state().m_strokeStyle->applyStrokeColor(c); 432 state().m_strokeStyle->applyStrokeColor(c);
426 modifiableState().m_unparsedStrokeColor = String(); 433 modifiableState().m_unparsedStrokeColor = String();
427 } 434 }
428 435
429 CanvasStyle* CanvasRenderingContext2D::fillStyle() const 436 CanvasStyle* CanvasRenderingContext2D::fillStyle() const
430 { 437 {
431 return state().m_fillStyle.get(); 438 return state().m_fillStyle.get();
432 } 439 }
433 440
434 void CanvasRenderingContext2D::setFillStyle(PassRefPtr<CanvasStyle> prpStyle) 441 void CanvasRenderingContext2D::setFillStyle(PassRefPtrWillBeRawPtr<CanvasStyle> prpStyle)
435 { 442 {
436 RefPtr<CanvasStyle> style = prpStyle; 443 RefPtrWillBeRawPtr<CanvasStyle> style = prpStyle;
437 444
438 if (!style) 445 if (!style)
439 return; 446 return;
440 447
441 if (state().m_fillStyle && state().m_fillStyle->isEquivalentColor(*style)) 448 if (state().m_fillStyle && state().m_fillStyle->isEquivalentColor(*style))
442 return; 449 return;
443 450
444 if (style->isCurrentColor()) { 451 if (style->isCurrentColor()) {
445 if (style->hasOverrideAlpha()) 452 if (style->hasOverrideAlpha())
446 style = CanvasStyle::createFromRGBA(colorWithOverrideAlpha(currentCo lor(canvas()), style->overrideAlpha())); 453 style = CanvasStyle::createFromRGBA(colorWithOverrideAlpha(currentCo lor(canvas()), style->overrideAlpha()));
(...skipping 1203 matching lines...) Expand 10 before | Expand all | Expand 10 after
1650 GraphicsContext* c = drawingContext(); 1657 GraphicsContext* c = drawingContext();
1651 ASSERT(c); 1658 ASSERT(c);
1652 c->beginLayer(1, state().m_globalComposite); 1659 c->beginLayer(1, state().m_globalComposite);
1653 CompositeOperator previousOperator = c->compositeOperation(); 1660 CompositeOperator previousOperator = c->compositeOperation();
1654 c->setCompositeOperation(CompositeSourceOver); 1661 c->setCompositeOperation(CompositeSourceOver);
1655 strokePrimitive(area, c); 1662 strokePrimitive(area, c);
1656 c->setCompositeOperation(previousOperator); 1663 c->setCompositeOperation(previousOperator);
1657 c->endLayer(); 1664 c->endLayer();
1658 } 1665 }
1659 1666
1660 PassRefPtr<CanvasGradient> CanvasRenderingContext2D::createLinearGradient(float x0, float y0, float x1, float y1) 1667 PassRefPtrWillBeRawPtr<CanvasGradient> CanvasRenderingContext2D::createLinearGra dient(float x0, float y0, float x1, float y1)
1661 { 1668 {
1662 RefPtr<CanvasGradient> gradient = CanvasGradient::create(FloatPoint(x0, y0), FloatPoint(x1, y1)); 1669 RefPtrWillBeRawPtr<CanvasGradient> gradient = CanvasGradient::create(FloatPo int(x0, y0), FloatPoint(x1, y1));
1663 return gradient.release(); 1670 return gradient.release();
1664 } 1671 }
1665 1672
1666 PassRefPtr<CanvasGradient> CanvasRenderingContext2D::createRadialGradient(float x0, float y0, float r0, float x1, float y1, float r1, ExceptionState& exceptionS tate) 1673 PassRefPtrWillBeRawPtr<CanvasGradient> CanvasRenderingContext2D::createRadialGra dient(float x0, float y0, float r0, float x1, float y1, float r1, ExceptionState & exceptionState)
1667 { 1674 {
1668 if (r0 < 0 || r1 < 0) { 1675 if (r0 < 0 || r1 < 0) {
1669 exceptionState.throwDOMException(IndexSizeError, String::format("The %s provided is less than 0.", r0 < 0 ? "r0" : "r1")); 1676 exceptionState.throwDOMException(IndexSizeError, String::format("The %s provided is less than 0.", r0 < 0 ? "r0" : "r1"));
1670 return nullptr; 1677 return nullptr;
1671 } 1678 }
1672 1679
1673 RefPtr<CanvasGradient> gradient = CanvasGradient::create(FloatPoint(x0, y0), r0, FloatPoint(x1, y1), r1); 1680 RefPtrWillBeRawPtr<CanvasGradient> gradient = CanvasGradient::create(FloatPo int(x0, y0), r0, FloatPoint(x1, y1), r1);
1674 return gradient.release(); 1681 return gradient.release();
1675 } 1682 }
1676 1683
1677 PassRefPtr<CanvasPattern> CanvasRenderingContext2D::createPattern(CanvasImageSou rce* imageSource, 1684 PassRefPtrWillBeRawPtr<CanvasPattern> CanvasRenderingContext2D::createPattern(Ca nvasImageSource* imageSource,
1678 const String& repetitionType, ExceptionState& exceptionState) 1685 const String& repetitionType, ExceptionState& exceptionState)
1679 { 1686 {
1680 bool repeatX, repeatY; 1687 bool repeatX, repeatY;
1681 CanvasPattern::parseRepetitionType(repetitionType, repeatX, repeatY, excepti onState); 1688 CanvasPattern::parseRepetitionType(repetitionType, repeatX, repeatY, excepti onState);
1682 if (exceptionState.hadException()) 1689 if (exceptionState.hadException())
1683 return nullptr; 1690 return nullptr;
1684 1691
1685 SourceImageStatus status; 1692 SourceImageStatus status;
1686 RefPtr<Image> imageForRendering = imageSource->getSourceImageForCanvas(CopyS ourceImageIfVolatile, &status); 1693 RefPtr<Image> imageForRendering = imageSource->getSourceImageForCanvas(CopyS ourceImageIfVolatile, &status);
1687 1694
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after
2049 for (unsigned i = 0; i < textLength; i++) { 2056 for (unsigned i = 0; i < textLength; i++) {
2050 if (isSpaceCharacter(text[i])) 2057 if (isSpaceCharacter(text[i]))
2051 charVector[i] = ' '; 2058 charVector[i] = ' ';
2052 else 2059 else
2053 charVector[i] = text[i]; 2060 charVector[i] = text[i];
2054 } 2061 }
2055 2062
2056 return String(charVector); 2063 return String(charVector);
2057 } 2064 }
2058 2065
2059 PassRefPtr<TextMetrics> CanvasRenderingContext2D::measureText(const String& text ) 2066 PassRefPtrWillBeRawPtr<TextMetrics> CanvasRenderingContext2D::measureText(const String& text)
2060 { 2067 {
2061 RefPtr<TextMetrics> metrics = TextMetrics::create(); 2068 RefPtrWillBeRawPtr<TextMetrics> metrics = TextMetrics::create();
2062 2069
2063 // The style resolution required for rendering text is not available in fram e-less documents. 2070 // The style resolution required for rendering text is not available in fram e-less documents.
2064 if (!canvas()->document().frame()) 2071 if (!canvas()->document().frame())
2065 return metrics.release(); 2072 return metrics.release();
2066 2073
2067 FontCachePurgePreventer fontCachePurgePreventer; 2074 FontCachePurgePreventer fontCachePurgePreventer;
2068 canvas()->document().updateRenderTreeIfNeeded(); 2075 canvas()->document().updateRenderTreeIfNeeded();
2069 const Font& font = accessFont(); 2076 const Font& font = accessFont();
2070 String normalizedText = normalizeSpaces(text); 2077 String normalizedText = normalizeSpaces(text);
2071 const TextRun textRun(normalizedText); 2078 const TextRun textRun(normalizedText);
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
2273 if (enabled == state().m_imageSmoothingEnabled) 2280 if (enabled == state().m_imageSmoothingEnabled)
2274 return; 2281 return;
2275 2282
2276 realizeSaves(); 2283 realizeSaves();
2277 modifiableState().m_imageSmoothingEnabled = enabled; 2284 modifiableState().m_imageSmoothingEnabled = enabled;
2278 GraphicsContext* c = drawingContext(); 2285 GraphicsContext* c = drawingContext();
2279 if (c) 2286 if (c)
2280 c->setImageInterpolationQuality(enabled ? CanvasDefaultInterpolationQual ity : InterpolationNone); 2287 c->setImageInterpolationQuality(enabled ? CanvasDefaultInterpolationQual ity : InterpolationNone);
2281 } 2288 }
2282 2289
2283 PassRefPtr<Canvas2DContextAttributes> CanvasRenderingContext2D::getContextAttrib utes() const 2290 PassRefPtrWillBeRawPtr<Canvas2DContextAttributes> CanvasRenderingContext2D::getC ontextAttributes() const
2284 { 2291 {
2285 RefPtr<Canvas2DContextAttributes> attributes = Canvas2DContextAttributes::cr eate(); 2292 RefPtrWillBeRawPtr<Canvas2DContextAttributes> attributes = Canvas2DContextAt tributes::create();
2286 attributes->setAlpha(m_hasAlpha); 2293 attributes->setAlpha(m_hasAlpha);
2287 return attributes.release(); 2294 return attributes.release();
2288 } 2295 }
2289 2296
2290 void CanvasRenderingContext2D::drawFocusIfNeeded(Element* element) 2297 void CanvasRenderingContext2D::drawFocusIfNeeded(Element* element)
2291 { 2298 {
2292 drawFocusIfNeededInternal(m_path, element); 2299 drawFocusIfNeededInternal(m_path, element);
2293 } 2300 }
2294 2301
2295 void CanvasRenderingContext2D::drawFocusIfNeeded(Path2D* path2d, Element* elemen t) 2302 void CanvasRenderingContext2D::drawFocusIfNeeded(Path2D* path2d, Element* elemen t)
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
2360 { 2367 {
2361 HitRegionOptions passOptions; 2368 HitRegionOptions passOptions;
2362 2369
2363 options.getWithUndefinedOrNullCheck("id", passOptions.id); 2370 options.getWithUndefinedOrNullCheck("id", passOptions.id);
2364 options.getWithUndefinedOrNullCheck("control", passOptions.control); 2371 options.getWithUndefinedOrNullCheck("control", passOptions.control);
2365 if (passOptions.id.isEmpty() && !passOptions.control) { 2372 if (passOptions.id.isEmpty() && !passOptions.control) {
2366 exceptionState.throwDOMException(NotSupportedError, "Both id and control are null."); 2373 exceptionState.throwDOMException(NotSupportedError, "Both id and control are null.");
2367 return; 2374 return;
2368 } 2375 }
2369 2376
2370 RefPtr<Path2D> path2d; 2377 RefPtrWillBeMember<Path2D> path2d;
2371 options.getWithUndefinedOrNullCheck("path", path2d); 2378 options.getWithUndefinedOrNullCheck("path", path2d);
2372 Path hitRegionPath = path2d ? path2d->path() : m_path; 2379 Path hitRegionPath = path2d ? path2d->path() : m_path;
2373 2380
2374 FloatRect clipBounds; 2381 FloatRect clipBounds;
2375 GraphicsContext* context = drawingContext(); 2382 GraphicsContext* context = drawingContext();
2376 2383
2377 if (hitRegionPath.isEmpty() || !context || !state().m_invertibleCTM 2384 if (hitRegionPath.isEmpty() || !context || !state().m_invertibleCTM
2378 || !context->getTransformedClipBounds(&clipBounds)) { 2385 || !context->getTransformedClipBounds(&clipBounds)) {
2379 exceptionState.throwDOMException(NotSupportedError, "The specified path has no pixels."); 2386 exceptionState.throwDOMException(NotSupportedError, "The specified path has no pixels.");
2380 return; 2387 return;
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
2438 2445
2439 unsigned CanvasRenderingContext2D::hitRegionsCount() const 2446 unsigned CanvasRenderingContext2D::hitRegionsCount() const
2440 { 2447 {
2441 if (m_hitRegionManager) 2448 if (m_hitRegionManager)
2442 return m_hitRegionManager->getHitRegionsCount(); 2449 return m_hitRegionManager->getHitRegionsCount();
2443 2450
2444 return 0; 2451 return 0;
2445 } 2452 }
2446 2453
2447 } // namespace blink 2454 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698