| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2010, Google Inc. All rights reserved. | 2 * Copyright (c) 2010, Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 #include "config.h" | 31 #include "config.h" |
| 32 | 32 |
| 33 #if ENABLE(ACCELERATED_2D_CANVAS) || ENABLE(WEBGL) | 33 #if ENABLE(ACCELERATED_2D_CANVAS) || ENABLE(WEBGL) |
| 34 | 34 |
| 35 #include "DrawingBuffer.h" | 35 #include "DrawingBuffer.h" |
| 36 | 36 |
| 37 #include "Extensions3D.h" | 37 #include "Extensions3D.h" |
| 38 | 38 |
| 39 namespace WebCore { | 39 namespace WebCore { |
| 40 | 40 |
| 41 // Global resource ceiling (expressed in terms of pixels) for DrawingBuffer crea
tion and resize. |
| 42 // When this limit is set, DrawingBuffer::create() and DrawingBuffer::reset() ca
lls that would |
| 43 // exceed the global cap will instead clear the buffer. |
| 44 #if PLATFORM(CHROMIUM) // Currently, this cap only exists for chromium. |
| 45 static int s_maximumResourceUsePixels = 16 * 1024 * 1024; |
| 46 #else |
| 47 static int s_maximumResourceUsePixels = 0; |
| 48 #endif |
| 49 static int s_currentResourceUsePixels = 0; |
| 50 |
| 41 PassRefPtr<DrawingBuffer> DrawingBuffer::create(GraphicsContext3D* context, cons
t IntSize& size) | 51 PassRefPtr<DrawingBuffer> DrawingBuffer::create(GraphicsContext3D* context, cons
t IntSize& size) |
| 42 { | 52 { |
| 43 Extensions3D* extensions = context->getExtensions(); | 53 Extensions3D* extensions = context->getExtensions(); |
| 44 bool multisampleSupported = extensions->supports("GL_ANGLE_framebuffer_blit"
) && extensions->supports("GL_ANGLE_framebuffer_multisample") && extensions->sup
ports("GL_OES_rgb8_rgba8"); | 54 bool multisampleSupported = extensions->supports("GL_ANGLE_framebuffer_blit"
) && extensions->supports("GL_ANGLE_framebuffer_multisample") && extensions->sup
ports("GL_OES_rgb8_rgba8"); |
| 45 if (multisampleSupported) { | 55 if (multisampleSupported) { |
| 46 extensions->ensureEnabled("GL_ANGLE_framebuffer_blit"); | 56 extensions->ensureEnabled("GL_ANGLE_framebuffer_blit"); |
| 47 extensions->ensureEnabled("GL_ANGLE_framebuffer_multisample"); | 57 extensions->ensureEnabled("GL_ANGLE_framebuffer_multisample"); |
| 48 extensions->ensureEnabled("GL_OES_rgb8_rgba8"); | 58 extensions->ensureEnabled("GL_OES_rgb8_rgba8"); |
| 49 } | 59 } |
| 50 bool packedDepthStencilSupported = extensions->supports("GL_OES_packed_depth
_stencil"); | 60 bool packedDepthStencilSupported = extensions->supports("GL_OES_packed_depth
_stencil"); |
| 51 if (packedDepthStencilSupported) | 61 if (packedDepthStencilSupported) |
| 52 extensions->ensureEnabled("GL_OES_packed_depth_stencil"); | 62 extensions->ensureEnabled("GL_OES_packed_depth_stencil"); |
| 53 RefPtr<DrawingBuffer> drawingBuffer = adoptRef(new DrawingBuffer(context, si
ze, multisampleSupported, packedDepthStencilSupported)); | 63 RefPtr<DrawingBuffer> drawingBuffer = adoptRef(new DrawingBuffer(context, si
ze, multisampleSupported, packedDepthStencilSupported)); |
| 54 return (drawingBuffer->m_context) ? drawingBuffer.release() : 0; | 64 return (drawingBuffer->m_context) ? drawingBuffer.release() : 0; |
| 55 } | 65 } |
| 56 | 66 |
| 57 void DrawingBuffer::clear() | 67 void DrawingBuffer::clear() |
| 58 { | 68 { |
| 59 if (!m_context) | 69 if (!m_context) |
| 60 return; | 70 return; |
| 61 | 71 |
| 62 m_context->makeContextCurrent(); | 72 m_context->makeContextCurrent(); |
| 73 if (!m_size.isEmpty()) |
| 74 s_currentResourceUsePixels -= m_size.width() * m_size.height(); |
| 63 | 75 |
| 64 if (m_colorBuffer) { | 76 if (m_colorBuffer) { |
| 65 m_context->deleteTexture(m_colorBuffer); | 77 m_context->deleteTexture(m_colorBuffer); |
| 66 m_colorBuffer = 0; | 78 m_colorBuffer = 0; |
| 67 } | 79 } |
| 68 | 80 |
| 69 if (m_multisampleColorBuffer) { | 81 if (m_multisampleColorBuffer) { |
| 70 m_context->deleteRenderbuffer(m_multisampleColorBuffer); | 82 m_context->deleteRenderbuffer(m_multisampleColorBuffer); |
| 71 m_multisampleColorBuffer = 0; | 83 m_multisampleColorBuffer = 0; |
| 72 } | 84 } |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 bool DrawingBuffer::reset(const IntSize& newSize) | 207 bool DrawingBuffer::reset(const IntSize& newSize) |
| 196 { | 208 { |
| 197 if (!m_context) | 209 if (!m_context) |
| 198 return false; | 210 return false; |
| 199 | 211 |
| 200 m_context->makeContextCurrent(); | 212 m_context->makeContextCurrent(); |
| 201 | 213 |
| 202 int maxTextureSize = 0; | 214 int maxTextureSize = 0; |
| 203 m_context->getIntegerv(GraphicsContext3D::MAX_TEXTURE_SIZE, &maxTextureSize)
; | 215 m_context->getIntegerv(GraphicsContext3D::MAX_TEXTURE_SIZE, &maxTextureSize)
; |
| 204 if (newSize.height() > maxTextureSize || newSize.width() > maxTextureSize) { | 216 if (newSize.height() > maxTextureSize || newSize.width() > maxTextureSize) { |
| 205 clear(); | 217 clear(); |
| 206 return false; | 218 return false; |
| 207 } | 219 } |
| 208 | 220 |
| 221 int pixelDelta = newSize.width() * newSize.height(); |
| 222 if (!m_size.isEmpty()) |
| 223 pixelDelta -= m_size.width() * m_size.height(); |
| 224 |
| 225 if (s_maximumResourceUsePixels && (s_currentResourceUsePixels + pixelDelta)
> s_maximumResourceUsePixels) { |
| 226 clear(); |
| 227 return false; |
| 228 } |
| 229 s_currentResourceUsePixels += pixelDelta; |
| 230 |
| 209 const GraphicsContext3D::Attributes& attributes = m_context->getContextAttri
butes(); | 231 const GraphicsContext3D::Attributes& attributes = m_context->getContextAttri
butes(); |
| 210 | 232 |
| 211 if (newSize != m_size) { | 233 if (newSize != m_size) { |
| 212 m_size = newSize; | 234 m_size = newSize; |
| 213 | 235 |
| 214 unsigned long internalColorFormat, colorFormat, internalRenderbufferForm
at; | 236 unsigned long internalColorFormat, colorFormat, internalRenderbufferForm
at; |
| 215 if (attributes.alpha) { | 237 if (attributes.alpha) { |
| 216 internalColorFormat = GraphicsContext3D::RGBA; | 238 internalColorFormat = GraphicsContext3D::RGBA; |
| 217 colorFormat = GraphicsContext3D::RGBA; | 239 colorFormat = GraphicsContext3D::RGBA; |
| 218 internalRenderbufferFormat = Extensions3D::RGBA8_OES; | 240 internalRenderbufferFormat = Extensions3D::RGBA8_OES; |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 295 if (!m_context) | 317 if (!m_context) |
| 296 return; | 318 return; |
| 297 | 319 |
| 298 m_context->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, m_multisampleFBO
? m_multisampleFBO : m_fbo); | 320 m_context->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, m_multisampleFBO
? m_multisampleFBO : m_fbo); |
| 299 m_context->viewport(0, 0, m_size.width(), m_size.height()); | 321 m_context->viewport(0, 0, m_size.width(), m_size.height()); |
| 300 } | 322 } |
| 301 | 323 |
| 302 } // namespace WebCore | 324 } // namespace WebCore |
| 303 | 325 |
| 304 #endif | 326 #endif |
| OLD | NEW |