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

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: Make WebGLObjects keep a blink::WebGraphicsContext3D for finalization. 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 369 matching lines...) Expand 10 before | Expand all | Expand 10 after
2057 for (unsigned i = 0; i < textLength; i++) { 2064 for (unsigned i = 0; i < textLength; i++) {
2058 if (isSpaceCharacter(text[i])) 2065 if (isSpaceCharacter(text[i]))
2059 charVector[i] = ' '; 2066 charVector[i] = ' ';
2060 else 2067 else
2061 charVector[i] = text[i]; 2068 charVector[i] = text[i];
2062 } 2069 }
2063 2070
2064 return String(charVector); 2071 return String(charVector);
2065 } 2072 }
2066 2073
2067 PassRefPtr<TextMetrics> CanvasRenderingContext2D::measureText(const String& text ) 2074 PassRefPtrWillBeRawPtr<TextMetrics> CanvasRenderingContext2D::measureText(const String& text)
2068 { 2075 {
2069 RefPtr<TextMetrics> metrics = TextMetrics::create(); 2076 RefPtrWillBeRawPtr<TextMetrics> metrics = TextMetrics::create();
2070 2077
2071 // The style resolution required for rendering text is not available in fram e-less documents. 2078 // The style resolution required for rendering text is not available in fram e-less documents.
2072 if (!canvas()->document().frame()) 2079 if (!canvas()->document().frame())
2073 return metrics.release(); 2080 return metrics.release();
2074 2081
2075 FontCachePurgePreventer fontCachePurgePreventer; 2082 FontCachePurgePreventer fontCachePurgePreventer;
2076 canvas()->document().updateRenderTreeIfNeeded(); 2083 canvas()->document().updateRenderTreeIfNeeded();
2077 const Font& font = accessFont(); 2084 const Font& font = accessFont();
2078 String normalizedText = normalizeSpaces(text); 2085 String normalizedText = normalizeSpaces(text);
2079 const TextRun textRun(normalizedText); 2086 const TextRun textRun(normalizedText);
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
2281 if (enabled == state().m_imageSmoothingEnabled) 2288 if (enabled == state().m_imageSmoothingEnabled)
2282 return; 2289 return;
2283 2290
2284 realizeSaves(); 2291 realizeSaves();
2285 modifiableState().m_imageSmoothingEnabled = enabled; 2292 modifiableState().m_imageSmoothingEnabled = enabled;
2286 GraphicsContext* c = drawingContext(); 2293 GraphicsContext* c = drawingContext();
2287 if (c) 2294 if (c)
2288 c->setImageInterpolationQuality(enabled ? CanvasDefaultInterpolationQual ity : InterpolationNone); 2295 c->setImageInterpolationQuality(enabled ? CanvasDefaultInterpolationQual ity : InterpolationNone);
2289 } 2296 }
2290 2297
2291 PassRefPtr<Canvas2DContextAttributes> CanvasRenderingContext2D::getContextAttrib utes() const 2298 PassRefPtrWillBeRawPtr<Canvas2DContextAttributes> CanvasRenderingContext2D::getC ontextAttributes() const
2292 { 2299 {
2293 RefPtr<Canvas2DContextAttributes> attributes = Canvas2DContextAttributes::cr eate(); 2300 RefPtrWillBeRawPtr<Canvas2DContextAttributes> attributes = Canvas2DContextAt tributes::create();
2294 attributes->setAlpha(m_hasAlpha); 2301 attributes->setAlpha(m_hasAlpha);
2295 return attributes.release(); 2302 return attributes.release();
2296 } 2303 }
2297 2304
2298 void CanvasRenderingContext2D::drawFocusIfNeeded(Element* element) 2305 void CanvasRenderingContext2D::drawFocusIfNeeded(Element* element)
2299 { 2306 {
2300 drawFocusIfNeededInternal(m_path, element); 2307 drawFocusIfNeededInternal(m_path, element);
2301 } 2308 }
2302 2309
2303 void CanvasRenderingContext2D::drawFocusIfNeeded(Path2D* path2d, Element* elemen t) 2310 void CanvasRenderingContext2D::drawFocusIfNeeded(Path2D* path2d, Element* elemen t)
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
2368 { 2375 {
2369 HitRegionOptions passOptions; 2376 HitRegionOptions passOptions;
2370 2377
2371 options.getWithUndefinedOrNullCheck("id", passOptions.id); 2378 options.getWithUndefinedOrNullCheck("id", passOptions.id);
2372 options.getWithUndefinedOrNullCheck("control", passOptions.control); 2379 options.getWithUndefinedOrNullCheck("control", passOptions.control);
2373 if (passOptions.id.isEmpty() && !passOptions.control) { 2380 if (passOptions.id.isEmpty() && !passOptions.control) {
2374 exceptionState.throwDOMException(NotSupportedError, "Both id and control are null."); 2381 exceptionState.throwDOMException(NotSupportedError, "Both id and control are null.");
2375 return; 2382 return;
2376 } 2383 }
2377 2384
2378 RefPtr<Path2D> path2d; 2385 RefPtrWillBeMember<Path2D> path2d;
Mads Ager (chromium) 2014/07/11 09:15:01 RefPtrWillBeRawPtr<Path2D> path2d = nullptr;
2379 options.getWithUndefinedOrNullCheck("path", path2d); 2386 options.getWithUndefinedOrNullCheck("path", path2d);
2380 Path hitRegionPath = path2d ? path2d->path() : m_path; 2387 Path hitRegionPath = path2d ? path2d->path() : m_path;
2381 2388
2382 FloatRect clipBounds; 2389 FloatRect clipBounds;
2383 GraphicsContext* context = drawingContext(); 2390 GraphicsContext* context = drawingContext();
2384 2391
2385 if (hitRegionPath.isEmpty() || !context || !state().m_invertibleCTM 2392 if (hitRegionPath.isEmpty() || !context || !state().m_invertibleCTM
2386 || !context->getTransformedClipBounds(&clipBounds)) { 2393 || !context->getTransformedClipBounds(&clipBounds)) {
2387 exceptionState.throwDOMException(NotSupportedError, "The specified path has no pixels."); 2394 exceptionState.throwDOMException(NotSupportedError, "The specified path has no pixels.");
2388 return; 2395 return;
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
2446 2453
2447 unsigned CanvasRenderingContext2D::hitRegionsCount() const 2454 unsigned CanvasRenderingContext2D::hitRegionsCount() const
2448 { 2455 {
2449 if (m_hitRegionManager) 2456 if (m_hitRegionManager)
2450 return m_hitRegionManager->getHitRegionsCount(); 2457 return m_hitRegionManager->getHitRegionsCount();
2451 2458
2452 return 0; 2459 return 0;
2453 } 2460 }
2454 2461
2455 } // namespace WebCore 2462 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698