|
Lines 22-27
a/Source/WebCore/platform/graphics/egl/GLContext.cpp_sec1
|
| 22 |
#if USE(EGL) |
22 |
#if USE(EGL) |
| 23 |
#include "GraphicsContextGL.h" |
23 |
#include "GraphicsContextGL.h" |
| 24 |
#include "Logging.h" |
24 |
#include "Logging.h" |
|
|
25 |
#include <wtf/ThreadSpecific.h> |
| 25 |
#include <wtf/Vector.h> |
26 |
#include <wtf/Vector.h> |
| 26 |
#include <wtf/text/StringToIntegerConversion.h> |
27 |
#include <wtf/text/StringToIntegerConversion.h> |
| 27 |
|
28 |
|
|
Lines 37-42
a/Source/WebCore/platform/graphics/egl/GLContext.cpp_sec2
|
| 37 |
|
38 |
|
| 38 |
namespace WebCore { |
39 |
namespace WebCore { |
| 39 |
|
40 |
|
|
|
41 |
static ThreadSpecific<GLContext*>& currentContext() |
| 42 |
{ |
| 43 |
static ThreadSpecific<GLContext*>* context; |
| 44 |
static std::once_flag flag; |
| 45 |
std::call_once(flag, [] { |
| 46 |
context = new ThreadSpecific<GLContext*>(); |
| 47 |
}); |
| 48 |
return *context; |
| 49 |
} |
| 50 |
|
| 40 |
const char* GLContext::errorString(int statusCode) |
51 |
const char* GLContext::errorString(int statusCode) |
| 41 |
{ |
52 |
{ |
| 42 |
static_assert(sizeof(int) >= sizeof(EGLint), "EGLint must not be wider than int"); |
53 |
static_assert(sizeof(int) >= sizeof(EGLint), "EGLint must not be wider than int"); |
|
Lines 398-403
GLContext::~GLContext()
a/Source/WebCore/platform/graphics/egl/GLContext.cpp_sec3
|
| 398 |
#if USE(WPE_RENDERER) |
409 |
#if USE(WPE_RENDERER) |
| 399 |
destroyWPETarget(); |
410 |
destroyWPETarget(); |
| 400 |
#endif |
411 |
#endif |
|
|
412 |
|
| 413 |
if (this == *currentContext()) |
| 414 |
*currentContext() = nullptr; |
| 401 |
} |
415 |
} |
| 402 |
|
416 |
|
| 403 |
EGLContext GLContext::createContextForEGLVersion(PlatformDisplay& platformDisplay, EGLConfig config, EGLContext sharingContext) |
417 |
EGLContext GLContext::createContextForEGLVersion(PlatformDisplay& platformDisplay, EGLConfig config, EGLContext sharingContext) |
|
Lines 416-448
EGLContext GLContext::createContextForEGLVersion(PlatformDisplay& platformDispla
a/Source/WebCore/platform/graphics/egl/GLContext.cpp_sec4
|
| 416 |
return eglCreateContext(platformDisplay.eglDisplay(), config, sharingContext, contextAttributes); |
430 |
return eglCreateContext(platformDisplay.eglDisplay(), config, sharingContext, contextAttributes); |
| 417 |
} |
431 |
} |
| 418 |
|
432 |
|
| 419 |
bool GLContext::makeCurrentImpl() |
433 |
bool GLContext::makeContextCurrent() |
| 420 |
{ |
434 |
{ |
| 421 |
ASSERT(m_context); |
435 |
ASSERT(m_context); |
| 422 |
return eglMakeCurrent(m_display.eglDisplay(), m_surface, m_surface, m_context); |
|
|
| 423 |
} |
| 424 |
|
436 |
|
| 425 |
bool GLContext::unmakeCurrentImpl() |
437 |
*currentContext() = this; |
| 426 |
{ |
438 |
if (eglGetCurrentContext() == m_context) |
| 427 |
return eglMakeCurrent(m_display.eglDisplay(), EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); |
439 |
return true; |
| 428 |
} |
|
|
| 429 |
|
440 |
|
| 430 |
bool GLContext::makeContextCurrent() |
441 |
return eglMakeCurrent(m_display.eglDisplay(), m_surface, m_surface, m_context); |
| 431 |
{ |
|
|
| 432 |
return makeCurrent(); |
| 433 |
} |
442 |
} |
| 434 |
|
443 |
|
| 435 |
bool GLContext::unmakeContextCurrent() |
444 |
bool GLContext::unmakeContextCurrent() |
| 436 |
{ |
445 |
{ |
| 437 |
return unmakeCurrent(); |
446 |
if (this != *currentContext()) |
|
|
447 |
return false; |
| 448 |
|
| 449 |
eglMakeCurrent(m_display.eglDisplay(), EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); |
| 450 |
*currentContext() = nullptr; |
| 451 |
|
| 452 |
return true; |
| 438 |
} |
453 |
} |
| 439 |
|
454 |
|
| 440 |
GLContext* GLContext::current() |
455 |
GLContext* GLContext::current() |
| 441 |
{ |
456 |
{ |
| 442 |
auto* context = currentContext(); |
457 |
return *currentContext(); |
| 443 |
if (context && context->type() == GLContextWrapper::Type::Native) |
|
|
| 444 |
return static_cast<GLContext*>(context); |
| 445 |
return nullptr; |
| 446 |
} |
458 |
} |
| 447 |
|
459 |
|
| 448 |
void GLContext::swapBuffers() |
460 |
void GLContext::swapBuffers() |
|
Lines 515-529
const GLContext::GLExtensions& GLContext::glExtensions() const
a/Source/WebCore/platform/graphics/egl/GLContext.cpp_sec5
|
| 515 |
GLContext::ScopedGLContext::ScopedGLContext(std::unique_ptr<GLContext>&& context) |
527 |
GLContext::ScopedGLContext::ScopedGLContext(std::unique_ptr<GLContext>&& context) |
| 516 |
: m_context(WTFMove(context)) |
528 |
: m_context(WTFMove(context)) |
| 517 |
{ |
529 |
{ |
| 518 |
auto eglContext = eglGetCurrentContext(); |
530 |
m_previous.context = eglGetCurrentContext(); |
| 519 |
m_previous.glContext = GLContext::current(); |
531 |
if (m_previous.context) { |
| 520 |
if (!m_previous.glContext || m_previous.glContext->platformContext() != eglContext) { |
532 |
m_previous.display = eglGetCurrentDisplay(); |
| 521 |
m_previous.context = eglContext; |
533 |
m_previous.readSurface = eglGetCurrentSurface(EGL_READ); |
| 522 |
if (m_previous.context != EGL_NO_CONTEXT) { |
534 |
m_previous.drawSurface = eglGetCurrentSurface(EGL_DRAW); |
| 523 |
m_previous.display = eglGetCurrentDisplay(); |
|
|
| 524 |
m_previous.readSurface = eglGetCurrentSurface(EGL_READ); |
| 525 |
m_previous.drawSurface = eglGetCurrentSurface(EGL_DRAW); |
| 526 |
} |
| 527 |
} |
535 |
} |
| 528 |
m_context->makeContextCurrent(); |
536 |
m_context->makeContextCurrent(); |
| 529 |
} |
537 |
} |
|
Lines 531-555
GLContext::ScopedGLContext::ScopedGLContext(std::unique_ptr<GLContext>&& context
a/Source/WebCore/platform/graphics/egl/GLContext.cpp_sec6
|
| 531 |
GLContext::ScopedGLContext::~ScopedGLContext() |
539 |
GLContext::ScopedGLContext::~ScopedGLContext() |
| 532 |
{ |
540 |
{ |
| 533 |
m_context = nullptr; |
541 |
m_context = nullptr; |
| 534 |
|
542 |
if (m_previous.context) |
| 535 |
if (m_previous.context != EGL_NO_CONTEXT) |
|
|
| 536 |
eglMakeCurrent(m_previous.display, m_previous.drawSurface, m_previous.readSurface, m_previous.context); |
543 |
eglMakeCurrent(m_previous.display, m_previous.drawSurface, m_previous.readSurface, m_previous.context); |
| 537 |
else if (m_previous.glContext) |
|
|
| 538 |
m_previous.glContext->makeContextCurrent(); |
| 539 |
} |
544 |
} |
| 540 |
|
545 |
|
| 541 |
GLContext::ScopedGLContextCurrent::ScopedGLContextCurrent(GLContext& context) |
546 |
GLContext::ScopedGLContextCurrent::ScopedGLContextCurrent(GLContext& context) |
| 542 |
: m_context(context) |
547 |
: m_context(context) |
| 543 |
{ |
548 |
{ |
| 544 |
auto eglContext = eglGetCurrentContext(); |
549 |
auto eglContext = eglGetCurrentContext(); |
| 545 |
m_previous.glContext = GLContext::current(); |
550 |
m_previous.glContext = *currentContext(); |
| 546 |
if (!m_previous.glContext || m_previous.glContext->platformContext() != eglContext) { |
551 |
if (!m_previous.glContext || m_previous.glContext->platformContext() != eglContext) { |
| 547 |
m_previous.context = eglContext; |
552 |
m_previous.context = eglContext; |
| 548 |
if (m_previous.context != EGL_NO_CONTEXT) { |
553 |
m_previous.display = eglGetCurrentDisplay(); |
| 549 |
m_previous.display = eglGetCurrentDisplay(); |
554 |
m_previous.readSurface = eglGetCurrentSurface(EGL_READ); |
| 550 |
m_previous.readSurface = eglGetCurrentSurface(EGL_READ); |
555 |
m_previous.drawSurface = eglGetCurrentSurface(EGL_DRAW); |
| 551 |
m_previous.drawSurface = eglGetCurrentSurface(EGL_DRAW); |
|
|
| 552 |
} |
| 553 |
} |
556 |
} |
| 554 |
m_context.makeContextCurrent(); |
557 |
m_context.makeContextCurrent(); |
| 555 |
} |
558 |
} |
|
Lines 561-570
GLContext::ScopedGLContextCurrent::~ScopedGLContextCurrent()
a/Source/WebCore/platform/graphics/egl/GLContext.cpp_sec7
|
| 561 |
return; |
564 |
return; |
| 562 |
} |
565 |
} |
| 563 |
|
566 |
|
| 564 |
m_context.unmakeContextCurrent(); |
|
|
| 565 |
|
| 566 |
if (m_previous.context) |
567 |
if (m_previous.context) |
| 567 |
eglMakeCurrent(m_previous.display, m_previous.drawSurface, m_previous.readSurface, m_previous.context); |
568 |
eglMakeCurrent(m_previous.display, m_previous.drawSurface, m_previous.readSurface, m_previous.context); |
|
|
569 |
else |
| 570 |
m_context.unmakeContextCurrent(); |
| 571 |
|
| 572 |
*currentContext() = m_previous.glContext; |
| 568 |
} |
573 |
} |
| 569 |
|
574 |
|
| 570 |
} // namespace WebCore |
575 |
} // namespace WebCore |