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 30 matching lines...) Expand all Loading... |
41 #include "core/html/canvas/CanvasAsyncBlobCreator.h" | 41 #include "core/html/canvas/CanvasAsyncBlobCreator.h" |
42 #include "core/html/canvas/CanvasContextCreationAttributes.h" | 42 #include "core/html/canvas/CanvasContextCreationAttributes.h" |
43 #include "core/html/canvas/CanvasFontCache.h" | 43 #include "core/html/canvas/CanvasFontCache.h" |
44 #include "core/html/canvas/CanvasRenderingContext.h" | 44 #include "core/html/canvas/CanvasRenderingContext.h" |
45 #include "core/html/canvas/CanvasRenderingContextFactory.h" | 45 #include "core/html/canvas/CanvasRenderingContextFactory.h" |
46 #include "core/layout/LayoutHTMLCanvas.h" | 46 #include "core/layout/LayoutHTMLCanvas.h" |
47 #include "core/paint/PaintLayer.h" | 47 #include "core/paint/PaintLayer.h" |
48 #include "platform/MIMETypeRegistry.h" | 48 #include "platform/MIMETypeRegistry.h" |
49 #include "platform/RuntimeEnabledFeatures.h" | 49 #include "platform/RuntimeEnabledFeatures.h" |
50 #include "platform/graphics/Canvas2DImageBufferSurface.h" | 50 #include "platform/graphics/Canvas2DImageBufferSurface.h" |
| 51 #include "platform/graphics/CanvasMetrics.h" |
51 #include "platform/graphics/ExpensiveCanvasHeuristicParameters.h" | 52 #include "platform/graphics/ExpensiveCanvasHeuristicParameters.h" |
52 #include "platform/graphics/ImageBuffer.h" | 53 #include "platform/graphics/ImageBuffer.h" |
53 #include "platform/graphics/RecordingImageBufferSurface.h" | 54 #include "platform/graphics/RecordingImageBufferSurface.h" |
54 #include "platform/graphics/StaticBitmapImage.h" | 55 #include "platform/graphics/StaticBitmapImage.h" |
55 #include "platform/graphics/UnacceleratedImageBufferSurface.h" | 56 #include "platform/graphics/UnacceleratedImageBufferSurface.h" |
56 #include "platform/graphics/gpu/AcceleratedImageBufferSurface.h" | 57 #include "platform/graphics/gpu/AcceleratedImageBufferSurface.h" |
57 #include "platform/transforms/AffineTransform.h" | 58 #include "platform/transforms/AffineTransform.h" |
58 #include "public/platform/Platform.h" | 59 #include "public/platform/Platform.h" |
59 #include "public/platform/WebTraceLocation.h" | 60 #include "public/platform/WebTraceLocation.h" |
60 #include <math.h> | 61 #include <math.h> |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 : HTMLElement(canvasTag, document) | 111 : HTMLElement(canvasTag, document) |
111 , DocumentVisibilityObserver(document) | 112 , DocumentVisibilityObserver(document) |
112 , m_size(DefaultWidth, DefaultHeight) | 113 , m_size(DefaultWidth, DefaultHeight) |
113 , m_ignoreReset(false) | 114 , m_ignoreReset(false) |
114 , m_externallyAllocatedMemory(0) | 115 , m_externallyAllocatedMemory(0) |
115 , m_originClean(true) | 116 , m_originClean(true) |
116 , m_didFailToCreateImageBuffer(false) | 117 , m_didFailToCreateImageBuffer(false) |
117 , m_imageBufferIsClear(false) | 118 , m_imageBufferIsClear(false) |
118 { | 119 { |
119 setHasCustomStyleCallbacks(); | 120 setHasCustomStyleCallbacks(); |
| 121 CanvasMetrics::countCanvasContextUsage(CanvasMetrics::CanvasCreated); |
120 } | 122 } |
121 | 123 |
122 DEFINE_NODE_FACTORY(HTMLCanvasElement) | 124 DEFINE_NODE_FACTORY(HTMLCanvasElement) |
123 | 125 |
124 HTMLCanvasElement::~HTMLCanvasElement() | 126 HTMLCanvasElement::~HTMLCanvasElement() |
125 { | 127 { |
126 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(-m_external
lyAllocatedMemory); | 128 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(-m_external
lyAllocatedMemory); |
127 #if !ENABLE(OILPAN) | 129 #if !ENABLE(OILPAN) |
128 // Ensure these go away before the ImageBuffer. | 130 // Ensure these go away before the ImageBuffer. |
129 m_context.clear(); | 131 m_context.clear(); |
(...skipping 516 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
646 // If 3d, but the use of the canvas will be for non-accelerated content | 648 // If 3d, but the use of the canvas will be for non-accelerated content |
647 // then make a non-accelerated ImageBuffer. This means copying the inter
nal | 649 // then make a non-accelerated ImageBuffer. This means copying the inter
nal |
648 // Image will require a pixel readback, but that is unavoidable in this
case. | 650 // Image will require a pixel readback, but that is unavoidable in this
case. |
649 return adoptPtr(new AcceleratedImageBufferSurface(deviceSize, opacityMod
e)); | 651 return adoptPtr(new AcceleratedImageBufferSurface(deviceSize, opacityMod
e)); |
650 } | 652 } |
651 | 653 |
652 if (shouldAccelerate(deviceSize)) { | 654 if (shouldAccelerate(deviceSize)) { |
653 if (document().settings()) | 655 if (document().settings()) |
654 *msaaSampleCount = document().settings()->accelerated2dCanvasMSAASam
pleCount(); | 656 *msaaSampleCount = document().settings()->accelerated2dCanvasMSAASam
pleCount(); |
655 OwnPtr<ImageBufferSurface> surface = adoptPtr(new Canvas2DImageBufferSur
face(deviceSize, *msaaSampleCount, opacityMode, Canvas2DLayerBridge::EnableAccel
eration)); | 657 OwnPtr<ImageBufferSurface> surface = adoptPtr(new Canvas2DImageBufferSur
face(deviceSize, *msaaSampleCount, opacityMode, Canvas2DLayerBridge::EnableAccel
eration)); |
656 if (surface->isValid()) | 658 if (surface->isValid()) { |
| 659 CanvasMetrics::countCanvasContextUsage(CanvasMetrics::GPUAccelerated
2DCanvasImageBufferCreated); |
657 return surface.release(); | 660 return surface.release(); |
| 661 } |
| 662 CanvasMetrics::countCanvasContextUsage(CanvasMetrics::GPUAccelerated2DCa
nvasImageBufferCreationFailed); |
658 } | 663 } |
659 | 664 |
660 OwnPtr<RecordingImageBufferFallbackSurfaceFactory> surfaceFactory = adoptPtr
(new UnacceleratedSurfaceFactory()); | 665 OwnPtr<RecordingImageBufferFallbackSurfaceFactory> surfaceFactory = adoptPtr
(new UnacceleratedSurfaceFactory()); |
661 | 666 |
662 if (shouldUseDisplayList(deviceSize)) { | 667 if (shouldUseDisplayList(deviceSize)) { |
663 OwnPtr<ImageBufferSurface> surface = adoptPtr(new RecordingImageBufferSu
rface(deviceSize, surfaceFactory.release(), opacityMode)); | 668 OwnPtr<ImageBufferSurface> surface = adoptPtr(new RecordingImageBufferSu
rface(deviceSize, surfaceFactory.release(), opacityMode)); |
664 if (surface->isValid()) | 669 if (surface->isValid()) { |
| 670 CanvasMetrics::countCanvasContextUsage(CanvasMetrics::DisplayList2DC
anvasImageBufferCreated); |
665 return surface.release(); | 671 return surface.release(); |
| 672 } |
666 surfaceFactory = adoptPtr(new UnacceleratedSurfaceFactory()); // recreat
e because previous one was released | 673 surfaceFactory = adoptPtr(new UnacceleratedSurfaceFactory()); // recreat
e because previous one was released |
667 } | 674 } |
668 | 675 auto surface = surfaceFactory->createSurface(deviceSize, opacityMode); |
669 return surfaceFactory->createSurface(deviceSize, opacityMode); | 676 if (!surface->isValid()) { |
| 677 CanvasMetrics::countCanvasContextUsage(CanvasMetrics::Unaccelerated2DCan
vasImageBufferCreationFailed); |
| 678 } else { |
| 679 CanvasMetrics::countCanvasContextUsage(CanvasMetrics::Unaccelerated2DCan
vasImageBufferCreated); |
| 680 } |
| 681 return surface; |
670 } | 682 } |
671 | 683 |
672 void HTMLCanvasElement::createImageBuffer() | 684 void HTMLCanvasElement::createImageBuffer() |
673 { | 685 { |
674 createImageBufferInternal(nullptr); | 686 createImageBufferInternal(nullptr); |
675 if (m_didFailToCreateImageBuffer && m_context->is2d() && !size().isEmpty()) | 687 if (m_didFailToCreateImageBuffer && m_context->is2d() && !size().isEmpty()) |
676 m_context->loseContext(CanvasRenderingContext::SyntheticLostContext); | 688 m_context->loseContext(CanvasRenderingContext::SyntheticLostContext); |
677 } | 689 } |
678 | 690 |
679 void HTMLCanvasElement::createImageBufferInternal(PassOwnPtr<ImageBufferSurface>
externalSurface) | 691 void HTMLCanvasElement::createImageBufferInternal(PassOwnPtr<ImageBufferSurface>
externalSurface) |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
920 { | 932 { |
921 return FloatSize(width(), height()); | 933 return FloatSize(width(), height()); |
922 } | 934 } |
923 | 935 |
924 bool HTMLCanvasElement::isOpaque() const | 936 bool HTMLCanvasElement::isOpaque() const |
925 { | 937 { |
926 return m_context && !m_context->hasAlpha(); | 938 return m_context && !m_context->hasAlpha(); |
927 } | 939 } |
928 | 940 |
929 } // blink | 941 } // blink |
OLD | NEW |