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

Side by Side Diff: Source/core/html/HTMLCanvasElement.cpp

Issue 104023007: Refactoring ImageBuffer to decouple it from Canvas2DLayerBridge (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: build fixes for win+mac Created 7 years 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 | Annotate | Revision Log
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 25 matching lines...) Expand all
36 #include "bindings/v8/ScriptController.h" 36 #include "bindings/v8/ScriptController.h"
37 #include "core/dom/Document.h" 37 #include "core/dom/Document.h"
38 #include "core/dom/ExceptionCode.h" 38 #include "core/dom/ExceptionCode.h"
39 #include "core/html/ImageData.h" 39 #include "core/html/ImageData.h"
40 #include "core/html/canvas/Canvas2DContextAttributes.h" 40 #include "core/html/canvas/Canvas2DContextAttributes.h"
41 #include "core/html/canvas/CanvasRenderingContext2D.h" 41 #include "core/html/canvas/CanvasRenderingContext2D.h"
42 #include "core/html/canvas/WebGLContextAttributes.h" 42 #include "core/html/canvas/WebGLContextAttributes.h"
43 #include "core/html/canvas/WebGLRenderingContext.h" 43 #include "core/html/canvas/WebGLRenderingContext.h"
44 #include "core/frame/Frame.h" 44 #include "core/frame/Frame.h"
45 #include "core/page/Settings.h" 45 #include "core/page/Settings.h"
46 #include "core/platform/graphics/Canvas2DImageBufferSurface.h"
46 #include "core/platform/graphics/GraphicsContextStateSaver.h" 47 #include "core/platform/graphics/GraphicsContextStateSaver.h"
47 #include "core/platform/graphics/ImageBuffer.h" 48 #include "core/platform/graphics/ImageBuffer.h"
49 #include "core/platform/graphics/gpu/NonDrawableAcceleratedImageBufferSurface.h"
48 #include "core/rendering/RenderHTMLCanvas.h" 50 #include "core/rendering/RenderHTMLCanvas.h"
49 #include "platform/MIMETypeRegistry.h" 51 #include "platform/MIMETypeRegistry.h"
52 #include "platform/graphics/UnacceleratedImageBufferSurface.h"
50 #include "public/platform/Platform.h" 53 #include "public/platform/Platform.h"
51 54
52 namespace WebCore { 55 namespace WebCore {
53 56
54 using namespace HTMLNames; 57 using namespace HTMLNames;
55 58
56 // These values come from the WhatWG spec. 59 // These values come from the WhatWG spec.
57 static const int DefaultWidth = 300; 60 static const int DefaultWidth = 300;
58 static const int DefaultHeight = 150; 61 static const int DefaultHeight = 150;
59 62
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after
425 // Do not use acceleration for small canvas. 428 // Do not use acceleration for small canvas.
426 if (size.width() * size.height() < settings->minimumAccelerated2dCanvasSize( )) 429 if (size.width() * size.height() < settings->minimumAccelerated2dCanvasSize( ))
427 return false; 430 return false;
428 431
429 if (!blink::Platform::current()->canAccelerate2dCanvas()) 432 if (!blink::Platform::current()->canAccelerate2dCanvas())
430 return false; 433 return false;
431 434
432 return true; 435 return true;
433 } 436 }
434 437
438 PassOwnPtr<ImageBufferSurface> HTMLCanvasElement::createImageBufferSurface(const IntSize& deviceSize, int* msaaSampleCount)
439 {
440 OwnPtr<ImageBufferSurface> surface;
441 OpacityMode opacityMode = !m_context || m_context->hasAlpha() ? NonOpaque : Opaque;
442 *msaaSampleCount = 0;
443 if (is3D()) {
444 // Note: No MSAA for 3D canvases because the image buffer is only used f or capturing contents.
445 // The actual rendering happens in DrawingBuffer.
446 surface = adoptPtr(new NonDrawableAcceleratedImageBufferSurface(size(), opacityMode, m_deviceScaleFactor));
447 } else {
448 if (shouldAccelerate(deviceSize)) {
449 if (document().settings())
450 *msaaSampleCount = document().settings()->accelerated2dCanvasMSA ASampleCount();
451 surface = adoptPtr(new Canvas2DImageBufferSurface(size(), opacityMod e, m_deviceScaleFactor, *msaaSampleCount));
452 }
453
454 if (!surface || !surface->isValid()) {
455 surface = adoptPtr(new UnacceleratedImageBufferSurface(size(), opaci tyMode, m_deviceScaleFactor));
Stephen White 2013/12/04 21:18:40 I'd prefer a Create() method on the surface subcla
456 }
457 }
458
459 return surface.release();
460 }
461
435 void HTMLCanvasElement::createImageBuffer() 462 void HTMLCanvasElement::createImageBuffer()
436 { 463 {
437 ASSERT(!m_imageBuffer); 464 ASSERT(!m_imageBuffer);
438 465
439 m_didFailToCreateImageBuffer = true; 466 m_didFailToCreateImageBuffer = true;
440 m_didClearImageBuffer = true; 467 m_didClearImageBuffer = true;
441 468
442 IntSize deviceSize = convertLogicalToDevice(size()); 469 IntSize deviceSize = convertLogicalToDevice(size());
443 if (deviceSize.width() * deviceSize.height() > MaxCanvasArea) 470 if (deviceSize.width() * deviceSize.height() > MaxCanvasArea)
444 return; 471 return;
445 472
446 if (deviceSize.width() > MaxSkiaDim || deviceSize.height() > MaxSkiaDim) 473 if (deviceSize.width() > MaxSkiaDim || deviceSize.height() > MaxSkiaDim)
447 return; 474 return;
448 475
449 if (!deviceSize.width() || !deviceSize.height()) 476 if (!deviceSize.width() || !deviceSize.height())
450 return; 477 return;
451 478
452 RenderingMode renderingMode = is3D() ? TextureBacked : (shouldAccelerate(dev iceSize) ? Accelerated : UnacceleratedNonPlatformBuffer); 479 int msaaSampleCount;
453 int msaaSampleCount = 0; 480 OwnPtr<ImageBufferSurface> surface = createImageBufferSurface(deviceSize, &m saaSampleCount);
454 if (document().settings()) 481 if (!surface || !surface->isValid())
455 msaaSampleCount = document().settings()->accelerated2dCanvasMSAASampleCo unt();
456 OpacityMode opacityMode = !m_context || m_context->hasAlpha() ? NonOpaque : Opaque;
457 m_imageBuffer = ImageBuffer::create(size(), m_deviceScaleFactor, renderingMo de, opacityMode, msaaSampleCount);
458 if (!m_imageBuffer)
459 return; 482 return;
483
460 m_didFailToCreateImageBuffer = false; 484 m_didFailToCreateImageBuffer = false;
485
486 m_imageBuffer = adoptPtr(new ImageBuffer(surface.release()));
487
461 setExternallyAllocatedMemory(4 * width() * height()); 488 setExternallyAllocatedMemory(4 * width() * height());
462 m_imageBuffer->context()->setShouldClampToSourceRect(false); 489 m_imageBuffer->context()->setShouldClampToSourceRect(false);
463 m_imageBuffer->context()->setImageInterpolationQuality(DefaultInterpolationQ uality); 490 m_imageBuffer->context()->setImageInterpolationQuality(DefaultInterpolationQ uality);
464 // Enabling MSAA overrides a request to disable antialiasing. This is true r egardless of whether the 491 // Enabling MSAA overrides a request to disable antialiasing. This is true r egardless of whether the
465 // rendering mode is accelerated or not. For consistency, we don't want to a pply AA in accelerated 492 // rendering mode is accelerated or not. For consistency, we don't want to a pply AA in accelerated
466 // canvases but not in unaccelerated canvases. 493 // canvases but not in unaccelerated canvases.
467 if (!msaaSampleCount && document().settings() && !document().settings()->ant ialiased2dCanvasEnabled()) 494 if (!msaaSampleCount && document().settings() && !document().settings()->ant ialiased2dCanvasEnabled())
468 m_imageBuffer->context()->setShouldAntialias(false); 495 m_imageBuffer->context()->setShouldAntialias(false);
469 // GraphicsContext's defaults don't always agree with the 2d canvas spec. 496 // GraphicsContext's defaults don't always agree with the 2d canvas spec.
470 // See CanvasRenderingContext2D::State::State() for more information. 497 // See CanvasRenderingContext2D::State::State() for more information.
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
541 ASSERT(hasImageBuffer() && !m_didFailToCreateImageBuffer); 568 ASSERT(hasImageBuffer() && !m_didFailToCreateImageBuffer);
542 IntSize unscaledSize = size(); 569 IntSize unscaledSize = size();
543 IntSize size = convertLogicalToDevice(unscaledSize); 570 IntSize size = convertLogicalToDevice(unscaledSize);
544 AffineTransform transform; 571 AffineTransform transform;
545 if (size.width() && size.height()) 572 if (size.width() && size.height())
546 transform.scaleNonUniform(size.width() / unscaledSize.width(), size.heig ht() / unscaledSize.height()); 573 transform.scaleNonUniform(size.width() / unscaledSize.width(), size.heig ht() / unscaledSize.height());
547 return m_imageBuffer->baseTransform() * transform; 574 return m_imageBuffer->baseTransform() * transform;
548 } 575 }
549 576
550 } 577 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698