void GraphicsContext3D::readPixelsAndConvertToBGRAIfNecessary(int x, int y, int width, int height, unsigned char* pixels) { ASSERT(m_private); bool readBGRA = !isGLES2Compliant() || platformGraphicsContext3D()->hasExtension("GL_EXT_read_format_bgra"); if (readBGRA) m_functions->glReadPixels(x, y, width, height, GL_BGRA, GL_UNSIGNED_BYTE, pixels); else m_functions->glReadPixels(x, y, width, height, GL_RGBA, GL_UNSIGNED_BYTE, pixels); int totalBytes = width * height * 4; if (!readBGRA) { for (int i = 0; i < totalBytes; i += 4) std::swap(pixels[i], pixels[i + 2]); // Convert to BGRA. } }
void GraphicsContext3D::reshape(int width, int height) { if (!platformGraphicsContext3D()) return; if (width == m_currentWidth && height == m_currentHeight) return; #if PLATFORM(QT) && USE(GRAPHICS_SURFACE) ::glFlush(); // Make sure all GL calls have been committed before resizing. createGraphicsSurfaces(IntSize(width, height)); #endif m_currentWidth = width; m_currentHeight = height; makeContextCurrent(); validateAttributes(); bool mustRestoreFBO = reshapeFBOs(IntSize(width, height)); // Initialize renderbuffers to 0. GLfloat clearColor[] = {0, 0, 0, 0}, clearDepth = 0; GLint clearStencil = 0; GLboolean colorMask[] = {GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE}, depthMask = GL_TRUE; GLuint stencilMask = 0xffffffff; GLboolean isScissorEnabled = GL_FALSE; GLboolean isDitherEnabled = GL_FALSE; GLbitfield clearMask = GL_COLOR_BUFFER_BIT; ::glGetFloatv(GL_COLOR_CLEAR_VALUE, clearColor); ::glClearColor(0, 0, 0, 0); ::glGetBooleanv(GL_COLOR_WRITEMASK, colorMask); ::glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); if (m_attrs.depth) { ::glGetFloatv(GL_DEPTH_CLEAR_VALUE, &clearDepth); GraphicsContext3D::clearDepth(1); ::glGetBooleanv(GL_DEPTH_WRITEMASK, &depthMask); ::glDepthMask(GL_TRUE); clearMask |= GL_DEPTH_BUFFER_BIT; } if (m_attrs.stencil) { ::glGetIntegerv(GL_STENCIL_CLEAR_VALUE, &clearStencil); ::glClearStencil(0); ::glGetIntegerv(GL_STENCIL_WRITEMASK, reinterpret_cast<GLint*>(&stencilMask)); ::glStencilMaskSeparate(GL_FRONT, 0xffffffff); clearMask |= GL_STENCIL_BUFFER_BIT; } isScissorEnabled = ::glIsEnabled(GL_SCISSOR_TEST); ::glDisable(GL_SCISSOR_TEST); isDitherEnabled = ::glIsEnabled(GL_DITHER); ::glDisable(GL_DITHER); ::glClear(clearMask); ::glClearColor(clearColor[0], clearColor[1], clearColor[2], clearColor[3]); ::glColorMask(colorMask[0], colorMask[1], colorMask[2], colorMask[3]); if (m_attrs.depth) { GraphicsContext3D::clearDepth(clearDepth); ::glDepthMask(depthMask); } if (m_attrs.stencil) { ::glClearStencil(clearStencil); ::glStencilMaskSeparate(GL_FRONT, stencilMask); } if (isScissorEnabled) ::glEnable(GL_SCISSOR_TEST); else ::glDisable(GL_SCISSOR_TEST); if (isDitherEnabled) ::glEnable(GL_DITHER); else ::glDisable(GL_DITHER); if (mustRestoreFBO) ::glBindFramebufferEXT(GraphicsContext3D::FRAMEBUFFER, m_boundFBO); ::glFlush(); }