本文整理汇总了C++中GLContext::makeContextCurrent方法的典型用法代码示例。如果您正苦于以下问题:C++ GLContext::makeContextCurrent方法的具体用法?C++ GLContext::makeContextCurrent怎么用?C++ GLContext::makeContextCurrent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GLContext
的用法示例。
在下文中一共展示了GLContext::makeContextCurrent方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: flushAndRenderLayers
void LayerTreeHostGtk::flushAndRenderLayers()
{
{
RefPtr<LayerTreeHostGtk> protect(this);
m_webPage->layoutIfNeeded();
if (!m_isValid)
return;
}
GLContext* context = glContext();
if (!context || !context->makeContextCurrent())
return;
m_lastFlushTime = currentTime();
if (!flushPendingLayerChanges())
return;
// Our model is very simple. We always composite and render the tree immediately after updating it.
compositeLayersToContext();
if (m_notifyAfterScheduledLayerFlush) {
// Let the drawing area know that we've done a flush of the layer changes.
static_cast<DrawingAreaImpl*>(m_webPage->drawingArea())->layerHostDidFlushLayers();
m_notifyAfterScheduledLayerFlush = false;
}
}
示例2: swapBuffersIfNeeded
void ImageBufferData::swapBuffersIfNeeded()
{
if (!m_bufferChanged)
return;
GLContext* previousActiveContext = GLContext::getCurrent();
cairo_surface_flush(m_surface.get());
if (!m_compositorTexture) {
createCompositorBuffer();
LockHolder holder(m_platformLayerProxy->lock());
m_platformLayerProxy->pushNextBuffer(std::make_unique<TextureMapperPlatformLayerBuffer>(m_compositorTexture, m_size, TextureMapperGL::ShouldBlend));
}
// It would be great if we could just swap the buffers here as we do with webgl, but that breaks the cases
// where one frame uses the content already rendered in the previous frame. So we just copy the content
// into the compositor buffer.
cairo_set_source_surface(m_compositorCr.get(), m_surface.get(), 0, 0);
cairo_set_operator(m_compositorCr.get(), CAIRO_OPERATOR_SOURCE);
cairo_paint(m_compositorCr.get());
m_bufferChanged = false;
if (previousActiveContext)
previousActiveContext->makeContextCurrent();
}
示例3: paintToTextureMapper
void ImageBufferData::paintToTextureMapper(TextureMapper& textureMapper, const FloatRect& targetRect, const TransformationMatrix& matrix, float opacity)
{
ASSERT(m_texture);
// Cairo may change the active context, so we make sure to change it back after flushing.
GLContext* previousActiveContext = GLContext::current();
cairo_surface_flush(m_surface.get());
previousActiveContext->makeContextCurrent();
static_cast<TextureMapperGL&>(textureMapper).drawTexture(m_texture, TextureMapperGL::ShouldBlend, m_size, targetRect, matrix, opacity);
}
示例4:
Extensions3DCache::Extensions3DCache()
{
GLContext* previousActiveContext = GLContext::getCurrent();
if (!previousActiveContext)
GLContext::sharingContext()->makeContextCurrent();
RefPtr<GraphicsContext3D> context3D = GraphicsContext3D::createForCurrentGLContext();
m_GL_EXT_unpack_subimage = context3D->getExtensions()->supports("GL_EXT_unpack_subimage");
context3D.release();
if (previousActiveContext)
previousActiveContext->makeContextCurrent();
}
示例5: initialize
void LayerTreeHostGtk::initialize()
{
m_rootLayer = GraphicsLayer::create(graphicsLayerFactory(), this);
m_rootLayer->setDrawsContent(false);
m_rootLayer->setSize(m_webPage->size());
// The non-composited contents are a child of the root layer.
m_nonCompositedContentLayer = GraphicsLayer::create(graphicsLayerFactory(), this);
m_nonCompositedContentLayer->setDrawsContent(true);
m_nonCompositedContentLayer->setContentsOpaque(m_webPage->drawsBackground() && !m_webPage->drawsTransparentBackground());
m_nonCompositedContentLayer->setSize(m_webPage->size());
if (m_webPage->corePage()->settings()->acceleratedDrawingEnabled())
m_nonCompositedContentLayer->setAcceleratesDrawing(true);
#ifndef NDEBUG
m_rootLayer->setName("LayerTreeHost root layer");
m_nonCompositedContentLayer->setName("LayerTreeHost non-composited content");
#endif
m_rootLayer->addChild(m_nonCompositedContentLayer.get());
m_nonCompositedContentLayer->setNeedsDisplay();
m_layerTreeContext.windowHandle = m_webPage->nativeWindowHandle();
GLContext* context = glContext();
if (!context) {
m_isValid = false;
return;
}
// The creation of the TextureMapper needs an active OpenGL context.
context->makeContextCurrent();
m_textureMapper = TextureMapperGL::create();
static_cast<TextureMapperGL*>(m_textureMapper.get())->setEnableEdgeDistanceAntialiasing(true);
toTextureMapperLayer(m_rootLayer.get())->setTextureMapper(m_textureMapper.get());
if (m_webPage->hasPageOverlay()) {
PageOverlayList& pageOverlays = m_webPage->pageOverlays();
PageOverlayList::iterator end = pageOverlays.end();
for (PageOverlayList::iterator it = pageOverlays.begin(); it != end; ++it)
createPageOverlayLayer(it->get());
}
scheduleLayerFlush();
}
示例6: initialize
void LayerTreeHostGtk::initialize()
{
m_rootLayer = GraphicsLayer::create(graphicsLayerFactory(), *this);
m_rootLayer->setDrawsContent(false);
m_rootLayer->setSize(m_webPage->size());
// The non-composited contents are a child of the root layer.
m_nonCompositedContentLayer = GraphicsLayer::create(graphicsLayerFactory(), *this);
m_nonCompositedContentLayer->setDrawsContent(true);
m_nonCompositedContentLayer->setContentsOpaque(m_webPage->drawsBackground() && !m_webPage->drawsTransparentBackground());
m_nonCompositedContentLayer->setSize(m_webPage->size());
if (m_webPage->corePage()->settings().acceleratedDrawingEnabled())
m_nonCompositedContentLayer->setAcceleratesDrawing(true);
#ifndef NDEBUG
m_rootLayer->setName("LayerTreeHost root layer");
m_nonCompositedContentLayer->setName("LayerTreeHost non-composited content");
#endif
m_rootLayer->addChild(m_nonCompositedContentLayer.get());
m_nonCompositedContentLayer->setNeedsDisplay();
m_layerTreeContext.contextID = m_webPage->nativeWindowHandle();
GLContext* context = glContext();
if (!context)
return;
// The creation of the TextureMapper needs an active OpenGL context.
context->makeContextCurrent();
m_textureMapper = TextureMapper::create(TextureMapper::OpenGLMode);
static_cast<TextureMapperGL*>(m_textureMapper.get())->setEnableEdgeDistanceAntialiasing(true);
toTextureMapperLayer(m_rootLayer.get())->setTextureMapper(m_textureMapper.get());
// FIXME: Cretae page olverlay layers. https://bugs.webkit.org/show_bug.cgi?id=131433.
scheduleLayerFlush();
}
示例7: textureSize
void GraphicsContext3DPrivate::paintToTextureMapper(TextureMapper* textureMapper, const FloatRect& targetRect, const TransformationMatrix& matrix, float opacity)
{
if (!m_glContext)
return;
ASSERT(m_renderStyle == GraphicsContext3D::RenderOffscreen);
m_context->markLayerComposited();
// FIXME: We do not support mask for the moment with TextureMapperImageBuffer.
if (textureMapper->accelerationMode() != TextureMapper::OpenGLMode) {
GraphicsContext* context = textureMapper->graphicsContext();
context->save();
context->platformContext()->setGlobalAlpha(opacity);
const int height = m_context->m_currentHeight;
const int width = m_context->m_currentWidth;
int totalBytes = width * height * 4;
auto pixels = std::make_unique<unsigned char[]>(totalBytes);
if (!pixels)
return;
// OpenGL keeps the pixels stored bottom up, so we need to flip the image here.
context->translate(0, height);
context->scale(FloatSize(1, -1));
context->concatCTM(matrix.toAffineTransform());
m_context->readRenderingResults(pixels.get(), totalBytes);
// Premultiply alpha.
for (int i = 0; i < totalBytes; i += 4)
if (pixels[i + 3] != 255) {
pixels[i + 0] = min(255, pixels[i + 0] * pixels[i + 3] / 255);
pixels[i + 1] = min(255, pixels[i + 1] * pixels[i + 3] / 255);
pixels[i + 2] = min(255, pixels[i + 2] * pixels[i + 3] / 255);
}
RefPtr<cairo_surface_t> imageSurface = adoptRef(cairo_image_surface_create_for_data(
const_cast<unsigned char*>(pixels.get()), CAIRO_FORMAT_ARGB32, width, height, width * 4));
context->platformContext()->drawSurfaceToContext(imageSurface.get(), targetRect, IntRect(0, 0, width, height), context);
context->restore();
return;
}
#if USE(TEXTURE_MAPPER_GL)
if (m_context->m_attrs.antialias && m_context->m_state.boundFBO == m_context->m_multisampleFBO) {
GLContext* previousActiveContext = GLContext::getCurrent();
if (previousActiveContext != m_glContext)
m_context->makeContextCurrent();
m_context->resolveMultisamplingIfNecessary();
::glBindFramebuffer(GraphicsContext3D::FRAMEBUFFER, m_context->m_state.boundFBO);
if (previousActiveContext && previousActiveContext != m_glContext)
previousActiveContext->makeContextCurrent();
}
TextureMapperGL* texmapGL = static_cast<TextureMapperGL*>(textureMapper);
TextureMapperGL::Flags flags = TextureMapperGL::ShouldFlipTexture | (m_context->m_attrs.alpha ? TextureMapperGL::ShouldBlend : 0);
IntSize textureSize(m_context->m_currentWidth, m_context->m_currentHeight);
texmapGL->drawTexture(m_context->m_texture, flags, textureSize, targetRect, matrix, opacity);
#endif // USE(ACCELERATED_COMPOSITING_GL)
}