| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2009 Apple Inc. All rights reserved. | 2 * Copyright (C) 2009 Apple 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 | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 1370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1381 return ImageData::create( | 1381 return ImageData::create( |
| 1382 IntSize(width, height), | 1382 IntSize(width, height), |
| 1383 DOMUint8ClampedArray::create(imageDataPixels, 0, imageDataPixels->byteLe
ngth())); | 1383 DOMUint8ClampedArray::create(imageDataPixels, 0, imageDataPixels->byteLe
ngth())); |
| 1384 } | 1384 } |
| 1385 | 1385 |
| 1386 void WebGLRenderingContextBase::reshape(int width, int height) | 1386 void WebGLRenderingContextBase::reshape(int width, int height) |
| 1387 { | 1387 { |
| 1388 if (isContextLost()) | 1388 if (isContextLost()) |
| 1389 return; | 1389 return; |
| 1390 | 1390 |
| 1391 if (isWebGL2OrHigher()) { |
| 1392 contextGL()->BindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); |
| 1393 } |
| 1394 |
| 1391 // This is an approximation because at WebGLRenderingContextBase level we do
n't | 1395 // This is an approximation because at WebGLRenderingContextBase level we do
n't |
| 1392 // know if the underlying FBO uses textures or renderbuffers. | 1396 // know if the underlying FBO uses textures or renderbuffers. |
| 1393 GLint maxSize = std::min(m_maxTextureSize, m_maxRenderbufferSize); | 1397 GLint maxSize = std::min(m_maxTextureSize, m_maxRenderbufferSize); |
| 1394 GLint maxWidth = std::min(maxSize, m_maxViewportDims[0]); | 1398 GLint maxWidth = std::min(maxSize, m_maxViewportDims[0]); |
| 1395 GLint maxHeight = std::min(maxSize, m_maxViewportDims[1]); | 1399 GLint maxHeight = std::min(maxSize, m_maxViewportDims[1]); |
| 1396 width = clamp(width, 1, maxWidth); | 1400 width = clamp(width, 1, maxWidth); |
| 1397 height = clamp(height, 1, maxHeight); | 1401 height = clamp(height, 1, maxHeight); |
| 1398 | 1402 |
| 1399 // Limit drawing buffer area to 4k*4k to avoid memory exhaustion. Width or h
eight may be larger than | 1403 // Limit drawing buffer area to 4k*4k to avoid memory exhaustion. Width or h
eight may be larger than |
| 1400 // 4k as long as it's within the max viewport dimensions and total area rema
ins within the limit. | 1404 // 4k as long as it's within the max viewport dimensions and total area rema
ins within the limit. |
| 1401 // For example: 5120x2880 should be fine. | 1405 // For example: 5120x2880 should be fine. |
| 1402 const int maxArea = 4096 * 4096; | 1406 const int maxArea = 4096 * 4096; |
| 1403 int currentArea = width * height; | 1407 int currentArea = width * height; |
| 1404 if (currentArea > maxArea) { | 1408 if (currentArea > maxArea) { |
| 1405 // If we've exceeded the area limit scale the buffer down, preserving as
cpect ratio, until it fits. | 1409 // If we've exceeded the area limit scale the buffer down, preserving as
cpect ratio, until it fits. |
| 1406 float scaleFactor = sqrtf(static_cast<float>(maxArea) / static_cast<floa
t>(currentArea)); | 1410 float scaleFactor = sqrtf(static_cast<float>(maxArea) / static_cast<floa
t>(currentArea)); |
| 1407 width = std::max(1, static_cast<int>(width * scaleFactor)); | 1411 width = std::max(1, static_cast<int>(width * scaleFactor)); |
| 1408 height = std::max(1, static_cast<int>(height * scaleFactor)); | 1412 height = std::max(1, static_cast<int>(height * scaleFactor)); |
| 1409 } | 1413 } |
| 1410 | 1414 |
| 1411 // We don't have to mark the canvas as dirty, since the newly created image
buffer will also start off | 1415 // We don't have to mark the canvas as dirty, since the newly created image
buffer will also start off |
| 1412 // clear (and this matches what reshape will do). | 1416 // clear (and this matches what reshape will do). |
| 1413 drawingBuffer()->reset(IntSize(width, height)); | 1417 drawingBuffer()->reset(IntSize(width, height)); |
| 1414 restoreStateAfterClear(); | 1418 restoreStateAfterClear(); |
| 1415 | 1419 |
| 1416 contextGL()->BindTexture(GL_TEXTURE_2D, objectOrZero(m_textureUnits[m_active
TextureUnit].m_texture2DBinding.get())); | 1420 contextGL()->BindTexture(GL_TEXTURE_2D, objectOrZero(m_textureUnits[m_active
TextureUnit].m_texture2DBinding.get())); |
| 1417 contextGL()->BindRenderbuffer(GL_RENDERBUFFER, objectOrZero(m_renderbufferBi
nding.get())); | 1421 contextGL()->BindRenderbuffer(GL_RENDERBUFFER, objectOrZero(m_renderbufferBi
nding.get())); |
| 1418 drawingBuffer()->restoreFramebufferBindings(); | 1422 drawingBuffer()->restoreFramebufferBindings(); |
| 1423 drawingBuffer()->restorePixelUnpackBufferBindings(); |
| 1419 } | 1424 } |
| 1420 | 1425 |
| 1421 int WebGLRenderingContextBase::drawingBufferWidth() const | 1426 int WebGLRenderingContextBase::drawingBufferWidth() const |
| 1422 { | 1427 { |
| 1423 return isContextLost() ? 0 : drawingBuffer()->size().width(); | 1428 return isContextLost() ? 0 : drawingBuffer()->size().width(); |
| 1424 } | 1429 } |
| 1425 | 1430 |
| 1426 int WebGLRenderingContextBase::drawingBufferHeight() const | 1431 int WebGLRenderingContextBase::drawingBufferHeight() const |
| 1427 { | 1432 { |
| 1428 return isContextLost() ? 0 : drawingBuffer()->size().height(); | 1433 return isContextLost() ? 0 : drawingBuffer()->size().height(); |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1513 void WebGLRenderingContextBase::bindBuffer(GLenum target, WebGLBuffer* buffer) | 1518 void WebGLRenderingContextBase::bindBuffer(GLenum target, WebGLBuffer* buffer) |
| 1514 { | 1519 { |
| 1515 bool deleted; | 1520 bool deleted; |
| 1516 if (!checkObjectToBeBound("bindBuffer", buffer, deleted)) | 1521 if (!checkObjectToBeBound("bindBuffer", buffer, deleted)) |
| 1517 return; | 1522 return; |
| 1518 if (deleted) | 1523 if (deleted) |
| 1519 buffer = 0; | 1524 buffer = 0; |
| 1520 if (!validateAndUpdateBufferBindTarget("bindBuffer", target, buffer)) | 1525 if (!validateAndUpdateBufferBindTarget("bindBuffer", target, buffer)) |
| 1521 return; | 1526 return; |
| 1522 | 1527 |
| 1528 if (target == GL_PIXEL_UNPACK_BUFFER) { |
| 1529 drawingBuffer()->setPixelUnpackBufferBinding(objectOrZero(buffer)); |
| 1530 } |
| 1523 contextGL()->BindBuffer(target, objectOrZero(buffer)); | 1531 contextGL()->BindBuffer(target, objectOrZero(buffer)); |
| 1524 } | 1532 } |
| 1525 | 1533 |
| 1526 void WebGLRenderingContextBase::bindFramebuffer(GLenum target, WebGLFramebuffer*
buffer) | 1534 void WebGLRenderingContextBase::bindFramebuffer(GLenum target, WebGLFramebuffer*
buffer) |
| 1527 { | 1535 { |
| 1528 bool deleted; | 1536 bool deleted; |
| 1529 if (!checkObjectToBeBound("bindFramebuffer", buffer, deleted)) | 1537 if (!checkObjectToBeBound("bindFramebuffer", buffer, deleted)) |
| 1530 return; | 1538 return; |
| 1531 | 1539 |
| 1532 if (deleted) | 1540 if (deleted) |
| (...skipping 490 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2023 if (object->hasObject()) { | 2031 if (object->hasObject()) { |
| 2024 // We need to pass in context here because we want | 2032 // We need to pass in context here because we want |
| 2025 // things in this context unbound. | 2033 // things in this context unbound. |
| 2026 object->deleteObject(contextGL()); | 2034 object->deleteObject(contextGL()); |
| 2027 } | 2035 } |
| 2028 return true; | 2036 return true; |
| 2029 } | 2037 } |
| 2030 | 2038 |
| 2031 void WebGLRenderingContextBase::deleteBuffer(WebGLBuffer* buffer) | 2039 void WebGLRenderingContextBase::deleteBuffer(WebGLBuffer* buffer) |
| 2032 { | 2040 { |
| 2041 GLuint bufferName = objectOrZero(buffer); |
| 2033 if (!deleteObject(buffer)) | 2042 if (!deleteObject(buffer)) |
| 2034 return; | 2043 return; |
| 2044 drawingBuffer()->notifyBufferDeleted(bufferName); |
| 2035 removeBoundBuffer(buffer); | 2045 removeBoundBuffer(buffer); |
| 2036 } | 2046 } |
| 2037 | 2047 |
| 2038 void WebGLRenderingContextBase::deleteFramebuffer(WebGLFramebuffer* framebuffer) | 2048 void WebGLRenderingContextBase::deleteFramebuffer(WebGLFramebuffer* framebuffer) |
| 2039 { | 2049 { |
| 2040 if (!deleteObject(framebuffer)) | 2050 if (!deleteObject(framebuffer)) |
| 2041 return; | 2051 return; |
| 2042 if (framebuffer == m_framebufferBinding) { | 2052 if (framebuffer == m_framebufferBinding) { |
| 2043 m_framebufferBinding = nullptr; | 2053 m_framebufferBinding = nullptr; |
| 2044 drawingBuffer()->setFramebufferBinding(GL_FRAMEBUFFER, 0); | 2054 drawingBuffer()->setFramebufferBinding(GL_FRAMEBUFFER, 0); |
| (...skipping 4392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6437 | 6447 |
| 6438 void WebGLRenderingContextBase::getHTMLOrOffscreenCanvas(HTMLCanvasElementOrOffs
creenCanvas& result) const | 6448 void WebGLRenderingContextBase::getHTMLOrOffscreenCanvas(HTMLCanvasElementOrOffs
creenCanvas& result) const |
| 6439 { | 6449 { |
| 6440 if (canvas()) | 6450 if (canvas()) |
| 6441 result.setHTMLCanvasElement(canvas()); | 6451 result.setHTMLCanvasElement(canvas()); |
| 6442 else | 6452 else |
| 6443 result.setOffscreenCanvas(getOffscreenCanvas()); | 6453 result.setOffscreenCanvas(getOffscreenCanvas()); |
| 6444 } | 6454 } |
| 6445 | 6455 |
| 6446 } // namespace blink | 6456 } // namespace blink |
| OLD | NEW |