Chromium Code Reviews| 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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 becomes laggy by setting the | |
|
Justin Novosad
2015/12/08 22:15:27
There is no hard rule for this in Blink, but we ge
| |
| 84 // total allocated memory for accelerated canvases to be equivalent to memory us ed by 80 accelerated | |
| 85 // canvases, each has a size of 1000*500 and 2d context. | |
| 86 // Each such canvas occupies 4000000 = 1000 * 500 * 2 * 4 bytes, where 2 is the gpuBufferCount in | |
| 87 // ImageBuffer::updateGPUMemoryUsage() and 4 means four bytes per pixel per buff er. | |
| 88 #if !OS(ANDROID) | |
| 89 const int MaxTotalGPUMemoryUsage = 4000000 * 80; | |
| 90 #else | |
| 91 // We estimate that the max limit for android phones is half of that for desktop s based on local | |
| 92 // experimental results on Android One; though a very slight lagginess on Androi d One is still expected, | |
| 93 // other Android devices should work fine. | |
| 94 const int MaxTotalGPUMemoryUsage = 4000000 * 40; | |
|
Justin Novosad
2015/12/08 22:15:27
This limit feels excessive
| |
| 95 #endif | |
| 96 | |
| 83 // A default value of quality argument for toDataURL and toBlob | 97 // 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 | 98 // It is in an invalid range (outside 0.0 - 1.0) so that it will not be misinter preted as a user-input value |
| 85 const int UndefinedQualityValue = -1.0; | 99 const int UndefinedQualityValue = -1.0; |
| 86 | 100 |
| 87 // Default image mime type for toDataURL and toBlob functions | 101 // Default image mime type for toDataURL and toBlob functions |
| 88 const char DefaultMimeType[] = "image/png"; | 102 const char DefaultMimeType[] = "image/png"; |
| 89 | 103 |
| 90 bool canCreateImageBuffer(const IntSize& size) | 104 bool canCreateImageBuffer(const IntSize& size) |
| 91 { | 105 { |
| 92 if (size.isEmpty()) | 106 if (size.isEmpty()) |
| (...skipping 514 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 607 return false; | 621 return false; |
| 608 } | 622 } |
| 609 | 623 |
| 610 // Do not use acceleration for small canvas. | 624 // Do not use acceleration for small canvas. |
| 611 if (canvasPixelCount < settings->minimumAccelerated2dCanvasSize()) | 625 if (canvasPixelCount < settings->minimumAccelerated2dCanvasSize()) |
| 612 return false; | 626 return false; |
| 613 | 627 |
| 614 if (!Platform::current()->canAccelerate2dCanvas()) | 628 if (!Platform::current()->canAccelerate2dCanvas()) |
| 615 return false; | 629 return false; |
| 616 | 630 |
| 631 // When GPU allocated memory runs low (due to having created too many accele rated canvases), the | |
| 632 // compositor starves and browser becomes laggy. Thus, we should stop alloca ting more GPU memory to | |
|
Justin Novosad
2015/12/08 22:15:27
wrapping
| |
| 633 // new canvases created when the current memory usage exceeds the threshold. | |
| 634 if (ImageBuffer::getTotalGPUMemoryUsage() >= MaxTotalGPUMemoryUsage) | |
| 635 return false; | |
| 636 | |
| 617 return true; | 637 return true; |
| 618 } | 638 } |
| 619 | 639 |
| 620 class UnacceleratedSurfaceFactory : public RecordingImageBufferFallbackSurfaceFa ctory { | 640 class UnacceleratedSurfaceFactory : public RecordingImageBufferFallbackSurfaceFa ctory { |
| 621 public: | 641 public: |
| 622 virtual PassOwnPtr<ImageBufferSurface> createSurface(const IntSize& size, Op acityMode opacityMode) | 642 virtual PassOwnPtr<ImageBufferSurface> createSurface(const IntSize& size, Op acityMode opacityMode) |
| 623 { | 643 { |
| 624 return adoptPtr(new UnacceleratedImageBufferSurface(size, opacityMode)); | 644 return adoptPtr(new UnacceleratedImageBufferSurface(size, opacityMode)); |
| 625 } | 645 } |
| 626 | 646 |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 755 // The number of internal GPU buffers vary between one (stable | 775 // The number of internal GPU buffers vary between one (stable |
| 756 // non-displayed state) and three (triple-buffered animations). | 776 // non-displayed state) and three (triple-buffered animations). |
| 757 // Adding 2 is a pessimistic but relevant estimate. | 777 // Adding 2 is a pessimistic but relevant estimate. |
| 758 // Note: These buffers might be allocated in GPU memory. | 778 // Note: These buffers might be allocated in GPU memory. |
| 759 bufferCount += 2; | 779 bufferCount += 2; |
| 760 } | 780 } |
| 761 } | 781 } |
| 762 if (m_copiedImage) | 782 if (m_copiedImage) |
| 763 bufferCount++; | 783 bufferCount++; |
| 764 | 784 |
| 765 // Four bytes per pixel per buffer. | |
|
Justin Novosad
2015/12/08 22:15:27
Why remove this comment?
| |
| 766 Checked<intptr_t, RecordOverflow> checkedExternallyAllocatedMemory = 4 * buf ferCount; | 785 Checked<intptr_t, RecordOverflow> checkedExternallyAllocatedMemory = 4 * buf ferCount; |
| 767 if (is3D()) | 786 if (is3D()) |
| 768 checkedExternallyAllocatedMemory += m_context->externallyAllocatedBytesP erPixel(); | 787 checkedExternallyAllocatedMemory += m_context->externallyAllocatedBytesP erPixel(); |
| 769 | 788 |
| 770 checkedExternallyAllocatedMemory *= width(); | 789 checkedExternallyAllocatedMemory *= width(); |
| 771 checkedExternallyAllocatedMemory *= height(); | 790 checkedExternallyAllocatedMemory *= height(); |
| 772 intptr_t externallyAllocatedMemory; | 791 intptr_t externallyAllocatedMemory; |
| 773 if (checkedExternallyAllocatedMemory.safeGet(externallyAllocatedMemory) == C heckedState::DidOverflow) | 792 if (checkedExternallyAllocatedMemory.safeGet(externallyAllocatedMemory) == C heckedState::DidOverflow) |
| 774 externallyAllocatedMemory = std::numeric_limits<intptr_t>::max(); | 793 externallyAllocatedMemory = std::numeric_limits<intptr_t>::max(); |
| 775 | 794 |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 950 } | 969 } |
| 951 return ImageBitmapSource::fulfillImageBitmap(scriptState, isPaintable() ? Im ageBitmap::create(this, IntRect(sx, sy, sw, sh)) : nullptr); | 970 return ImageBitmapSource::fulfillImageBitmap(scriptState, isPaintable() ? Im ageBitmap::create(this, IntRect(sx, sy, sw, sh)) : nullptr); |
| 952 } | 971 } |
| 953 | 972 |
| 954 bool HTMLCanvasElement::isOpaque() const | 973 bool HTMLCanvasElement::isOpaque() const |
| 955 { | 974 { |
| 956 return m_context && !m_context->hasAlpha(); | 975 return m_context && !m_context->hasAlpha(); |
| 957 } | 976 } |
| 958 | 977 |
| 959 } // blink | 978 } // blink |
| OLD | NEW |