Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(732)

Side by Side Diff: gpu/gles2_conform_support/egl/display.cc

Issue 7057033: Move OpenGL ES 2.0 conformance test support into main tree (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fixes for osx Created 9 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « gpu/gles2_conform_support/egl/display.h ('k') | gpu/gles2_conform_support/egl/egl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "gpu/gles2_conform_support/egl/display.h"
6
7 #include <vector>
8 #include "gpu/command_buffer/client/gles2_lib.h"
9 #include "gpu/command_buffer/service/command_buffer_service.h"
10 #include "gpu/command_buffer/service/gles2_cmd_decoder.h"
11 #include "gpu/command_buffer/service/gpu_scheduler.h"
12 #include "gpu/GLES2/gles2_command_buffer.h"
13 #include "gpu/gles2_conform_support/egl/config.h"
14 #include "gpu/gles2_conform_support/egl/surface.h"
15
16 namespace {
17 const int32 kCommandBufferSize = 1024 * 1024;
18 const int32 kTransferBufferSize = 512 * 1024;
19 }
20
21 namespace egl {
22
23 Display::Display(EGLNativeDisplayType display_id)
24 : display_id_(display_id),
25 is_initialized_(false),
26 transfer_buffer_id_(-1) {
27 }
28
29 Display::~Display() {
30 gles2::Terminate();
31 }
32
33 bool Display::Initialize() {
34 using gpu::CommandBufferService;
35 scoped_ptr<CommandBufferService> command_buffer(new CommandBufferService);
36 if (!command_buffer->Initialize(kCommandBufferSize))
37 return false;
38
39 using gpu::Buffer;
40 int32 transfer_buffer_id =
41 command_buffer->CreateTransferBuffer(kTransferBufferSize, -1);
42 Buffer transfer_buffer =
43 command_buffer->GetTransferBuffer(transfer_buffer_id);
44 if (transfer_buffer.ptr == NULL)
45 return false;
46
47 using gpu::gles2::GLES2CmdHelper;
48 scoped_ptr<GLES2CmdHelper> cmd_helper(
49 new GLES2CmdHelper(command_buffer.get()));
50 if (!cmd_helper->Initialize(kCommandBufferSize))
51 return false;
52
53 gles2::Initialize();
54
55 is_initialized_ = true;
56 command_buffer_.reset(command_buffer.release());
57 transfer_buffer_id_ = transfer_buffer_id;
58 gles2_cmd_helper_.reset(cmd_helper.release());
59 return true;
60 }
61
62 bool Display::IsValidConfig(EGLConfig config) {
63 return (config != NULL) && (config == config_.get());
64 }
65
66 bool Display::GetConfigs(EGLConfig* configs,
67 EGLint config_size,
68 EGLint* num_config) {
69 // TODO(alokp): Find out a way to find all configs. CommandBuffer currently
70 // does not support finding or choosing configs.
71 *num_config = 1;
72 if (configs != NULL) {
73 if (config_ == NULL) {
74 config_.reset(new Config);
75 }
76 configs[0] = config_.get();
77 }
78 return true;
79 }
80
81 bool Display::GetConfigAttrib(EGLConfig config,
82 EGLint attribute,
83 EGLint* value) {
84 const egl::Config* cfg = static_cast<egl::Config*>(config);
85 return cfg->GetAttrib(attribute, value);
86 }
87
88 bool Display::IsValidNativeWindow(EGLNativeWindowType win) {
89 #if defined OS_WIN
90 return ::IsWindow(win) != FALSE;
91 #else
92 // TODO(alokp): Validate window handle.
93 return true;
94 #endif // OS_WIN
95 }
96
97 bool Display::IsValidSurface(EGLSurface surface) {
98 return (surface != NULL) && (surface == surface_.get());
99 }
100
101 EGLSurface Display::CreateWindowSurface(EGLConfig config,
102 EGLNativeWindowType win,
103 const EGLint* attrib_list) {
104 if (surface_ != NULL) {
105 // We do not support more than one window surface.
106 return EGL_NO_SURFACE;
107 }
108
109 using gpu::GpuScheduler;
110 std::vector<int32> attribs;
111 scoped_ptr<GpuScheduler> gpu_scheduler(
112 new GpuScheduler(command_buffer_.get(), NULL));
113 if (!gpu_scheduler->Initialize(
114 win, gfx::Size(), gpu::gles2::DisallowedExtensions(), NULL,
115 attribs, NULL, 0))
116 return EGL_NO_SURFACE;
117
118 command_buffer_->SetPutOffsetChangeCallback(
119 NewCallback(gpu_scheduler.get(), &GpuScheduler::PutChanged));
120 gpu_scheduler_.reset(gpu_scheduler.release());
121 surface_.reset(new Surface(win));
122
123 return surface_.get();
124 }
125
126 void Display::DestroySurface(EGLSurface surface) {
127 DCHECK(IsValidSurface(surface));
128 gpu_scheduler_.reset();
129 surface_.reset();
130 }
131
132 void Display::SwapBuffers(EGLSurface surface) {
133 DCHECK(IsValidSurface(surface));
134 context_->SwapBuffers();
135 }
136
137 bool Display::IsValidContext(EGLContext ctx) {
138 return (ctx != NULL) && (ctx == context_.get());
139 }
140
141 EGLContext Display::CreateContext(EGLConfig config,
142 EGLContext share_ctx,
143 const EGLint* attrib_list) {
144 DCHECK(IsValidConfig(config));
145 // TODO(alokp): Command buffer does not support shared contexts.
146 if (share_ctx != NULL)
147 return EGL_NO_CONTEXT;
148
149 DCHECK(command_buffer_ != NULL);
150 DCHECK(transfer_buffer_id_ != -1);
151 gpu::Buffer buffer = command_buffer_->GetTransferBuffer(transfer_buffer_id_);
152 DCHECK(buffer.ptr != NULL);
153 bool share_resources = share_ctx != NULL;
154 using gpu::gles2::GLES2Implementation;
155 context_.reset(new GLES2Implementation(
156 gles2_cmd_helper_.get(),
157 buffer.size,
158 buffer.ptr,
159 transfer_buffer_id_,
160 share_resources));
161
162 context_->CommandBufferEnableCHROMIUM(
163 PEPPER3D_ALLOW_BUFFERS_ON_MULTIPLE_TARGETS);
164 context_->CommandBufferEnableCHROMIUM(
165 PEPPER3D_SUPPORT_FIXED_ATTRIBS);
166
167 return context_.get();
168 }
169
170 void Display::DestroyContext(EGLContext ctx) {
171 DCHECK(IsValidContext(ctx));
172 context_.reset();
173 }
174
175 bool Display::MakeCurrent(EGLSurface draw, EGLSurface read, EGLContext ctx) {
176 if (ctx == EGL_NO_CONTEXT) {
177 gles2::SetGLContext(NULL);
178 } else {
179 DCHECK(IsValidSurface(draw));
180 DCHECK(IsValidSurface(read));
181 DCHECK(IsValidContext(ctx));
182 gles2::SetGLContext(context_.get());
183 }
184 return true;
185 }
186
187 } // namespace egl
OLDNEW
« no previous file with comments | « gpu/gles2_conform_support/egl/display.h ('k') | gpu/gles2_conform_support/egl/egl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698