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

Side by Side Diff: sky/engine/core/html/HTMLCanvasElement.cpp

Issue 922893002: Merge the Sky Engine changes from the SkyDart branch (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 10 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
« no previous file with comments | « sky/engine/core/html/HTMLCanvasElement.h ('k') | sky/engine/core/html/HTMLCanvasElement.idl » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 15 matching lines...) Expand all
26 */ 26 */
27 27
28 #include "sky/engine/config.h" 28 #include "sky/engine/config.h"
29 #include "sky/engine/core/html/HTMLCanvasElement.h" 29 #include "sky/engine/core/html/HTMLCanvasElement.h"
30 30
31 #include <math.h> 31 #include <math.h>
32 32
33 #include "base/bind.h" 33 #include "base/bind.h"
34 #include "gen/sky/core/HTMLNames.h" 34 #include "gen/sky/core/HTMLNames.h"
35 #include "gen/sky/platform/RuntimeEnabledFeatures.h" 35 #include "gen/sky/platform/RuntimeEnabledFeatures.h"
36 #include "sky/engine/bindings/core/v8/ExceptionMessages.h" 36 #include "sky/engine/bindings2/exception_messages.h"
37 #include "sky/engine/bindings/core/v8/ExceptionState.h" 37 #include "sky/engine/bindings2/exception_state.h"
38 #include "sky/engine/bindings/core/v8/ScriptController.h"
39 #include "sky/engine/core/dom/Document.h" 38 #include "sky/engine/core/dom/Document.h"
40 #include "sky/engine/core/dom/ExceptionCode.h" 39 #include "sky/engine/core/dom/ExceptionCode.h"
41 #include "sky/engine/core/dom/Microtask.h" 40 #include "sky/engine/core/dom/Microtask.h"
42 #include "sky/engine/core/frame/LocalFrame.h" 41 #include "sky/engine/core/frame/LocalFrame.h"
43 #include "sky/engine/core/frame/Settings.h" 42 #include "sky/engine/core/frame/Settings.h"
44 #include "sky/engine/core/html/ImageData.h" 43 #include "sky/engine/core/html/ImageData.h"
45 #include "sky/engine/core/html/canvas/Canvas2DContextAttributes.h" 44 #include "sky/engine/core/html/canvas/Canvas2DContextAttributes.h"
46 #include "sky/engine/core/html/canvas/CanvasRenderingContext2D.h" 45 #include "sky/engine/core/html/canvas/CanvasRenderingContext2D.h"
47 #include "sky/engine/core/html/canvas/WebGLContextAttributes.h" 46 #include "sky/engine/core/html/canvas/WebGLContextAttributes.h"
48 #include "sky/engine/core/html/canvas/WebGLContextEvent.h" 47 #include "sky/engine/core/html/canvas/WebGLContextEvent.h"
49 #include "sky/engine/core/html/canvas/WebGLRenderingContext.h" 48 #include "sky/engine/core/html/canvas/WebGLRenderingContext.h"
50 #include "sky/engine/core/rendering/RenderHTMLCanvas.h" 49 #include "sky/engine/core/rendering/RenderHTMLCanvas.h"
51 #include "sky/engine/core/rendering/RenderLayer.h" 50 #include "sky/engine/core/rendering/RenderLayer.h"
52 #include "sky/engine/platform/MIMETypeRegistry.h" 51 #include "sky/engine/platform/MIMETypeRegistry.h"
53 #include "sky/engine/platform/graphics/Canvas2DImageBufferSurface.h" 52 #include "sky/engine/platform/graphics/Canvas2DImageBufferSurface.h"
54 #include "sky/engine/platform/graphics/GraphicsContextStateSaver.h" 53 #include "sky/engine/platform/graphics/GraphicsContextStateSaver.h"
55 #include "sky/engine/platform/graphics/ImageBuffer.h" 54 #include "sky/engine/platform/graphics/ImageBuffer.h"
56 #include "sky/engine/platform/graphics/UnacceleratedImageBufferSurface.h" 55 #include "sky/engine/platform/graphics/UnacceleratedImageBufferSurface.h"
57 #include "sky/engine/platform/graphics/gpu/WebGLImageBufferSurface.h" 56 #include "sky/engine/platform/graphics/gpu/WebGLImageBufferSurface.h"
58 #include "sky/engine/platform/transforms/AffineTransform.h" 57 #include "sky/engine/platform/transforms/AffineTransform.h"
59 #include "sky/engine/public/platform/Platform.h" 58 #include "sky/engine/public/platform/Platform.h"
60 #include "v8/include/v8.h"
61 59
62 namespace blink { 60 namespace blink {
63 61
64 // These values come from the WhatWG spec. 62 // These values come from the WhatWG spec.
65 static const int DefaultWidth = 300; 63 static const int DefaultWidth = 300;
66 static const int DefaultHeight = 150; 64 static const int DefaultHeight = 150;
67 65
68 // Firefox limits width/height to 32767 pixels, but slows down dramatically befo re it 66 // Firefox limits width/height to 32767 pixels, but slows down dramatically befo re it
69 // reaches that limit. We limit by area instead, giving us larger maximum dimens ions, 67 // reaches that limit. We limit by area instead, giving us larger maximum dimens ions,
70 // in exchange for a smaller maximum canvas size. 68 // in exchange for a smaller maximum canvas size.
(...skipping 13 matching lines...) Expand all
84 , m_didFailToCreateImageBuffer(false) 82 , m_didFailToCreateImageBuffer(false)
85 , m_didClearImageBuffer(false) 83 , m_didClearImageBuffer(false)
86 { 84 {
87 } 85 }
88 86
89 DEFINE_NODE_FACTORY(HTMLCanvasElement) 87 DEFINE_NODE_FACTORY(HTMLCanvasElement)
90 88
91 HTMLCanvasElement::~HTMLCanvasElement() 89 HTMLCanvasElement::~HTMLCanvasElement()
92 { 90 {
93 resetDirtyRect(); 91 resetDirtyRect();
94 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(-m_external lyAllocatedMemory);
95 #if !ENABLE(OILPAN) 92 #if !ENABLE(OILPAN)
96 HashSet<RawPtr<CanvasObserver> >::iterator end = m_observers.end(); 93 HashSet<RawPtr<CanvasObserver> >::iterator end = m_observers.end();
97 for (HashSet<RawPtr<CanvasObserver> >::iterator it = m_observers.begin(); it != end; ++it) 94 for (HashSet<RawPtr<CanvasObserver> >::iterator it = m_observers.begin(); it != end; ++it)
98 (*it)->canvasDestroyed(this); 95 (*it)->canvasDestroyed(this);
99 // Ensure these go away before the ImageBuffer. 96 // Ensure these go away before the ImageBuffer.
100 m_contextStateSaver.clear(); 97 m_contextStateSaver.clear();
101 m_context.clear(); 98 m_context.clear();
102 #endif 99 #endif
103 } 100 }
104 101
(...skipping 22 matching lines...) Expand all
127 void HTMLCanvasElement::setHeight(int value) 124 void HTMLCanvasElement::setHeight(int value)
128 { 125 {
129 setIntegralAttribute(HTMLNames::heightAttr, value); 126 setIntegralAttribute(HTMLNames::heightAttr, value);
130 } 127 }
131 128
132 void HTMLCanvasElement::setWidth(int value) 129 void HTMLCanvasElement::setWidth(int value)
133 { 130 {
134 setIntegralAttribute(HTMLNames::widthAttr, value); 131 setIntegralAttribute(HTMLNames::widthAttr, value);
135 } 132 }
136 133
137 CanvasRenderingContext* HTMLCanvasElement::getContext(const String& type, Canvas ContextAttributes* attrs) 134 CanvasRenderingContext2D* HTMLCanvasElement::getContext(const String& type, Canv asContextAttributes* attrs)
138 { 135 {
139 // A Canvas can either be "2D" or "webgl" but never both. If you request a 2 D canvas and the existing 136 // A Canvas can either be "2D" or "webgl" but never both. If you request a 2 D canvas and the existing
140 // context is already 2D, just return that. If the existing context is WebGL , then destroy it 137 // context is already 2D, just return that. If the existing context is WebGL , then destroy it
141 // before creating a new 2D context. Vice versa when requesting a WebGL canv as. Requesting a 138 // before creating a new 2D context. Vice versa when requesting a WebGL canv as. Requesting a
142 // context with any other type string will destroy any existing context. 139 // context with any other type string will destroy any existing context.
143 enum ContextType { 140 enum ContextType {
144 // Do not change assigned numbers of existing items: add new features to the end of the list. 141 // Do not change assigned numbers of existing items: add new features to the end of the list.
145 Context2d = 0, 142 Context2d = 0,
146 ContextExperimentalWebgl = 2, 143 ContextExperimentalWebgl = 2,
147 ContextWebgl = 3, 144 ContextWebgl = 3,
148 ContextTypeCount, 145 ContextTypeCount,
149 }; 146 };
150 147
151 // FIXME - The code depends on the context not going away once created, to p revent JS from 148 // FIXME - The code depends on the context not going away once created, to p revent JS from
152 // seeing a dangling pointer. So for now we will disallow the context from b eing changed 149 // seeing a dangling pointer. So for now we will disallow the context from b eing changed
153 // once it is created. 150 // once it is created.
154 if (type == "2d") { 151 if (type == "2d") {
155 if (m_context && !m_context->is2d()) 152 if (m_context && !m_context->is2d())
156 return 0; 153 return 0;
157 if (!m_context) { 154 if (!m_context) {
158 blink::Platform::current()->histogramEnumeration("Canvas.ContextType ", Context2d, ContextTypeCount); 155 blink::Platform::current()->histogramEnumeration("Canvas.ContextType ", Context2d, ContextTypeCount);
159 m_context = CanvasRenderingContext2D::create(this, static_cast<Canva s2DContextAttributes*>(attrs)); 156 m_context = CanvasRenderingContext2D::create(this, static_cast<Canva s2DContextAttributes*>(attrs));
160 } 157 }
161 return m_context.get(); 158 return static_cast<CanvasRenderingContext2D*>(m_context.get());
162 } 159 }
163 160
164 // Accept the the provisional "experimental-webgl" or official "webgl" conte xt ID. 161 // Accept the the provisional "experimental-webgl" or official "webgl" conte xt ID.
165 if (type == "webgl" || type == "experimental-webgl") { 162 // if (type == "webgl" || type == "experimental-webgl") {
166 ContextType contextType = (type == "webgl") ? ContextWebgl : ContextExpe rimentalWebgl; 163 // ContextType contextType = (type == "webgl") ? ContextWebgl : ContextE xperimentalWebgl;
167 if (!m_context) { 164 // if (!m_context) {
168 blink::Platform::current()->histogramEnumeration("Canvas.ContextType ", contextType, ContextTypeCount); 165 // blink::Platform::current()->histogramEnumeration("Canvas.ContextT ype", contextType, ContextTypeCount);
169 m_context = WebGLRenderingContext::create(this, static_cast<WebGLCon textAttributes*>(attrs)); 166 // m_context = WebGLRenderingContext::create(this, static_cast<WebGL ContextAttributes*>(attrs));
170 updateExternallyAllocatedMemory(); 167 // updateExternallyAllocatedMemory();
171 } else if (!m_context->is3d()) { 168 // } else if (!m_context->is3d()) {
172 dispatchEvent(WebGLContextEvent::create(EventTypeNames::webglcontext creationerror, false, true, "Canvas has an existing, non-WebGL context")); 169 // dispatchEvent(WebGLContextEvent::create(EventTypeNames::webglcont extcreationerror, false, true, "Canvas has an existing, non-WebGL context"));
173 return 0; 170 // return 0;
174 } 171 // }
175 return m_context.get(); 172 // return m_context.get();
176 } 173 // }
177 174
178 return 0; 175 return nullptr;
179 } 176 }
180 177
181 void HTMLCanvasElement::didDraw(const FloatRect& rect) 178 void HTMLCanvasElement::didDraw(const FloatRect& rect)
182 { 179 {
183 if (rect.isEmpty()) 180 if (rect.isEmpty())
184 return; 181 return;
185 clearCopiedImage(); 182 clearCopiedImage();
186 if (m_dirtyRect.isEmpty()) { 183 if (m_dirtyRect.isEmpty()) {
187 m_finalizeFrameTask.Reset(base::Bind( 184 m_finalizeFrameTask.Reset(base::Bind(
188 &HTMLCanvasElement::finalizeFrameMicrotask, base::Unretained(this))) ; 185 &HTMLCanvasElement::finalizeFrameMicrotask, base::Unretained(this))) ;
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after
527 bufferCount++; 524 bufferCount++;
528 525
529 Checked<intptr_t, RecordOverflow> checkedExternallyAllocatedMemory = 4 * buf ferCount; 526 Checked<intptr_t, RecordOverflow> checkedExternallyAllocatedMemory = 4 * buf ferCount;
530 checkedExternallyAllocatedMemory *= width(); 527 checkedExternallyAllocatedMemory *= width();
531 checkedExternallyAllocatedMemory *= height(); 528 checkedExternallyAllocatedMemory *= height();
532 intptr_t externallyAllocatedMemory; 529 intptr_t externallyAllocatedMemory;
533 if (checkedExternallyAllocatedMemory.safeGet(externallyAllocatedMemory) == C heckedState::DidOverflow) 530 if (checkedExternallyAllocatedMemory.safeGet(externallyAllocatedMemory) == C heckedState::DidOverflow)
534 externallyAllocatedMemory = std::numeric_limits<intptr_t>::max(); 531 externallyAllocatedMemory = std::numeric_limits<intptr_t>::max();
535 532
536 // Subtracting two intptr_t that are known to be positive will never underfl ow. 533 // Subtracting two intptr_t that are known to be positive will never underfl ow.
537 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(externallyA llocatedMemory - m_externallyAllocatedMemory);
538 m_externallyAllocatedMemory = externallyAllocatedMemory; 534 m_externallyAllocatedMemory = externallyAllocatedMemory;
539 } 535 }
540 536
541 GraphicsContext* HTMLCanvasElement::drawingContext() const 537 GraphicsContext* HTMLCanvasElement::drawingContext() const
542 { 538 {
543 return buffer() ? m_imageBuffer->context() : 0; 539 return buffer() ? m_imageBuffer->context() : 0;
544 } 540 }
545 541
546 GraphicsContext* HTMLCanvasElement::existingDrawingContext() const 542 GraphicsContext* HTMLCanvasElement::existingDrawingContext() const
547 { 543 {
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
650 } 646 }
651 return m_imageBuffer->copyImage(DontCopyBackingStore, Unscaled); 647 return m_imageBuffer->copyImage(DontCopyBackingStore, Unscaled);
652 } 648 }
653 649
654 FloatSize HTMLCanvasElement::sourceSize() const 650 FloatSize HTMLCanvasElement::sourceSize() const
655 { 651 {
656 return FloatSize(width(), height()); 652 return FloatSize(width(), height());
657 } 653 }
658 654
659 } 655 }
OLDNEW
« no previous file with comments | « sky/engine/core/html/HTMLCanvasElement.h ('k') | sky/engine/core/html/HTMLCanvasElement.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698