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

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

Issue 1482363004: Fixing laggy chrome on a multitude of accelerated canvases (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: m_imageBuffer nullibility check to ensure other unrelated unit tests on layerbridge not fail Created 5 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
« no previous file with comments | « no previous file | third_party/WebKit/Source/modules/canvas2d/CanvasRenderingContext2DTest.cpp » ('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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 const int DefaultHeight = 150; 73 const int DefaultHeight = 150;
74 74
75 // Firefox limits width/height to 32767 pixels, but slows down dramatically befo re it 75 // Firefox limits width/height to 32767 pixels, but slows down dramatically befo re it
76 // reaches that limit. We limit by area instead, giving us larger maximum dimens ions, 76 // reaches that limit. We limit by area instead, giving us larger maximum dimens ions,
77 // in exchange for a smaller maximum canvas size. 77 // in exchange for a smaller maximum canvas size.
78 const int MaxCanvasArea = 32768 * 8192; // Maximum canvas area in CSS pixels 78 const int MaxCanvasArea = 32768 * 8192; // Maximum canvas area in CSS pixels
79 79
80 // In Skia, we will also limit width/height to 32767. 80 // In Skia, we will also limit width/height to 32767.
81 const int MaxSkiaDim = 32767; // Maximum width/height in CSS pixels. 81 const int MaxSkiaDim = 32767; // Maximum width/height in CSS pixels.
82 82
83 // We estimate the max limit of GPU allocated memory for canvases before Chrome
84 // becomes laggy by setting the total allocated memory for accelerated canvases
85 // to be equivalent to memory used by 80 accelerated canvases, each has a size
86 // of 1000*500 and 2d context.
87 // Each such canvas occupies 4000000 = 1000 * 500 * 2 * 4 bytes, where 2 is the
88 // gpuBufferCount in ImageBuffer::updateGPUMemoryUsage() and 4 means four bytes
89 // per pixel per buffer.
90 #if !OS(ANDROID)
91 const int MaxGlobalGPUMemoryUsage = 4000000 * 80;
92 #else
93 // We estimate that the max limit for android phones is a quarter of that for
94 // desktops based on local experimental results on Android One.,
95 const int MaxGlobalGPUMemoryUsage = 4000000 * 20;
96 #endif
97
83 // A default value of quality argument for toDataURL and toBlob 98 // A default value of quality argument for toDataURL and toBlob
84 // It is in an invalid range (outside 0.0 - 1.0) so that it will not be misinter preted as a user-input value 99 // It is in an invalid range (outside 0.0 - 1.0) so that it will not be
100 // misinterpreted as a user-input value
85 const int UndefinedQualityValue = -1.0; 101 const int UndefinedQualityValue = -1.0;
86 102
87 // Default image mime type for toDataURL and toBlob functions 103 // Default image mime type for toDataURL and toBlob functions
88 const char DefaultMimeType[] = "image/png"; 104 const char DefaultMimeType[] = "image/png";
89 105
90 bool canCreateImageBuffer(const IntSize& size) 106 bool canCreateImageBuffer(const IntSize& size)
91 { 107 {
92 if (size.isEmpty()) 108 if (size.isEmpty())
93 return false; 109 return false;
94 if (size.width() * size.height() > MaxCanvasArea) 110 if (size.width() * size.height() > MaxCanvasArea)
(...skipping 552 matching lines...) Expand 10 before | Expand all | Expand 10 after
647 return false; 663 return false;
648 } 664 }
649 665
650 // Do not use acceleration for small canvas. 666 // Do not use acceleration for small canvas.
651 if (canvasPixelCount < settings->minimumAccelerated2dCanvasSize()) 667 if (canvasPixelCount < settings->minimumAccelerated2dCanvasSize())
652 return false; 668 return false;
653 669
654 if (!Platform::current()->canAccelerate2dCanvas()) 670 if (!Platform::current()->canAccelerate2dCanvas())
655 return false; 671 return false;
656 672
673 // When GPU allocated memory runs low (due to having created too many
674 // accelerated canvases), the compositor starves and browser becomes laggy.
675 // Thus, we should stop allocating more GPU memory to new canvases created
676 // when the current memory usage exceeds the threshold.
677 if (ImageBuffer::getGlobalGPUMemoryUsage() >= MaxGlobalGPUMemoryUsage)
678 return false;
679
657 return true; 680 return true;
658 } 681 }
659 682
660 class UnacceleratedSurfaceFactory : public RecordingImageBufferFallbackSurfaceFa ctory { 683 class UnacceleratedSurfaceFactory : public RecordingImageBufferFallbackSurfaceFa ctory {
661 public: 684 public:
662 virtual PassOwnPtr<ImageBufferSurface> createSurface(const IntSize& size, Op acityMode opacityMode) 685 virtual PassOwnPtr<ImageBufferSurface> createSurface(const IntSize& size, Op acityMode opacityMode)
663 { 686 {
664 return adoptPtr(new UnacceleratedImageBufferSurface(size, opacityMode)); 687 return adoptPtr(new UnacceleratedImageBufferSurface(size, opacityMode));
665 } 688 }
666 689
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after
991 } 1014 }
992 return ImageBitmapSource::fulfillImageBitmap(scriptState, isPaintable() ? Im ageBitmap::create(this, IntRect(sx, sy, sw, sh)) : nullptr); 1015 return ImageBitmapSource::fulfillImageBitmap(scriptState, isPaintable() ? Im ageBitmap::create(this, IntRect(sx, sy, sw, sh)) : nullptr);
993 } 1016 }
994 1017
995 bool HTMLCanvasElement::isOpaque() const 1018 bool HTMLCanvasElement::isOpaque() const
996 { 1019 {
997 return m_context && !m_context->hasAlpha(); 1020 return m_context && !m_context->hasAlpha();
998 } 1021 }
999 1022
1000 } // blink 1023 } // blink
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/modules/canvas2d/CanvasRenderingContext2DTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698