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

Side by Side Diff: third_party/WebKit/Source/modules/webgl/WebGLRenderingContextBase.cpp

Issue 2329523002: Save/restore PBO bindings in DrawingBuffer (Closed)
Patch Set: Created 4 years, 3 months 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
OLDNEW
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
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 contextGL()->BindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
Zhenyao Mo 2016/09/09 18:58:04 You can't do this in WebGL1 because if it's implem
Kai Ninomiya 2016/09/09 20:30:44 Done.
1392
1391 // This is an approximation because at WebGLRenderingContextBase level we do n't 1393 // This is an approximation because at WebGLRenderingContextBase level we do n't
1392 // know if the underlying FBO uses textures or renderbuffers. 1394 // know if the underlying FBO uses textures or renderbuffers.
1393 GLint maxSize = std::min(m_maxTextureSize, m_maxRenderbufferSize); 1395 GLint maxSize = std::min(m_maxTextureSize, m_maxRenderbufferSize);
1394 GLint maxWidth = std::min(maxSize, m_maxViewportDims[0]); 1396 GLint maxWidth = std::min(maxSize, m_maxViewportDims[0]);
1395 GLint maxHeight = std::min(maxSize, m_maxViewportDims[1]); 1397 GLint maxHeight = std::min(maxSize, m_maxViewportDims[1]);
1396 width = clamp(width, 1, maxWidth); 1398 width = clamp(width, 1, maxWidth);
1397 height = clamp(height, 1, maxHeight); 1399 height = clamp(height, 1, maxHeight);
1398 1400
1399 // Limit drawing buffer area to 4k*4k to avoid memory exhaustion. Width or h eight may be larger than 1401 // 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. 1402 // 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. 1403 // For example: 5120x2880 should be fine.
1402 const int maxArea = 4096 * 4096; 1404 const int maxArea = 4096 * 4096;
1403 int currentArea = width * height; 1405 int currentArea = width * height;
1404 if (currentArea > maxArea) { 1406 if (currentArea > maxArea) {
1405 // If we've exceeded the area limit scale the buffer down, preserving as cpect ratio, until it fits. 1407 // 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)); 1408 float scaleFactor = sqrtf(static_cast<float>(maxArea) / static_cast<floa t>(currentArea));
1407 width = std::max(1, static_cast<int>(width * scaleFactor)); 1409 width = std::max(1, static_cast<int>(width * scaleFactor));
1408 height = std::max(1, static_cast<int>(height * scaleFactor)); 1410 height = std::max(1, static_cast<int>(height * scaleFactor));
1409 } 1411 }
1410 1412
1411 // We don't have to mark the canvas as dirty, since the newly created image buffer will also start off 1413 // 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). 1414 // clear (and this matches what reshape will do).
1413 drawingBuffer()->reset(IntSize(width, height)); 1415 drawingBuffer()->reset(IntSize(width, height));
1414 restoreStateAfterClear(); 1416 restoreStateAfterClear();
1415 1417
1416 contextGL()->BindTexture(GL_TEXTURE_2D, objectOrZero(m_textureUnits[m_active TextureUnit].m_texture2DBinding.get())); 1418 contextGL()->BindTexture(GL_TEXTURE_2D, objectOrZero(m_textureUnits[m_active TextureUnit].m_texture2DBinding.get()));
1417 contextGL()->BindRenderbuffer(GL_RENDERBUFFER, objectOrZero(m_renderbufferBi nding.get())); 1419 contextGL()->BindRenderbuffer(GL_RENDERBUFFER, objectOrZero(m_renderbufferBi nding.get()));
1418 drawingBuffer()->restoreFramebufferBindings(); 1420 drawingBuffer()->restoreFramebufferBindings();
1421 drawingBuffer()->restorePixelUnpackBufferBindings();
1419 } 1422 }
1420 1423
1421 int WebGLRenderingContextBase::drawingBufferWidth() const 1424 int WebGLRenderingContextBase::drawingBufferWidth() const
1422 { 1425 {
1423 return isContextLost() ? 0 : drawingBuffer()->size().width(); 1426 return isContextLost() ? 0 : drawingBuffer()->size().width();
1424 } 1427 }
1425 1428
1426 int WebGLRenderingContextBase::drawingBufferHeight() const 1429 int WebGLRenderingContextBase::drawingBufferHeight() const
1427 { 1430 {
1428 return isContextLost() ? 0 : drawingBuffer()->size().height(); 1431 return isContextLost() ? 0 : drawingBuffer()->size().height();
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
1513 void WebGLRenderingContextBase::bindBuffer(GLenum target, WebGLBuffer* buffer) 1516 void WebGLRenderingContextBase::bindBuffer(GLenum target, WebGLBuffer* buffer)
1514 { 1517 {
1515 bool deleted; 1518 bool deleted;
1516 if (!checkObjectToBeBound("bindBuffer", buffer, deleted)) 1519 if (!checkObjectToBeBound("bindBuffer", buffer, deleted))
1517 return; 1520 return;
1518 if (deleted) 1521 if (deleted)
1519 buffer = 0; 1522 buffer = 0;
1520 if (!validateAndUpdateBufferBindTarget("bindBuffer", target, buffer)) 1523 if (!validateAndUpdateBufferBindTarget("bindBuffer", target, buffer))
1521 return; 1524 return;
1522 1525
1526 if (target == GL_PIXEL_UNPACK_BUFFER) {
1527 drawingBuffer()->setPixelUnpackBufferBinding(objectOrZero(buffer));
1528 }
1523 contextGL()->BindBuffer(target, objectOrZero(buffer)); 1529 contextGL()->BindBuffer(target, objectOrZero(buffer));
1524 } 1530 }
1525 1531
1526 void WebGLRenderingContextBase::bindFramebuffer(GLenum target, WebGLFramebuffer* buffer) 1532 void WebGLRenderingContextBase::bindFramebuffer(GLenum target, WebGLFramebuffer* buffer)
1527 { 1533 {
1528 bool deleted; 1534 bool deleted;
1529 if (!checkObjectToBeBound("bindFramebuffer", buffer, deleted)) 1535 if (!checkObjectToBeBound("bindFramebuffer", buffer, deleted))
1530 return; 1536 return;
1531 1537
1532 if (deleted) 1538 if (deleted)
(...skipping 4443 matching lines...) Expand 10 before | Expand all | Expand 10 after
5976 synthesizeGLError(GL_INVALID_ENUM, functionName, "invalid usage"); 5982 synthesizeGLError(GL_INVALID_ENUM, functionName, "invalid usage");
5977 return false; 5983 return false;
5978 } 5984 }
5979 } 5985 }
5980 5986
5981 void WebGLRenderingContextBase::removeBoundBuffer(WebGLBuffer* buffer) 5987 void WebGLRenderingContextBase::removeBoundBuffer(WebGLBuffer* buffer)
5982 { 5988 {
5983 if (m_boundArrayBuffer == buffer) 5989 if (m_boundArrayBuffer == buffer)
5984 m_boundArrayBuffer = nullptr; 5990 m_boundArrayBuffer = nullptr;
5985 5991
5992 drawingBuffer()->notifyBufferDeleted(objectOrZero(buffer));
5986 m_boundVertexArrayObject->unbindBuffer(buffer); 5993 m_boundVertexArrayObject->unbindBuffer(buffer);
5987 } 5994 }
5988 5995
5989 bool WebGLRenderingContextBase::validateHTMLImageElement(const char* functionNam e, HTMLImageElement* image, ExceptionState& exceptionState) 5996 bool WebGLRenderingContextBase::validateHTMLImageElement(const char* functionNam e, HTMLImageElement* image, ExceptionState& exceptionState)
5990 { 5997 {
5991 if (!image || !image->cachedImage()) { 5998 if (!image || !image->cachedImage()) {
5992 synthesizeGLError(GL_INVALID_VALUE, functionName, "no image"); 5999 synthesizeGLError(GL_INVALID_VALUE, functionName, "no image");
5993 return false; 6000 return false;
5994 } 6001 }
5995 const KURL& url = image->cachedImage()->response().url(); 6002 const KURL& url = image->cachedImage()->response().url();
(...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after
6437 6444
6438 void WebGLRenderingContextBase::getHTMLOrOffscreenCanvas(HTMLCanvasElementOrOffs creenCanvas& result) const 6445 void WebGLRenderingContextBase::getHTMLOrOffscreenCanvas(HTMLCanvasElementOrOffs creenCanvas& result) const
6439 { 6446 {
6440 if (canvas()) 6447 if (canvas())
6441 result.setHTMLCanvasElement(canvas()); 6448 result.setHTMLCanvasElement(canvas());
6442 else 6449 else
6443 result.setOffscreenCanvas(getOffscreenCanvas()); 6450 result.setOffscreenCanvas(getOffscreenCanvas());
6444 } 6451 }
6445 6452
6446 } // namespace blink 6453 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698