LayerRendererChromium::~LayerRendererChromium() { ASSERT(CCProxy::isImplThread()); Extensions3DChromium* extensions3DChromium = static_cast<Extensions3DChromium*>(m_context->getExtensions()); extensions3DChromium->setSwapBuffersCompleteCallbackCHROMIUM(nullptr); m_headsUpDisplay.clear(); // Explicitly destroy the HUD before the TextureManager dies. cleanupSharedObjects(); }
bool LayerRendererChromium::initializeSharedObjects() { makeContextCurrent(); // Get the max texture size supported by the system. m_maxTextureSize = 0; GLC(m_context.get(), m_context->getIntegerv(GraphicsContext3D::MAX_TEXTURE_SIZE, &m_maxTextureSize)); // Create an FBO for doing offscreen rendering. GLC(m_context.get(), m_offscreenFramebufferId = m_context->createFramebuffer()); m_sharedGeometry = adoptPtr(new GeometryBinding(m_context.get())); m_borderProgram = adoptPtr(new LayerChromium::BorderProgram(m_context.get())); m_headsUpDisplayProgram = adoptPtr(new CCHeadsUpDisplay::Program(m_context.get())); m_canvasLayerProgram = adoptPtr(new CCCanvasLayerImpl::Program(m_context.get())); m_videoLayerRGBAProgram = adoptPtr(new CCVideoLayerImpl::RGBAProgram(m_context.get())); m_videoLayerYUVProgram = adoptPtr(new CCVideoLayerImpl::YUVProgram(m_context.get())); m_pluginLayerProgram = adoptPtr(new CCPluginLayerImpl::Program(m_context.get())); m_renderSurfaceProgram = adoptPtr(new RenderSurfaceChromium::Program(m_context.get())); m_renderSurfaceMaskProgram = adoptPtr(new RenderSurfaceChromium::MaskProgram(m_context.get())); m_tilerProgram = adoptPtr(new LayerTilerChromium::Program(m_context.get())); if (!m_sharedGeometry->initialized() || !m_borderProgram->initialized() || !m_canvasLayerProgram->initialized() || !m_headsUpDisplayProgram->initialized() || !m_videoLayerRGBAProgram->initialized() || !m_videoLayerYUVProgram->initialized() || !m_pluginLayerProgram->initialized() || !m_renderSurfaceProgram->initialized() || !m_renderSurfaceMaskProgram->initialized() || !m_tilerProgram->initialized()) { LOG_ERROR("Compositor failed to initialize shaders. Falling back to software."); cleanupSharedObjects(); return false; } m_textureManager = TextureManager::create(m_context.get(), textureMemoryLimitBytes, m_maxTextureSize); return true; }
LayerRendererChromium::~LayerRendererChromium() { cleanupSharedObjects(); }
bool LayerRendererChromium::initializeSharedObjects() { makeContextCurrent(); // Vertex and fragment shaders for rendering the scrolled root layer quad. // They differ from a regular content layer shader in that they don't swizzle // the colors or take an alpha value. char scrollVertexShaderString[] = "attribute vec4 a_position; \n" "attribute vec2 a_texCoord; \n" "uniform mat4 matrix; \n" "varying vec2 v_texCoord; \n" "void main() \n" "{ \n" " gl_Position = matrix * a_position; \n" " v_texCoord = a_texCoord; \n" "} \n"; char scrollFragmentShaderString[] = "precision mediump float; \n" "varying vec2 v_texCoord; \n" "uniform sampler2D s_texture; \n" "void main() \n" "{ \n" " vec4 texColor = texture2D(s_texture, v_texCoord); \n" " gl_FragColor = vec4(texColor.x, texColor.y, texColor.z, texColor.w); \n" "} \n"; m_scrollShaderProgram = LayerChromium::createShaderProgram(scrollVertexShaderString, scrollFragmentShaderString); if (!m_scrollShaderProgram) { LOG_ERROR("LayerRendererChromium: Failed to create scroll shader program"); cleanupSharedObjects(); return false; } GLC(m_scrollShaderSamplerLocation = glGetUniformLocation(m_scrollShaderProgram, "s_texture")); GLC(m_scrollShaderMatrixLocation = glGetUniformLocation(m_scrollShaderProgram, "matrix")); if (m_scrollShaderSamplerLocation == -1 || m_scrollShaderMatrixLocation == -1) { LOG_ERROR("Failed to initialize scroll shader."); cleanupSharedObjects(); return false; } // Create a texture object to hold the contents of the root layer. m_rootLayerTextureId = createLayerTexture(); if (!m_rootLayerTextureId) { LOG_ERROR("Failed to create texture for root layer"); cleanupSharedObjects(); return false; } // Turn off filtering for the root layer to avoid blurring from the repeated // writes and reads to the framebuffer that happen while scrolling. GLC(glBindTexture(GL_TEXTURE_2D, m_rootLayerTextureId)); GLC(glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)); GLC(glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)); // Get the max texture size supported by the system. GLC(glGetIntegerv(GL_MAX_TEXTURE_SIZE, &m_maxTextureSize)); // Get the number of bits available in the stencil buffer. GLC(glGetIntegerv(GL_STENCIL_BITS, &m_numStencilBits)); m_layerSharedValues = adoptPtr(new LayerChromium::SharedValues()); m_contentLayerSharedValues = adoptPtr(new ContentLayerChromium::SharedValues()); m_canvasLayerSharedValues = adoptPtr(new CanvasLayerChromium::SharedValues()); if (!m_layerSharedValues->initialized() || !m_contentLayerSharedValues->initialized() || !m_canvasLayerSharedValues->initialized()) { cleanupSharedObjects(); return false; } return true; }
LayerRendererChromium::~LayerRendererChromium() { m_headsUpDisplay.clear(); // Explicitly destroy the HUD before the TextureManager dies. cleanupSharedObjects(); }