blob: d142e01fb13a567d945674d6a5980d97636d8c54 (
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
103
104
105
106
107
108
109
110
111
112
113
114
|
// 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 "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());
// Virtual contexts obviously can't make a context that is compatible
// with the surface (the context already exists), but we do need to
// make a context current for SetupForVirtualization() below.
if (!IsCurrent(compatible_surface)) {
if (!shared_context_->MakeCurrent(compatible_surface)) {
// This is likely an error. The real context should be made as
// compatible with all required surfaces when it was created.
LOG(ERROR) << "Failed MakeCurrent(compatible_surface)";
return false;
}
}
shared_context_->SetupForVirtualization();
return true;
}
void GLContextVirtual::Destroy() {
shared_context_->OnDestroyVirtualContext(this);
shared_context_ = NULL;
display_ = NULL;
}
bool GLContextVirtual::MakeCurrent(gfx::GLSurface* surface) {
if (decoder_.get() && decoder_->initialized())
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) {
// If it's a real surface it needs to be current.
if (surface &&
!surface->GetBackingFrameBufferObject() &&
!surface->IsOffscreen())
return shared_context_->IsCurrent(surface);
// Otherwise, only insure the context itself is current.
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() {
// TODO(ccameron): This will not work if two contexts that disagree
// about whether or not forced gpu switching may be done both share
// the same underlying shared_context_.
return shared_context_->SetSafeToForceGpuSwitch();
}
bool GLContextVirtual::WasAllocatedUsingRobustnessExtension() {
return shared_context_->WasAllocatedUsingRobustnessExtension();
}
void GLContextVirtual::SetUnbindFboOnMakeCurrent() {
shared_context_->SetUnbindFboOnMakeCurrent();
}
GLContextVirtual::~GLContextVirtual() {
Destroy();
}
} // namespace gpu
|