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

Side by Side Diff: gpu/pgl/pgl.cc

Issue 552007: Resubmitting r36268 with a fix for mac:... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 11 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/pgl/pgl.h ('k') | webkit/tools/pepper_test_plugin/DEPS » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 // Copyright (c) 2010 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/command_buffer/client/gles2_cmd_helper.h"
6 #include "gpu/command_buffer/client/gles2_implementation.h"
7 #include "gpu/command_buffer/client/gles2_lib.h"
8 #include "gpu/pgl/command_buffer_pepper.h"
9 #include "gpu/pgl/pgl.h"
10
11 #if defined(_MSC_VER)
12 #define THREAD_LOCAL __declspec(thread)
13 #else
14 #define THREAD_LOCAL __thread
15 #endif
16
17 namespace {
18 const int32 kTransferBufferSize = 512 * 1024;
19
20 class PGLContextImpl {
21 public:
22 PGLContextImpl(NPP npp,
23 NPDevice* device,
24 NPDeviceContext3D* device_context);
25 ~PGLContextImpl();
26
27 // Initlaize a PGL context with a transfer buffer of a particular size.
28 bool Initialize(int32 transfer_buffer_size);
29
30 // Destroy all resources associated with the PGL context.
31 void Destroy();
32
33 // Make a PGL context current for the calling thread.
34 static bool MakeCurrent(PGLContextImpl* pgl_context);
35
36 // Display all content rendered since last call to SwapBuffers.
37 bool SwapBuffers();
38
39 private:
40 PGLContextImpl(const PGLContextImpl&);
41 void operator=(const PGLContextImpl&);
42
43 NPP npp_;
44 NPDevice* device_;
45 NPDeviceContext3D* device_context_;
46 CommandBufferPepper* command_buffer_;
47 gpu::gles2::GLES2CmdHelper* gles2_helper_;
48 int32 transfer_buffer_id_;
49 gpu::gles2::GLES2Implementation* gles2_implementation_;
50 };
51
52 THREAD_LOCAL PGLContextImpl* g_current_pgl_context;
53
54 PGLContextImpl::PGLContextImpl(NPP npp,
55 NPDevice* device,
56 NPDeviceContext3D* device_context)
57 : npp_(npp),
58 device_(device),
59 device_context_(device_context),
60 command_buffer_(NULL),
61 gles2_helper_(NULL),
62 transfer_buffer_id_(0),
63 gles2_implementation_(NULL) {
64 }
65
66 PGLContextImpl::~PGLContextImpl() {
67 Destroy();
68 }
69
70 bool PGLContextImpl::Initialize(int32 transfer_buffer_size) {
71 // Create and initialize the objects required to issue GLES2 calls.
72 command_buffer_ = new CommandBufferPepper(
73 npp_, device_, device_context_);
74 gles2_helper_ = new gpu::gles2::GLES2CmdHelper(command_buffer_);
75 if (gles2_helper_->Initialize()) {
76 transfer_buffer_id_ =
77 command_buffer_->CreateTransferBuffer(kTransferBufferSize);
78 gpu::Buffer transfer_buffer =
79 command_buffer_->GetTransferBuffer(transfer_buffer_id_);
80 if (transfer_buffer.ptr) {
81 gles2_implementation_ = new gpu::gles2::GLES2Implementation(
82 gles2_helper_,
83 transfer_buffer.size,
84 transfer_buffer.ptr,
85 transfer_buffer_id_);
86 return true;
87 }
88 }
89
90 // Tear everything down if initialization failed.
91 Destroy();
92 return false;
93 }
94
95 void PGLContextImpl::Destroy() {
96 delete gles2_implementation_;
97 gles2_implementation_ = NULL;
98
99 if (command_buffer_ && transfer_buffer_id_ != 0) {
100 command_buffer_->DestroyTransferBuffer(transfer_buffer_id_);
101 transfer_buffer_id_ = 0;
102 }
103
104 delete gles2_helper_;
105 gles2_helper_ = NULL;
106
107 delete command_buffer_;
108 command_buffer_ = NULL;
109 }
110
111 bool PGLContextImpl::MakeCurrent(PGLContextImpl* pgl_context) {
112 g_current_pgl_context = pgl_context;
113 if (pgl_context)
114 gles2::g_gl_impl = pgl_context->gles2_implementation_;
115 else
116 gles2::g_gl_impl = NULL;
117
118 return true;
119 }
120
121 bool PGLContextImpl::SwapBuffers() {
122 gles2_implementation_->SwapBuffers();
123 return true;
124 }
125 } // namespace anonymous
126
127 extern "C" {
128
129 PGLContext pglCreateContext(NPP npp,
130 NPDevice* device,
131 NPDeviceContext3D* device_context) {
132 PGLContextImpl* pgl_context = new PGLContextImpl(
133 npp, device, device_context);
134 if (pgl_context->Initialize(kTransferBufferSize)) {
135 return pgl_context;
136 }
137
138 delete pgl_context;
139 return NULL;
140 }
141
142 PGLBoolean pglMakeCurrent(PGLContext pgl_context) {
143 return PGLContextImpl::MakeCurrent(static_cast<PGLContextImpl*>(pgl_context));
144 }
145
146 PGLBoolean pglSwapBuffers() {
147 if (!g_current_pgl_context)
148 return false;
149
150 return g_current_pgl_context->SwapBuffers();
151 }
152
153 PGLBoolean pglDestroyContext(PGLContext pgl_context) {
154 if (!pgl_context)
155 return false;
156
157 delete pgl_context;
158 return true;
159 }
160
161 } // extern "C"
OLDNEW
« no previous file with comments | « gpu/pgl/pgl.h ('k') | webkit/tools/pepper_test_plugin/DEPS » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698