| 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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 | 42 |
| 43 // Global resource ceiling (expressed in terms of pixels) for DrawingBuffer crea
tion and resize. | 43 // Global resource ceiling (expressed in terms of pixels) for DrawingBuffer crea
tion and resize. |
| 44 // When this limit is set, DrawingBuffer::create() and DrawingBuffer::reset() ca
lls that would | 44 // When this limit is set, DrawingBuffer::create() and DrawingBuffer::reset() ca
lls that would |
| 45 // exceed the global cap will instead clear the buffer. | 45 // exceed the global cap will instead clear the buffer. |
| 46 #if PLATFORM(CHROMIUM) // Currently, this cap only exists for chromium. | 46 #if PLATFORM(CHROMIUM) // Currently, this cap only exists for chromium. |
| 47 static int s_maximumResourceUsePixels = 16 * 1024 * 1024; | 47 static int s_maximumResourceUsePixels = 16 * 1024 * 1024; |
| 48 #else | 48 #else |
| 49 static int s_maximumResourceUsePixels = 0; | 49 static int s_maximumResourceUsePixels = 0; |
| 50 #endif | 50 #endif |
| 51 static int s_currentResourceUsePixels = 0; | 51 static int s_currentResourceUsePixels = 0; |
| 52 static const float s_resourceAdjustedRatio = 0.5; |
| 52 | 53 |
| 53 PassRefPtr<DrawingBuffer> DrawingBuffer::create(GraphicsContext3D* context, cons
t IntSize& size, bool separateBackingTexture) | 54 PassRefPtr<DrawingBuffer> DrawingBuffer::create(GraphicsContext3D* context, cons
t IntSize& size, bool separateBackingTexture) |
| 54 { | 55 { |
| 55 Extensions3D* extensions = context->getExtensions(); | 56 Extensions3D* extensions = context->getExtensions(); |
| 56 bool multisampleSupported = extensions->supports("GL_ANGLE_framebuffer_blit"
) && extensions->supports("GL_ANGLE_framebuffer_multisample") && extensions->sup
ports("GL_OES_rgb8_rgba8"); | 57 bool multisampleSupported = extensions->supports("GL_ANGLE_framebuffer_blit"
) && extensions->supports("GL_ANGLE_framebuffer_multisample") && extensions->sup
ports("GL_OES_rgb8_rgba8"); |
| 57 if (multisampleSupported) { | 58 if (multisampleSupported) { |
| 58 extensions->ensureEnabled("GL_ANGLE_framebuffer_blit"); | 59 extensions->ensureEnabled("GL_ANGLE_framebuffer_blit"); |
| 59 extensions->ensureEnabled("GL_ANGLE_framebuffer_multisample"); | 60 extensions->ensureEnabled("GL_ANGLE_framebuffer_multisample"); |
| 60 extensions->ensureEnabled("GL_OES_rgb8_rgba8"); | 61 extensions->ensureEnabled("GL_OES_rgb8_rgba8"); |
| 61 } | 62 } |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 m_context->makeContextCurrent(); | 230 m_context->makeContextCurrent(); |
| 230 | 231 |
| 231 int maxTextureSize = 0; | 232 int maxTextureSize = 0; |
| 232 m_context->getIntegerv(GraphicsContext3D::MAX_TEXTURE_SIZE, &maxTextureSize)
; | 233 m_context->getIntegerv(GraphicsContext3D::MAX_TEXTURE_SIZE, &maxTextureSize)
; |
| 233 if (newSize.height() > maxTextureSize || newSize.width() > maxTextureSize) { | 234 if (newSize.height() > maxTextureSize || newSize.width() > maxTextureSize) { |
| 234 clear(); | 235 clear(); |
| 235 return false; | 236 return false; |
| 236 } | 237 } |
| 237 | 238 |
| 238 int pixelDelta = newSize.width() * newSize.height(); | 239 int pixelDelta = newSize.width() * newSize.height(); |
| 239 if (!m_size.isEmpty()) | 240 int oldSize = 0; |
| 240 pixelDelta -= m_size.width() * m_size.height(); | 241 if (!m_size.isEmpty()) { |
| 242 oldSize = m_size.width() * m_size.height(); |
| 243 pixelDelta -= oldSize; |
| 244 } |
| 241 | 245 |
| 242 if (s_maximumResourceUsePixels && (s_currentResourceUsePixels + pixelDelta)
> s_maximumResourceUsePixels) { | 246 IntSize adjustedSize = newSize; |
| 243 clear(); | 247 if (s_maximumResourceUsePixels) { |
| 244 return false; | 248 while ((s_currentResourceUsePixels + pixelDelta) > s_maximumResourceUseP
ixels) { |
| 245 } | 249 adjustedSize.scale(s_resourceAdjustedRatio); |
| 246 s_currentResourceUsePixels += pixelDelta; | 250 if (adjustedSize.isEmpty()) { |
| 251 clear(); |
| 252 return false; |
| 253 } |
| 254 pixelDelta = adjustedSize.width() * adjustedSize.height(); |
| 255 pixelDelta -= oldSize; |
| 256 } |
| 257 } |
| 247 | 258 |
| 248 const GraphicsContext3D::Attributes& attributes = m_context->getContextAttri
butes(); | 259 const GraphicsContext3D::Attributes& attributes = m_context->getContextAttri
butes(); |
| 249 | 260 |
| 250 if (newSize != m_size) { | 261 if (adjustedSize != m_size) { |
| 251 m_size = newSize; | |
| 252 | 262 |
| 253 unsigned internalColorFormat, colorFormat, internalRenderbufferFormat; | 263 unsigned internalColorFormat, colorFormat, internalRenderbufferFormat; |
| 254 if (attributes.alpha) { | 264 if (attributes.alpha) { |
| 255 internalColorFormat = GraphicsContext3D::RGBA; | 265 internalColorFormat = GraphicsContext3D::RGBA; |
| 256 colorFormat = GraphicsContext3D::RGBA; | 266 colorFormat = GraphicsContext3D::RGBA; |
| 257 internalRenderbufferFormat = Extensions3D::RGBA8_OES; | 267 internalRenderbufferFormat = Extensions3D::RGBA8_OES; |
| 258 } else { | 268 } else { |
| 259 internalColorFormat = GraphicsContext3D::RGB; | 269 internalColorFormat = GraphicsContext3D::RGB; |
| 260 colorFormat = GraphicsContext3D::RGB; | 270 colorFormat = GraphicsContext3D::RGB; |
| 261 internalRenderbufferFormat = Extensions3D::RGB8_OES; | 271 internalRenderbufferFormat = Extensions3D::RGB8_OES; |
| 262 } | 272 } |
| 263 | 273 |
| 264 | 274 |
| 265 // resize multisample FBO | 275 do { |
| 266 if (multisample()) { | 276 m_size = adjustedSize; |
| 267 int maxSampleCount = 0; | 277 // resize multisample FBO |
| 268 | 278 if (multisample()) { |
| 269 m_context->getIntegerv(Extensions3D::MAX_SAMPLES, &maxSampleCount); | 279 int maxSampleCount = 0; |
| 270 int sampleCount = std::min(4, maxSampleCount); | |
| 271 | 280 |
| 272 m_context->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, m_multisa
mpleFBO); | 281 m_context->getIntegerv(Extensions3D::MAX_SAMPLES, &maxSampleCoun
t); |
| 282 int sampleCount = std::min(4, maxSampleCount); |
| 273 | 283 |
| 274 m_context->bindRenderbuffer(GraphicsContext3D::RENDERBUFFER, m_multi
sampleColorBuffer); | 284 m_context->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, m_mul
tisampleFBO); |
| 275 m_context->getExtensions()->renderbufferStorageMultisample(GraphicsC
ontext3D::RENDERBUFFER, sampleCount, internalRenderbufferFormat, m_size.width(),
m_size.height()); | 285 |
| 276 m_context->framebufferRenderbuffer(GraphicsContext3D::FRAMEBUFFER, G
raphicsContext3D::COLOR_ATTACHMENT0, GraphicsContext3D::RENDERBUFFER, m_multisam
pleColorBuffer); | 286 m_context->bindRenderbuffer(GraphicsContext3D::RENDERBUFFER, m_m
ultisampleColorBuffer); |
| 277 resizeDepthStencil(sampleCount); | 287 m_context->getExtensions()->renderbufferStorageMultisample(Graph
icsContext3D::RENDERBUFFER, sampleCount, internalRenderbufferFormat, m_size.widt
h(), m_size.height()); |
| 278 if (m_context->checkFramebufferStatus(GraphicsContext3D::FRAMEBUFFER
) != GraphicsContext3D::FRAMEBUFFER_COMPLETE) { | 288 m_context->framebufferRenderbuffer(GraphicsContext3D::FRAMEBUFFE
R, GraphicsContext3D::COLOR_ATTACHMENT0, GraphicsContext3D::RENDERBUFFER, m_mult
isampleColorBuffer); |
| 279 // Cleanup | 289 resizeDepthStencil(sampleCount); |
| 280 clear(); | 290 if (m_context->checkFramebufferStatus(GraphicsContext3D::FRAMEBU
FFER) != GraphicsContext3D::FRAMEBUFFER_COMPLETE) { |
| 281 return false; | 291 adjustedSize.scale(s_resourceAdjustedRatio); |
| 292 continue; |
| 293 } |
| 282 } | 294 } |
| 283 } | |
| 284 | 295 |
| 285 // resize regular FBO | 296 // resize regular FBO |
| 286 m_context->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, m_fbo); | 297 m_context->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, m_fbo); |
| 287 | 298 |
| 288 m_context->bindTexture(GraphicsContext3D::TEXTURE_2D, m_colorBuffer); | 299 m_context->bindTexture(GraphicsContext3D::TEXTURE_2D, m_colorBuffer)
; |
| 289 m_context->texImage2D(GraphicsContext3D::TEXTURE_2D, 0, internalColorFor
mat, m_size.width(), m_size.height(), 0, colorFormat, GraphicsContext3D::UNSIGNE
D_BYTE, 0); | 300 m_context->texImage2D(GraphicsContext3D::TEXTURE_2D, 0, internalColo
rFormat, m_size.width(), m_size.height(), 0, colorFormat, GraphicsContext3D::UNS
IGNED_BYTE, 0); |
| 290 | 301 |
| 291 m_context->framebufferTexture2D(GraphicsContext3D::FRAMEBUFFER, Graphics
Context3D::COLOR_ATTACHMENT0, GraphicsContext3D::TEXTURE_2D, m_colorBuffer, 0); | 302 m_context->framebufferTexture2D(GraphicsContext3D::FRAMEBUFFER, Grap
hicsContext3D::COLOR_ATTACHMENT0, GraphicsContext3D::TEXTURE_2D, m_colorBuffer,
0); |
| 292 | 303 |
| 293 // resize the backing color buffer | 304 // resize the backing color buffer |
| 294 if (m_separateBackingTexture) { | 305 if (m_separateBackingTexture) { |
| 295 m_context->bindTexture(GraphicsContext3D::TEXTURE_2D, m_backingColor
Buffer); | 306 m_context->bindTexture(GraphicsContext3D::TEXTURE_2D, m_backingC
olorBuffer); |
| 296 m_context->texImage2D(GraphicsContext3D::TEXTURE_2D, 0, internalColo
rFormat, m_size.width(), m_size.height(), 0, colorFormat, GraphicsContext3D::UNS
IGNED_BYTE, 0); | 307 m_context->texImage2D(GraphicsContext3D::TEXTURE_2D, 0, internal
ColorFormat, m_size.width(), m_size.height(), 0, colorFormat, GraphicsContext3D:
:UNSIGNED_BYTE, 0); |
| 297 } | 308 } |
| 298 | 309 |
| 299 m_context->bindTexture(GraphicsContext3D::TEXTURE_2D, 0); | 310 m_context->bindTexture(GraphicsContext3D::TEXTURE_2D, 0); |
| 300 | 311 |
| 301 if (!multisample()) | 312 if (!multisample()) |
| 302 resizeDepthStencil(0); | 313 resizeDepthStencil(0); |
| 303 if (m_context->checkFramebufferStatus(GraphicsContext3D::FRAMEBUFFER) !=
GraphicsContext3D::FRAMEBUFFER_COMPLETE) { | 314 if (m_context->checkFramebufferStatus(GraphicsContext3D::FRAMEBUFFER
) == GraphicsContext3D::FRAMEBUFFER_COMPLETE) |
| 304 // Cleanup | 315 break; |
| 316 adjustedSize.scale(s_resourceAdjustedRatio); |
| 317 |
| 318 } while (!adjustedSize.isEmpty()); |
| 319 |
| 320 pixelDelta = m_size.width() * m_size.height(); |
| 321 pixelDelta -= oldSize; |
| 322 s_currentResourceUsePixels += pixelDelta; |
| 323 |
| 324 if (!newSize.isEmpty() && adjustedSize.isEmpty()) { |
| 305 clear(); | 325 clear(); |
| 306 return false; | 326 return false; |
| 307 } | 327 } |
| 308 } | 328 } |
| 309 | 329 |
| 310 clearFramebuffer(); | 330 clearFramebuffer(); |
| 311 | 331 |
| 312 return true; | 332 return true; |
| 313 } | 333 } |
| 314 | 334 |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 370 { | 390 { |
| 371 if (!m_context) | 391 if (!m_context) |
| 372 return; | 392 return; |
| 373 | 393 |
| 374 m_context->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, m_multisampleFBO
? m_multisampleFBO : m_fbo); | 394 m_context->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, m_multisampleFBO
? m_multisampleFBO : m_fbo); |
| 375 } | 395 } |
| 376 | 396 |
| 377 } // namespace WebCore | 397 } // namespace WebCore |
| 378 | 398 |
| 379 #endif | 399 #endif |
| OLD | NEW |