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

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

Issue 659873002: Making display list canvases fall back to gpu-accelerated when appropriate (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: response to comments Created 6 years, 2 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 | 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 455 matching lines...) Expand 10 before | Expand all | Expand 10 after
466 // Do not use acceleration for small canvas. 466 // Do not use acceleration for small canvas.
467 if (size.width() * size.height() < settings->minimumAccelerated2dCanvasSize( )) 467 if (size.width() * size.height() < settings->minimumAccelerated2dCanvasSize( ))
468 return false; 468 return false;
469 469
470 if (!blink::Platform::current()->canAccelerate2dCanvas()) 470 if (!blink::Platform::current()->canAccelerate2dCanvas())
471 return false; 471 return false;
472 472
473 return true; 473 return true;
474 } 474 }
475 475
476 class UnacceleratedSurfaceFactory : public RecordingImageBufferFallbackSurfaceFa ctory {
477 public:
478 virtual PassOwnPtr<ImageBufferSurface> createSurface(const IntSize& size, Op acityMode opacityMode)
479 {
480 return adoptPtr(new UnacceleratedImageBufferSurface(size, opacityMode));
481 }
482
483 virtual ~UnacceleratedSurfaceFactory() { }
484 };
485
486 class Accelerated2dSurfaceFactory : public RecordingImageBufferFallbackSurfaceFa ctory {
487 public:
488 Accelerated2dSurfaceFactory(int msaaSampleCount) : m_msaaSampleCount(msaaSam pleCount) { }
489
490 virtual PassOwnPtr<ImageBufferSurface> createSurface(const IntSize& size, Op acityMode opacityMode)
491 {
492 OwnPtr<ImageBufferSurface> surface = adoptPtr(new Canvas2DImageBufferSur face(size, opacityMode, m_msaaSampleCount));
493 if (surface->isValid())
494 return surface.release();
495 return adoptPtr(new UnacceleratedImageBufferSurface(size, opacityMode));
496 }
497
498 virtual ~Accelerated2dSurfaceFactory() { }
499 private:
500 int m_msaaSampleCount;
501 };
502
503 PassOwnPtr<RecordingImageBufferFallbackSurfaceFactory> HTMLCanvasElement::create SurfaceFactory(const IntSize& deviceSize, int* msaaSampleCount) const
504 {
505 *msaaSampleCount = 0;
506 OwnPtr<RecordingImageBufferFallbackSurfaceFactory> surfaceFactory;
507 if (shouldAccelerate(deviceSize)) {
508 if (document().settings())
509 *msaaSampleCount = document().settings()->accelerated2dCanvasMSAASam pleCount();
510 surfaceFactory = adoptPtr(new Accelerated2dSurfaceFactory(*msaaSampleCou nt));
511 } else {
512 surfaceFactory = adoptPtr(new UnacceleratedSurfaceFactory());
513 }
514 return surfaceFactory.release();
515 }
516
476 PassOwnPtr<ImageBufferSurface> HTMLCanvasElement::createImageBufferSurface(const IntSize& deviceSize, int* msaaSampleCount) 517 PassOwnPtr<ImageBufferSurface> HTMLCanvasElement::createImageBufferSurface(const IntSize& deviceSize, int* msaaSampleCount)
477 { 518 {
478 OpacityMode opacityMode = !m_context || m_context->hasAlpha() ? NonOpaque : Opaque; 519 OpacityMode opacityMode = !m_context || m_context->hasAlpha() ? NonOpaque : Opaque;
479 520
480 *msaaSampleCount = 0; 521 *msaaSampleCount = 0;
481 if (is3D()) { 522 if (is3D()) {
482 // If 3d, but the use of the canvas will be for non-accelerated content 523 // If 3d, but the use of the canvas will be for non-accelerated content
483 // (such as -webkit-canvas, then then make a non-accelerated 524 // (such as -webkit-canvas, then then make a non-accelerated
484 // ImageBuffer. This means copying the internal Image will require a 525 // ImageBuffer. This means copying the internal Image will require a
485 // pixel readback, but that is unavoidable in this case. 526 // pixel readback, but that is unavoidable in this case.
486 // FIXME: Actually, avoid setting m_accelerationDisabled at all when 527 // FIXME: Actually, avoid setting m_accelerationDisabled at all when
487 // doing GPU-based rasterization. 528 // doing GPU-based rasterization.
488 if (m_accelerationDisabled) 529 if (m_accelerationDisabled)
489 return adoptPtr(new UnacceleratedImageBufferSurface(size(), opacityM ode)); 530 return adoptPtr(new UnacceleratedImageBufferSurface(deviceSize, opac ityMode));
490 return adoptPtr(new WebGLImageBufferSurface(size(), opacityMode)); 531 return adoptPtr(new WebGLImageBufferSurface(deviceSize, opacityMode));
491 } 532 }
492 533
534 OwnPtr<RecordingImageBufferFallbackSurfaceFactory> surfaceFactory = createSu rfaceFactory(deviceSize, msaaSampleCount);
535
493 if (RuntimeEnabledFeatures::displayList2dCanvasEnabled()) { 536 if (RuntimeEnabledFeatures::displayList2dCanvasEnabled()) {
494 OwnPtr<ImageBufferSurface> surface = adoptPtr(new RecordingImageBufferSu rface(size(), opacityMode)); 537 OwnPtr<ImageBufferSurface> surface = adoptPtr(new RecordingImageBufferSu rface(deviceSize, surfaceFactory.release(), opacityMode));
495 if (surface->isValid()) 538 if (surface->isValid())
496 return surface.release(); 539 return surface.release();
540 surfaceFactory = createSurfaceFactory(deviceSize, msaaSampleCount); // r ecreate because old previous one was released
497 } 541 }
498 542
499 if (shouldAccelerate(deviceSize)) { 543 return surfaceFactory->createSurface(deviceSize, opacityMode);
500 if (document().settings())
501 *msaaSampleCount = document().settings()->accelerated2dCanvasMSAASam pleCount();
502 OwnPtr<ImageBufferSurface> surface = adoptPtr(new Canvas2DImageBufferSur face(size(), opacityMode, *msaaSampleCount));
503 if (surface->isValid())
504 return surface.release();
505 }
506
507 return adoptPtr(new UnacceleratedImageBufferSurface(size(), opacityMode));
508 } 544 }
509 545
510 void HTMLCanvasElement::createImageBuffer() 546 void HTMLCanvasElement::createImageBuffer()
511 { 547 {
512 createImageBufferInternal(); 548 createImageBufferInternal();
513 if (m_didFailToCreateImageBuffer && m_context && m_context->is2d()) 549 if (m_didFailToCreateImageBuffer && m_context && m_context->is2d())
514 toCanvasRenderingContext2D(m_context.get())->loseContext(); 550 toCanvasRenderingContext2D(m_context.get())->loseContext();
515 } 551 }
516 552
517 void HTMLCanvasElement::createImageBufferInternal() 553 void HTMLCanvasElement::createImageBufferInternal()
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
757 { 793 {
758 return !originClean(); 794 return !originClean();
759 } 795 }
760 796
761 FloatSize HTMLCanvasElement::sourceSize() const 797 FloatSize HTMLCanvasElement::sourceSize() const
762 { 798 {
763 return FloatSize(width(), height()); 799 return FloatSize(width(), height());
764 } 800 }
765 801
766 } 802 }
OLDNEW
« no previous file with comments | « Source/core/html/HTMLCanvasElement.h ('k') | Source/platform/graphics/RecordingImageBufferSurface.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698