This source file includes following definitions.
- decoder_
- display
- Initialize
- Destroy
- MakeCurrent
- ReleaseCurrent
- IsCurrent
- GetHandle
- SetSwapInterval
- GetExtensions
- GetTotalGpuMemory
- SetSafeToForceGpuSwitch
- WasAllocatedUsingRobustnessExtension
- SetUnbindFboOnMakeCurrent
#include "gpu/command_buffer/service/gl_context_virtual.h"
#include "gpu/command_buffer/service/gl_state_restorer_impl.h"
#include "gpu/command_buffer/service/gles2_cmd_decoder.h"
#include "ui/gl/gl_surface.h"
namespace gpu {
GLContextVirtual::GLContextVirtual(
gfx::GLShareGroup* share_group,
gfx::GLContext* shared_context,
base::WeakPtr<gles2::GLES2Decoder> decoder)
: GLContext(share_group),
shared_context_(shared_context),
display_(NULL),
decoder_(decoder) {
}
gfx::Display* GLContextVirtual::display() {
return display_;
}
bool GLContextVirtual::Initialize(
gfx::GLSurface* compatible_surface, gfx::GpuPreference gpu_preference) {
SetGLStateRestorer(new GLStateRestorerImpl(decoder_));
display_ = static_cast<gfx::Display*>(compatible_surface->GetDisplay());
if (!IsCurrent(compatible_surface)) {
if (!shared_context_->MakeCurrent(compatible_surface)) {
LOG(ERROR) << "Failed MakeCurrent(compatible_surface)";
return false;
}
}
shared_context_->SetupForVirtualization();
shared_context_->MakeVirtuallyCurrent(this, compatible_surface);
return true;
}
void GLContextVirtual::Destroy() {
shared_context_->OnReleaseVirtuallyCurrent(this);
shared_context_ = NULL;
display_ = NULL;
}
bool GLContextVirtual::MakeCurrent(gfx::GLSurface* surface) {
if (decoder_.get())
return shared_context_->MakeVirtuallyCurrent(this, surface);
LOG(ERROR) << "Trying to make virtual context current without decoder.";
return false;
}
void GLContextVirtual::ReleaseCurrent(gfx::GLSurface* surface) {
if (IsCurrent(surface)) {
shared_context_->OnReleaseVirtuallyCurrent(this);
shared_context_->ReleaseCurrent(surface);
}
}
bool GLContextVirtual::IsCurrent(gfx::GLSurface* surface) {
if (surface &&
!surface->IsOffscreen())
return shared_context_->IsCurrent(surface);
return shared_context_->IsCurrent(NULL);
}
void* GLContextVirtual::GetHandle() {
return shared_context_->GetHandle();
}
void GLContextVirtual::SetSwapInterval(int interval) {
shared_context_->SetSwapInterval(interval);
}
std::string GLContextVirtual::GetExtensions() {
return shared_context_->GetExtensions();
}
bool GLContextVirtual::GetTotalGpuMemory(size_t* bytes) {
return shared_context_->GetTotalGpuMemory(bytes);
}
void GLContextVirtual::SetSafeToForceGpuSwitch() {
return shared_context_->SetSafeToForceGpuSwitch();
}
bool GLContextVirtual::WasAllocatedUsingRobustnessExtension() {
return shared_context_->WasAllocatedUsingRobustnessExtension();
}
void GLContextVirtual::SetUnbindFboOnMakeCurrent() {
shared_context_->SetUnbindFboOnMakeCurrent();
}
GLContextVirtual::~GLContextVirtual() {
Destroy();
}
}