HighPerformanceGPUManager.cpp [plain text]
#include "config.h"
#include "HighPerformanceGPUManager.h"
#if PLATFORM(MAC)
#include "Logging.h"
#include <OpenGL/CGLTypes.h>
#include <OpenGL/OpenGL.h>
#include <WebCore/GraphicsContext3DManager.h>
namespace WebKit {
HighPerformanceGPUManager& HighPerformanceGPUManager::singleton()
{
static NeverDestroyed<HighPerformanceGPUManager> sharedManager;
return sharedManager;
}
void HighPerformanceGPUManager::addProcessRequiringHighPerformance(WebProcessProxy* process)
{
if (!WebCore::hasLowAndHighPowerGPUs())
return;
if (m_processesRequiringHighPerformance.add(process)) {
LOG(WebGL, "HighPerformanceGPUManager::addProcessRequiringHighPerformance() - adding process %p", process);
updateState();
return;
}
LOG(WebGL, "HighPerformanceGPUManager::addProcessRequiringHighPerformance() - process %p was already requesting high performance", process);
}
void HighPerformanceGPUManager::removeProcessRequiringHighPerformance(WebProcessProxy* process)
{
if (!WebCore::hasLowAndHighPowerGPUs())
return;
if (m_processesRequiringHighPerformance.remove(process)) {
LOG(WebGL, "HighPerformanceGPUManager::removeProcessRequiringHighPerformance() - removing process %p", process);
updateState();
return;
}
LOG(WebGL, "HighPerformanceGPUManager::removeProcessRequiringHighPerformance() - process %p was not requesting high performance", process);
}
void HighPerformanceGPUManager::updateState()
{
if (m_processesRequiringHighPerformance.size()) {
if (!m_pixelFormatObj) {
LOG(WebGL, "HighPerformanceGPUManager - turning on high-performance GPU.");
CGLPixelFormatAttribute attributes[] = { kCGLPFAAccelerated, kCGLPFAColorSize, static_cast<CGLPixelFormatAttribute>(32), static_cast<CGLPixelFormatAttribute>(0) };
GLint numPixelFormats = 0;
CGLChoosePixelFormat(attributes, &m_pixelFormatObj, &numPixelFormats);
LOG(WebGL, "HighPerformanceGPUManager - CGLPixelFormatObj is %p", m_pixelFormatObj);
}
} else if (m_pixelFormatObj) {
LOG(WebGL, "HighPerformanceGPUManager - turning off high-performance GPU.");
CGLReleasePixelFormat(m_pixelFormatObj);
m_pixelFormatObj = nullptr;
}
}
}
#endif