| 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 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 | 150 |
| 151 // FIXME - The code depends on the context not going away once created, to p
revent JS from | 151 // 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 | 152 // seeing a dangling pointer. So for now we will disallow the context from b
eing changed |
| 153 // once it is created. | 153 // once it is created. |
| 154 if (type == "2d") { | 154 if (type == "2d") { |
| 155 if (m_context && !m_context->is2d()) | 155 if (m_context && !m_context->is2d()) |
| 156 return 0; | 156 return 0; |
| 157 if (!m_context) { | 157 if (!m_context) { |
| 158 blink::Platform::current()->histogramEnumeration("Canvas.ContextType
", Context2d, ContextTypeCount); | 158 blink::Platform::current()->histogramEnumeration("Canvas.ContextType
", Context2d, ContextTypeCount); |
| 159 m_context = CanvasRenderingContext2D::create(this, static_cast<Canva
s2DContextAttributes*>(attrs)); | 159 m_context = CanvasRenderingContext2D::create(this, static_cast<Canva
s2DContextAttributes*>(attrs)); |
| 160 setNeedsCompositingUpdate(); | |
| 161 } | 160 } |
| 162 return m_context.get(); | 161 return m_context.get(); |
| 163 } | 162 } |
| 164 | 163 |
| 165 // Accept the the provisional "experimental-webgl" or official "webgl" conte
xt ID. | 164 // Accept the the provisional "experimental-webgl" or official "webgl" conte
xt ID. |
| 166 if (type == "webgl" || type == "experimental-webgl") { | 165 if (type == "webgl" || type == "experimental-webgl") { |
| 167 ContextType contextType = (type == "webgl") ? ContextWebgl : ContextExpe
rimentalWebgl; | 166 ContextType contextType = (type == "webgl") ? ContextWebgl : ContextExpe
rimentalWebgl; |
| 168 if (!m_context) { | 167 if (!m_context) { |
| 169 blink::Platform::current()->histogramEnumeration("Canvas.ContextType
", contextType, ContextTypeCount); | 168 blink::Platform::current()->histogramEnumeration("Canvas.ContextType
", contextType, ContextTypeCount); |
| 170 m_context = WebGLRenderingContext::create(this, static_cast<WebGLCon
textAttributes*>(attrs)); | 169 m_context = WebGLRenderingContext::create(this, static_cast<WebGLCon
textAttributes*>(attrs)); |
| 171 setNeedsCompositingUpdate(); | |
| 172 updateExternallyAllocatedMemory(); | 170 updateExternallyAllocatedMemory(); |
| 173 } else if (!m_context->is3d()) { | 171 } else if (!m_context->is3d()) { |
| 174 dispatchEvent(WebGLContextEvent::create(EventTypeNames::webglcontext
creationerror, false, true, "Canvas has an existing, non-WebGL context")); | 172 dispatchEvent(WebGLContextEvent::create(EventTypeNames::webglcontext
creationerror, false, true, "Canvas has an existing, non-WebGL context")); |
| 175 return 0; | 173 return 0; |
| 176 } | 174 } |
| 177 return m_context.get(); | 175 return m_context.get(); |
| 178 } | 176 } |
| 179 | 177 |
| 180 return 0; | 178 return 0; |
| 181 } | 179 } |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 278 return; | 276 return; |
| 279 } | 277 } |
| 280 | 278 |
| 281 setSurfaceSize(newSize); | 279 setSurfaceSize(newSize); |
| 282 | 280 |
| 283 if (m_context && m_context->is3d() && oldSize != size()) | 281 if (m_context && m_context->is3d() && oldSize != size()) |
| 284 toWebGLRenderingContext(m_context.get())->reshape(width(), height()); | 282 toWebGLRenderingContext(m_context.get())->reshape(width(), height()); |
| 285 | 283 |
| 286 if (RenderObject* renderer = this->renderer()) { | 284 if (RenderObject* renderer = this->renderer()) { |
| 287 if (renderer->isCanvas()) { | 285 if (renderer->isCanvas()) { |
| 288 if (oldSize != size()) { | |
| 289 toRenderHTMLCanvas(renderer)->canvasSizeChanged(); | |
| 290 if (renderBox() && renderBox()->hasAcceleratedCompositing()) | |
| 291 renderBox()->contentChanged(CanvasChanged); | |
| 292 } | |
| 293 if (hadImageBuffer) | 286 if (hadImageBuffer) |
| 294 renderer->setShouldDoFullPaintInvalidation(true); | 287 renderer->setShouldDoFullPaintInvalidation(true); |
| 295 } | 288 } |
| 296 } | 289 } |
| 297 | 290 |
| 298 HashSet<RawPtr<CanvasObserver> >::iterator end = m_observers.end(); | 291 HashSet<RawPtr<CanvasObserver> >::iterator end = m_observers.end(); |
| 299 for (HashSet<RawPtr<CanvasObserver> >::iterator it = m_observers.begin(); it
!= end; ++it) | 292 for (HashSet<RawPtr<CanvasObserver> >::iterator it = m_observers.begin(); it
!= end; ++it) |
| 300 (*it)->canvasResized(this); | 293 (*it)->canvasResized(this); |
| 301 } | 294 } |
| 302 | 295 |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 518 if (!msaaSampleCount && document().settings() && !document().settings()->ant
ialiased2dCanvasEnabled()) | 511 if (!msaaSampleCount && document().settings() && !document().settings()->ant
ialiased2dCanvasEnabled()) |
| 519 m_imageBuffer->context()->setShouldAntialias(false); | 512 m_imageBuffer->context()->setShouldAntialias(false); |
| 520 // GraphicsContext's defaults don't always agree with the 2d canvas spec. | 513 // GraphicsContext's defaults don't always agree with the 2d canvas spec. |
| 521 // See CanvasRenderingContext2D::State::State() for more information. | 514 // See CanvasRenderingContext2D::State::State() for more information. |
| 522 m_imageBuffer->context()->setMiterLimit(10); | 515 m_imageBuffer->context()->setMiterLimit(10); |
| 523 m_imageBuffer->context()->setStrokeThickness(1); | 516 m_imageBuffer->context()->setStrokeThickness(1); |
| 524 #if ENABLE(ASSERT) | 517 #if ENABLE(ASSERT) |
| 525 m_imageBuffer->context()->disableDestructionChecks(); // 2D canvas is allowe
d to leave context in an unfinalized state. | 518 m_imageBuffer->context()->disableDestructionChecks(); // 2D canvas is allowe
d to leave context in an unfinalized state. |
| 526 #endif | 519 #endif |
| 527 m_contextStateSaver = adoptPtr(new GraphicsContextStateSaver(*m_imageBuffer-
>context())); | 520 m_contextStateSaver = adoptPtr(new GraphicsContextStateSaver(*m_imageBuffer-
>context())); |
| 528 | |
| 529 if (m_context) | |
| 530 setNeedsCompositingUpdate(); | |
| 531 } | 521 } |
| 532 | 522 |
| 533 void HTMLCanvasElement::notifySurfaceInvalid() | 523 void HTMLCanvasElement::notifySurfaceInvalid() |
| 534 { | 524 { |
| 535 if (m_context && m_context->is2d()) { | 525 if (m_context && m_context->is2d()) { |
| 536 CanvasRenderingContext2D* context2d = toCanvasRenderingContext2D(m_conte
xt.get()); | 526 CanvasRenderingContext2D* context2d = toCanvasRenderingContext2D(m_conte
xt.get()); |
| 537 context2d->loseContext(); | 527 context2d->loseContext(); |
| 538 } | 528 } |
| 539 } | 529 } |
| 540 | 530 |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 674 } | 664 } |
| 675 return m_imageBuffer->copyImage(DontCopyBackingStore, Unscaled); | 665 return m_imageBuffer->copyImage(DontCopyBackingStore, Unscaled); |
| 676 } | 666 } |
| 677 | 667 |
| 678 FloatSize HTMLCanvasElement::sourceSize() const | 668 FloatSize HTMLCanvasElement::sourceSize() const |
| 679 { | 669 { |
| 680 return FloatSize(width(), height()); | 670 return FloatSize(width(), height()); |
| 681 } | 671 } |
| 682 | 672 |
| 683 } | 673 } |
| OLD | NEW |