blob: 63550d6a061d44a363c732cdb909efbf63318063 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "gpu/command_buffer/service/gl_context_virtual.h"
#include "gpu/command_buffer/service/gl_state_restorer_impl.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),
state_restorer_(new GLStateRestorerImpl(decoder)),
decoder_(decoder) {
}
gfx::Display* GLContextVirtual::display() {
return display_;
}
bool GLContextVirtual::Initialize(
gfx::GLSurface* compatible_surface, gfx::GpuPreference gpu_preference) {
display_ = static_cast<gfx::Display*>(compatible_surface->GetDisplay());
if (!shared_context_->MakeCurrent(compatible_surface))
return false;
shared_context_->SetupForVirtualization();
shared_context_->ReleaseCurrent(compatible_surface);
return true;
}
void GLContextVirtual::Destroy() {
shared_context_->OnDestroyVirtualContext(this);
shared_context_ = NULL;
display_ = NULL;
}
bool GLContextVirtual::MakeCurrent(gfx::GLSurface* surface) {
if (decoder_.get())
shared_context_->MakeVirtuallyCurrent(this, surface);
else
shared_context_->MakeCurrent(surface);
return true;
}
void GLContextVirtual::ReleaseCurrent(gfx::GLSurface* surface) {
if (IsCurrent(surface))
shared_context_->ReleaseCurrent(surface);
}
bool GLContextVirtual::IsCurrent(gfx::GLSurface* surface) {
bool context_current = shared_context_->IsCurrent(NULL);
if (!context_current)
return false;
if (!surface)
return true;
gfx::GLSurface* current_surface = gfx::GLSurface::GetCurrent();
return surface->GetBackingFrameBufferObject() ||
surface->IsOffscreen() ||
(current_surface &&
current_surface->GetHandle() == surface->GetHandle());
}
void* GLContextVirtual::GetHandle() {
return NULL;
}
gfx::GLStateRestorer* GLContextVirtual::GetGLStateRestorer() {
return state_restorer_.get();
}
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);
}
bool GLContextVirtual::WasAllocatedUsingRobustnessExtension() {
return shared_context_->WasAllocatedUsingRobustnessExtension();
}
GLContextVirtual::~GLContextVirtual() {
Destroy();
}
} // namespace gpu
|