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

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

Issue 2662003002: Fix a bug where PIXEL_UNPACK_BUFFER is cleared but never restored. (Closed)
Patch Set: Fix a bug where PIXEL_UNPACK_BUFFER is cleared but never restored. Created 3 years, 10 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 1570 matching lines...) Expand 10 before | Expand all | Expand 10 after
1581 return ImageData::create( 1581 return ImageData::create(
1582 IntSize(width, height), 1582 IntSize(width, height),
1583 DOMUint8ClampedArray::create(imageDataPixels, 0, 1583 DOMUint8ClampedArray::create(imageDataPixels, 0,
1584 imageDataPixels->byteLength())); 1584 imageDataPixels->byteLength()));
1585 } 1585 }
1586 1586
1587 void WebGLRenderingContextBase::reshape(int width, int height) { 1587 void WebGLRenderingContextBase::reshape(int width, int height) {
1588 if (isContextLost()) 1588 if (isContextLost())
1589 return; 1589 return;
1590 1590
1591 GLint buffer = 0;
1591 if (isWebGL2OrHigher()) { 1592 if (isWebGL2OrHigher()) {
1592 contextGL()->BindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); 1593 // This query returns client side cached binding, so it's trivial.
1594 // If it changes in the future, such query is heavy and should be avoided.
1595 contextGL()->GetIntegerv(GL_PIXEL_UNPACK_BUFFER_BINDING, &buffer);
1596 if (buffer) {
1597 contextGL()->BindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
1598 }
1593 } 1599 }
1594 1600
1595 // This is an approximation because at WebGLRenderingContextBase level we 1601 // This is an approximation because at WebGLRenderingContextBase level we
1596 // don't know if the underlying FBO uses textures or renderbuffers. 1602 // don't know if the underlying FBO uses textures or renderbuffers.
1597 GLint maxSize = std::min(m_maxTextureSize, m_maxRenderbufferSize); 1603 GLint maxSize = std::min(m_maxTextureSize, m_maxRenderbufferSize);
1598 GLint maxWidth = std::min(maxSize, m_maxViewportDims[0]); 1604 GLint maxWidth = std::min(maxSize, m_maxViewportDims[0]);
1599 GLint maxHeight = std::min(maxSize, m_maxViewportDims[1]); 1605 GLint maxHeight = std::min(maxSize, m_maxViewportDims[1]);
1600 width = clamp(width, 1, maxWidth); 1606 width = clamp(width, 1, maxWidth);
1601 height = clamp(height, 1, maxHeight); 1607 height = clamp(height, 1, maxHeight);
1602 1608
1603 // Limit drawing buffer area to 4k*4k to avoid memory exhaustion. Width or 1609 // Limit drawing buffer area to 4k*4k to avoid memory exhaustion. Width or
1604 // height may be larger than 4k as long as it's within the max viewport 1610 // height may be larger than 4k as long as it's within the max viewport
1605 // dimensions and total area remains within the limit. 1611 // dimensions and total area remains within the limit.
1606 // For example: 5120x2880 should be fine. 1612 // For example: 5120x2880 should be fine.
1607 const int maxArea = 4096 * 4096; 1613 const int maxArea = 4096 * 4096;
1608 int currentArea = width * height; 1614 int currentArea = width * height;
1609 if (currentArea > maxArea) { 1615 if (currentArea > maxArea) {
1610 // If we've exceeded the area limit scale the buffer down, preserving 1616 // If we've exceeded the area limit scale the buffer down, preserving
1611 // ascpect ratio, until it fits. 1617 // ascpect ratio, until it fits.
1612 float scaleFactor = 1618 float scaleFactor =
1613 sqrtf(static_cast<float>(maxArea) / static_cast<float>(currentArea)); 1619 sqrtf(static_cast<float>(maxArea) / static_cast<float>(currentArea));
1614 width = std::max(1, static_cast<int>(width * scaleFactor)); 1620 width = std::max(1, static_cast<int>(width * scaleFactor));
1615 height = std::max(1, static_cast<int>(height * scaleFactor)); 1621 height = std::max(1, static_cast<int>(height * scaleFactor));
1616 } 1622 }
1617 1623
1618 // We don't have to mark the canvas as dirty, since the newly created image 1624 // We don't have to mark the canvas as dirty, since the newly created image
1619 // buffer will also start off clear (and this matches what reshape will do). 1625 // buffer will also start off clear (and this matches what reshape will do).
1620 drawingBuffer()->resize(IntSize(width, height)); 1626 drawingBuffer()->resize(IntSize(width, height));
1627
1628 if (buffer) {
1629 contextGL()->BindBuffer(GL_PIXEL_UNPACK_BUFFER,
1630 static_cast<GLuint>(buffer));
1631 }
1621 } 1632 }
1622 1633
1623 int WebGLRenderingContextBase::drawingBufferWidth() const { 1634 int WebGLRenderingContextBase::drawingBufferWidth() const {
1624 return isContextLost() ? 0 : drawingBuffer()->size().width(); 1635 return isContextLost() ? 0 : drawingBuffer()->size().width();
1625 } 1636 }
1626 1637
1627 int WebGLRenderingContextBase::drawingBufferHeight() const { 1638 int WebGLRenderingContextBase::drawingBufferHeight() const {
1628 return isContextLost() ? 0 : drawingBuffer()->size().height(); 1639 return isContextLost() ? 0 : drawingBuffer()->size().height();
1629 } 1640 }
1630 1641
(...skipping 6196 matching lines...) Expand 10 before | Expand all | Expand 10 after
7827 7838
7828 void WebGLRenderingContextBase::getHTMLOrOffscreenCanvas( 7839 void WebGLRenderingContextBase::getHTMLOrOffscreenCanvas(
7829 HTMLCanvasElementOrOffscreenCanvas& result) const { 7840 HTMLCanvasElementOrOffscreenCanvas& result) const {
7830 if (canvas()) 7841 if (canvas())
7831 result.setHTMLCanvasElement(canvas()); 7842 result.setHTMLCanvasElement(canvas());
7832 else 7843 else
7833 result.setOffscreenCanvas(offscreenCanvas()); 7844 result.setOffscreenCanvas(offscreenCanvas());
7834 } 7845 }
7835 7846
7836 } // namespace blink 7847 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698