Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2004, 2006, 2007 Apple Inc. All rights reserved. | 2 * Copyright (C) 2004, 2006, 2007 Apple Inc. All rights reserved. |
| 3 * Copyright (C) 2007 Alp Toker <alp@atoker.com> | 3 * Copyright (C) 2007 Alp Toker <alp@atoker.com> |
| 4 * Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved. | 4 * Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved. |
| 5 * | 5 * |
| 6 * Redistribution and use in source and binary forms, with or without | 6 * Redistribution and use in source and binary forms, with or without |
| 7 * modification, are permitted provided that the following conditions | 7 * modification, are permitted provided that the following conditions |
| 8 * are met: | 8 * are met: |
| 9 * 1. Redistributions of source code must retain the above copyright | 9 * 1. Redistributions of source code must retain the above copyright |
| 10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 104 | 104 |
| 105 } // namespace | 105 } // namespace |
| 106 | 106 |
| 107 DEFINE_EMPTY_DESTRUCTOR_WILL_BE_REMOVED(CanvasObserver); | 107 DEFINE_EMPTY_DESTRUCTOR_WILL_BE_REMOVED(CanvasObserver); |
| 108 | 108 |
| 109 inline HTMLCanvasElement::HTMLCanvasElement(Document& document) | 109 inline HTMLCanvasElement::HTMLCanvasElement(Document& document) |
| 110 : HTMLElement(canvasTag, document) | 110 : HTMLElement(canvasTag, document) |
| 111 , DocumentVisibilityObserver(document) | 111 , DocumentVisibilityObserver(document) |
| 112 , m_size(DefaultWidth, DefaultHeight) | 112 , m_size(DefaultWidth, DefaultHeight) |
| 113 , m_ignoreReset(false) | 113 , m_ignoreReset(false) |
| 114 , m_accelerationDisabled(false) | |
| 115 , m_externallyAllocatedMemory(0) | 114 , m_externallyAllocatedMemory(0) |
| 116 , m_originClean(true) | 115 , m_originClean(true) |
| 117 , m_didFailToCreateImageBuffer(false) | 116 , m_didFailToCreateImageBuffer(false) |
| 118 , m_imageBufferIsClear(false) | 117 , m_imageBufferIsClear(false) |
| 119 { | 118 { |
| 120 setHasCustomStyleCallbacks(); | 119 setHasCustomStyleCallbacks(); |
| 121 } | 120 } |
| 122 | 121 |
| 123 DEFINE_NODE_FACTORY(HTMLCanvasElement) | 122 DEFINE_NODE_FACTORY(HTMLCanvasElement) |
| 124 | 123 |
| 125 HTMLCanvasElement::~HTMLCanvasElement() | 124 HTMLCanvasElement::~HTMLCanvasElement() |
| 126 { | 125 { |
| 127 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(-m_external lyAllocatedMemory); | 126 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(-m_external lyAllocatedMemory); |
| 128 #if !ENABLE(OILPAN) | 127 #if !ENABLE(OILPAN) |
| 129 for (CanvasObserver* canvasObserver : m_observers) | |
| 130 canvasObserver->canvasDestroyed(this); | |
| 131 // Ensure these go away before the ImageBuffer. | 128 // Ensure these go away before the ImageBuffer. |
| 132 m_context.clear(); | 129 m_context.clear(); |
| 133 #endif | 130 #endif |
| 134 } | 131 } |
| 135 | 132 |
| 136 WebThread* HTMLCanvasElement::getToBlobThreadInstance() | 133 WebThread* HTMLCanvasElement::getToBlobThreadInstance() |
| 137 { | 134 { |
| 138 DEFINE_STATIC_LOCAL(OwnPtr<WebThread>, s_toBlobThread, ()); | 135 DEFINE_STATIC_LOCAL(OwnPtr<WebThread>, s_toBlobThread, ()); |
| 139 if (!s_toBlobThread) { | 136 if (!s_toBlobThread) { |
| 140 s_toBlobThread = adoptPtr(Platform::current()->createThread("Async toBlo b")); | 137 s_toBlobThread = adoptPtr(Platform::current()->createThread("Async toBlo b")); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 174 m_imageBuffer->setFilterQuality(filterQuality); | 171 m_imageBuffer->setFilterQuality(filterQuality); |
| 175 } | 172 } |
| 176 } | 173 } |
| 177 | 174 |
| 178 Node::InsertionNotificationRequest HTMLCanvasElement::insertedInto(ContainerNode * node) | 175 Node::InsertionNotificationRequest HTMLCanvasElement::insertedInto(ContainerNode * node) |
| 179 { | 176 { |
| 180 setIsInCanvasSubtree(true); | 177 setIsInCanvasSubtree(true); |
| 181 return HTMLElement::insertedInto(node); | 178 return HTMLElement::insertedInto(node); |
| 182 } | 179 } |
| 183 | 180 |
| 184 void HTMLCanvasElement::addObserver(CanvasObserver* observer) | |
| 185 { | |
| 186 m_observers.add(observer); | |
| 187 } | |
| 188 | |
| 189 void HTMLCanvasElement::removeObserver(CanvasObserver* observer) | |
| 190 { | |
| 191 m_observers.remove(observer); | |
| 192 } | |
| 193 | |
| 194 void HTMLCanvasElement::setHeight(int value) | 181 void HTMLCanvasElement::setHeight(int value) |
| 195 { | 182 { |
| 196 setIntegralAttribute(heightAttr, value); | 183 setIntegralAttribute(heightAttr, value); |
| 197 } | 184 } |
| 198 | 185 |
| 199 void HTMLCanvasElement::setWidth(int value) | 186 void HTMLCanvasElement::setWidth(int value) |
| 200 { | 187 { |
| 201 setIntegralAttribute(widthAttr, value); | 188 setIntegralAttribute(widthAttr, value); |
| 202 } | 189 } |
| 203 | 190 |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 291 { | 278 { |
| 292 if (rect.isEmpty()) | 279 if (rect.isEmpty()) |
| 293 return; | 280 return; |
| 294 m_imageBufferIsClear = false; | 281 m_imageBufferIsClear = false; |
| 295 clearCopiedImage(); | 282 clearCopiedImage(); |
| 296 if (layoutObject()) | 283 if (layoutObject()) |
| 297 layoutObject()->setMayNeedPaintInvalidation(); | 284 layoutObject()->setMayNeedPaintInvalidation(); |
| 298 m_dirtyRect.unite(rect); | 285 m_dirtyRect.unite(rect); |
| 299 if (m_context && m_context->is2d() && hasImageBuffer()) | 286 if (m_context && m_context->is2d() && hasImageBuffer()) |
| 300 buffer()->didDraw(rect); | 287 buffer()->didDraw(rect); |
| 301 notifyObserversCanvasChanged(rect); | |
| 302 } | 288 } |
| 303 | 289 |
| 304 void HTMLCanvasElement::didFinalizeFrame() | 290 void HTMLCanvasElement::didFinalizeFrame() |
| 305 { | 291 { |
| 306 if (m_dirtyRect.isEmpty()) | 292 if (m_dirtyRect.isEmpty()) |
| 307 return; | 293 return; |
| 308 | 294 |
| 309 // Propagate the m_dirtyRect accumulated so far to the compositor | 295 // Propagate the m_dirtyRect accumulated so far to the compositor |
| 310 // before restarting with a blank dirty rect. | 296 // before restarting with a blank dirty rect. |
| 311 FloatRect srcRect(0, 0, size().width(), size().height()); | 297 FloatRect srcRect(0, 0, size().width(), size().height()); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 348 mappedDirtyRect.move(-lb->contentBoxOffset()); | 334 mappedDirtyRect.move(-lb->contentBoxOffset()); |
| 349 } | 335 } |
| 350 m_imageBuffer->finalizeFrame(mappedDirtyRect); | 336 m_imageBuffer->finalizeFrame(mappedDirtyRect); |
| 351 } else { | 337 } else { |
| 352 m_imageBuffer->finalizeFrame(m_dirtyRect); | 338 m_imageBuffer->finalizeFrame(m_dirtyRect); |
| 353 } | 339 } |
| 354 } | 340 } |
| 355 ASSERT(m_dirtyRect.isEmpty()); | 341 ASSERT(m_dirtyRect.isEmpty()); |
| 356 } | 342 } |
| 357 | 343 |
| 358 void HTMLCanvasElement::notifyObserversCanvasChanged(const FloatRect& rect) | |
| 359 { | |
| 360 for (CanvasObserver* canvasObserver : m_observers) | |
| 361 canvasObserver->canvasChanged(this, rect); | |
| 362 } | |
| 363 | |
| 364 void HTMLCanvasElement::reset() | 344 void HTMLCanvasElement::reset() |
| 365 { | 345 { |
| 366 if (m_ignoreReset) | 346 if (m_ignoreReset) |
| 367 return; | 347 return; |
| 368 | 348 |
| 369 m_dirtyRect = FloatRect(); | 349 m_dirtyRect = FloatRect(); |
| 370 | 350 |
| 371 bool ok; | 351 bool ok; |
| 372 bool hadImageBuffer = hasImageBuffer(); | 352 bool hadImageBuffer = hasImageBuffer(); |
| 373 | 353 |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 404 if (layoutObject->isCanvas()) { | 384 if (layoutObject->isCanvas()) { |
| 405 if (oldSize != size()) { | 385 if (oldSize != size()) { |
| 406 toLayoutHTMLCanvas(layoutObject)->canvasSizeChanged(); | 386 toLayoutHTMLCanvas(layoutObject)->canvasSizeChanged(); |
| 407 if (layoutBox() && layoutBox()->hasAcceleratedCompositing()) | 387 if (layoutBox() && layoutBox()->hasAcceleratedCompositing()) |
| 408 layoutBox()->contentChanged(CanvasChanged); | 388 layoutBox()->contentChanged(CanvasChanged); |
| 409 } | 389 } |
| 410 if (hadImageBuffer) | 390 if (hadImageBuffer) |
| 411 layoutObject->setShouldDoFullPaintInvalidation(); | 391 layoutObject->setShouldDoFullPaintInvalidation(); |
| 412 } | 392 } |
| 413 } | 393 } |
| 414 | |
| 415 for (CanvasObserver* canvasObserver : m_observers) | |
| 416 canvasObserver->canvasResized(this); | |
| 417 } | 394 } |
| 418 | 395 |
| 419 bool HTMLCanvasElement::paintsIntoCanvasBuffer() const | 396 bool HTMLCanvasElement::paintsIntoCanvasBuffer() const |
| 420 { | 397 { |
| 421 ASSERT(m_context); | 398 ASSERT(m_context); |
| 422 | 399 |
| 423 if (!m_context->isAccelerated()) | 400 if (!m_context->isAccelerated()) |
| 424 return true; | 401 return true; |
| 425 | 402 |
| 426 if (layoutBox() && layoutBox()->hasAcceleratedCompositing()) | 403 if (layoutBox() && layoutBox()->hasAcceleratedCompositing()) |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 623 if (document().settings() && document().settings()->disableReadingFromCanvas ()) | 600 if (document().settings() && document().settings()->disableReadingFromCanvas ()) |
| 624 return false; | 601 return false; |
| 625 return m_originClean; | 602 return m_originClean; |
| 626 } | 603 } |
| 627 | 604 |
| 628 bool HTMLCanvasElement::shouldAccelerate(const IntSize& size) const | 605 bool HTMLCanvasElement::shouldAccelerate(const IntSize& size) const |
| 629 { | 606 { |
| 630 if (m_context && !m_context->is2d()) | 607 if (m_context && !m_context->is2d()) |
| 631 return false; | 608 return false; |
| 632 | 609 |
| 633 if (m_accelerationDisabled) | |
| 634 return false; | |
| 635 | |
| 636 if (RuntimeEnabledFeatures::forceDisplayList2dCanvasEnabled()) | 610 if (RuntimeEnabledFeatures::forceDisplayList2dCanvasEnabled()) |
| 637 return false; | 611 return false; |
| 638 | 612 |
| 639 Settings* settings = document().settings(); | 613 Settings* settings = document().settings(); |
| 640 if (!settings || !settings->accelerated2dCanvasEnabled()) | 614 if (!settings || !settings->accelerated2dCanvasEnabled()) |
| 641 return false; | 615 return false; |
| 642 | 616 |
| 643 int canvasPixelCount = size.width() * size.height(); | 617 int canvasPixelCount = size.width() * size.height(); |
| 644 | 618 |
| 645 if (RuntimeEnabledFeatures::displayList2dCanvasEnabled()) { | 619 if (RuntimeEnabledFeatures::displayList2dCanvasEnabled()) { |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 688 return true; | 662 return true; |
| 689 } | 663 } |
| 690 | 664 |
| 691 PassOwnPtr<ImageBufferSurface> HTMLCanvasElement::createImageBufferSurface(const IntSize& deviceSize, int* msaaSampleCount) | 665 PassOwnPtr<ImageBufferSurface> HTMLCanvasElement::createImageBufferSurface(const IntSize& deviceSize, int* msaaSampleCount) |
| 692 { | 666 { |
| 693 OpacityMode opacityMode = !m_context || m_context->hasAlpha() ? NonOpaque : Opaque; | 667 OpacityMode opacityMode = !m_context || m_context->hasAlpha() ? NonOpaque : Opaque; |
| 694 | 668 |
| 695 *msaaSampleCount = 0; | 669 *msaaSampleCount = 0; |
| 696 if (is3D()) { | 670 if (is3D()) { |
| 697 // If 3d, but the use of the canvas will be for non-accelerated content | 671 // If 3d, but the use of the canvas will be for non-accelerated content |
| 698 // (such as -webkit-canvas, then then make a non-accelerated | 672 // then make a non-accelerated |
|
pdr.
2015/10/23 18:23:55
Nit: This looks weird on my 80 column punchcards.
chrishtr
2015/10/23 19:47:06
Done.
| |
| 699 // ImageBuffer. This means copying the internal Image will require a | 673 // ImageBuffer. This means copying the internal Image will require a |
| 700 // pixel readback, but that is unavoidable in this case. | 674 // pixel readback, but that is unavoidable in this case. |
| 701 // FIXME: Actually, avoid setting m_accelerationDisabled at all when | |
| 702 // doing GPU-based rasterization. | |
| 703 if (m_accelerationDisabled) | |
| 704 return adoptPtr(new UnacceleratedImageBufferSurface(deviceSize, opac ityMode)); | |
| 705 return adoptPtr(new AcceleratedImageBufferSurface(deviceSize, opacityMod e)); | 675 return adoptPtr(new AcceleratedImageBufferSurface(deviceSize, opacityMod e)); |
| 706 } | 676 } |
| 707 | 677 |
| 708 if (shouldAccelerate(deviceSize)) { | 678 if (shouldAccelerate(deviceSize)) { |
| 709 if (document().settings()) | 679 if (document().settings()) |
| 710 *msaaSampleCount = document().settings()->accelerated2dCanvasMSAASam pleCount(); | 680 *msaaSampleCount = document().settings()->accelerated2dCanvasMSAASam pleCount(); |
| 711 OwnPtr<ImageBufferSurface> surface = adoptPtr(new Canvas2DImageBufferSur face(deviceSize, *msaaSampleCount, opacityMode, Canvas2DLayerBridge::EnableAccel eration)); | 681 OwnPtr<ImageBufferSurface> surface = adoptPtr(new Canvas2DImageBufferSur face(deviceSize, *msaaSampleCount, opacityMode, Canvas2DLayerBridge::EnableAccel eration)); |
| 712 if (surface->isValid()) | 682 if (surface->isValid()) |
| 713 return surface.release(); | 683 return surface.release(); |
| 714 } | 684 } |
| (...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 979 { | 949 { |
| 980 return FloatSize(width(), height()); | 950 return FloatSize(width(), height()); |
| 981 } | 951 } |
| 982 | 952 |
| 983 bool HTMLCanvasElement::isOpaque() const | 953 bool HTMLCanvasElement::isOpaque() const |
| 984 { | 954 { |
| 985 return m_context && !m_context->hasAlpha(); | 955 return m_context && !m_context->hasAlpha(); |
| 986 } | 956 } |
| 987 | 957 |
| 988 } // blink | 958 } // blink |
| OLD | NEW |