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

Side by Side Diff: webkit/plugins/ppapi/ppb_context_3d_impl.cc

Issue 6062003: Added ppapi::Context3D interface. The API has already been reviewed. I am add... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 12 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
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 "webkit/plugins/ppapi/ppb_context_3d_impl.h"
6
7 #include "gpu/command_buffer/common/command_buffer.h"
8 #include "ppapi/c/dev/ppb_graphics_3d_dev.h"
9 #include "webkit/plugins/ppapi/common.h"
10 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
11
12 namespace webkit {
13 namespace ppapi {
14
15 namespace {
16
17 // Size of the transfer buffer.
18 enum { kTransferBufferSize = 512 * 1024 };
19
20 PP_Resource Create(PP_Instance instance_id,
21 PP_Config3D_Dev config,
22 PP_Resource share_context,
23 const int32_t* attrib_list) {
24 // TODO(alokp): Support shared context.
25 DCHECK_EQ(0, share_context);
26 if (share_context != 0)
27 return 0;
28
29 PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id);
30 if (!instance)
31 return 0;
32
33 scoped_refptr<PPB_Context3D_Impl> context(
34 new PPB_Context3D_Impl(instance->module()));
35 if (!context->Init(instance, config, share_context, attrib_list)) {
brettw 2010/12/22 22:56:21 Remove {} for consistency.
alokp 2010/12/22 23:04:49 Done.
36 return 0;
37 }
38
39 return context->GetReference();
40 }
41
42 PP_Bool IsContext3D(PP_Resource resource) {
43 return BoolToPPBool(!!Resource::GetAs<PPB_Context3D_Impl>(resource));
44 }
45
46 int32_t GetAttrib(PP_Resource context,
47 int32_t attribute,
48 int32_t* value) {
49 // TODO(alokp): Implement me.
50 return 0;
51 }
52
53 int32_t BindSurfaces(PP_Resource context,
54 PP_Resource draw,
55 PP_Resource read) {
56 // TODO(alokp): Implement me.
57 return 0;
58 }
59
60 int32_t GetBoundSurfaces(PP_Resource context,
61 PP_Resource* draw,
62 PP_Resource* read) {
63 // TODO(alokp): Implement me.
64 return 0;
65 }
66
67 int32_t SwapBuffers(PP_Resource context_id,
68 PP_CompletionCallback callback) {
69 scoped_refptr<PPB_Context3D_Impl> context(
70 Resource::GetAs<PPB_Context3D_Impl>(context_id));
71 return context->SwapBuffers();
72 }
73
74 const PPB_Context3D_Dev ppb_context3d = {
75 &Create,
76 &IsContext3D,
77 &GetAttrib,
78 &BindSurfaces,
79 &GetBoundSurfaces,
80 &SwapBuffers
81 };
82
83 } // namespace
84
85 PPB_Context3D_Impl::PPB_Context3D_Impl(PluginModule* module)
86 : Resource(module),
87 bound_instance_(NULL),
88 gles2_impl_(NULL) {
89 }
90
91 PPB_Context3D_Impl::~PPB_Context3D_Impl() {
92 Destroy();
93 }
94
95 const PPB_Context3D_Dev* PPB_Context3D_Impl::GetInterface() {
96 return &ppb_context3d;
97 }
98
99 PPB_Context3D_Impl* PPB_Context3D_Impl::AsPPB_Context3D_Impl() {
100 return this;
101 }
102
103 bool PPB_Context3D_Impl::Init(PluginInstance* instance,
104 PP_Config3D_Dev config,
105 PP_Resource share_context,
106 const int32_t* attrib_list) {
107 DCHECK(instance);
108 // Create and initialize the objects required to issue GLES2 calls.
109 platform_context_.reset(instance->delegate()->CreateContext3D());
110 if (!platform_context_.get()) {
111 Destroy();
112 return false;
113 }
114 if (!platform_context_->Init()) {
115 Destroy();
116 return false;
117 }
118
119 gles2_impl_ = platform_context_->GetGLES2Implementation();
120 DCHECK(gles2_impl_);
121
122 return true;
123 }
124
125 bool PPB_Context3D_Impl::BindToInstance(PluginInstance* new_instance) {
126 if (bound_instance_ == new_instance)
brettw 2010/12/22 22:56:21 Is there a way we can ensure that the instance tha
alokp 2010/12/22 23:04:49 I will actually move this function to PPB_Surface3
127 return true; // Rebinding the same device, nothing to do.
128 if (bound_instance_ && new_instance)
129 return false; // Can't change a bound device.
130
131 if (new_instance) {
132 // Resize the backing texture to the size of the instance when it is bound.
133 platform_context_->ResizeBackingTexture(new_instance->position().size());
134
135 // This is a temporary hack. The SwapBuffers is issued to force the resize
136 // to take place before any subsequent rendering. This might lead to a
137 // partially rendered frame being displayed. It is also not thread safe
138 // since the SwapBuffers is written to the command buffer and that command
139 // buffer might be written to by another thread.
140 // TODO(apatrick): Figure out the semantics of binding and resizing.
141 platform_context_->SwapBuffers();
142 }
143
144 bound_instance_ = new_instance;
145 return true;
146 }
147
148 bool PPB_Context3D_Impl::SwapBuffers() {
149 if (!platform_context_.get())
150 return false;
151
152 return platform_context_->SwapBuffers();
153 }
154
155 void PPB_Context3D_Impl::SetSwapBuffersCallback(Callback0::Type* callback) {
156 if (!platform_context_.get())
157 return;
158
159 platform_context_->SetSwapBuffersCallback(callback);
160 }
161
162 unsigned int PPB_Context3D_Impl::GetBackingTextureId() {
163 if (!platform_context_.get())
164 return 0;
165
166 return platform_context_->GetBackingTextureId();
167 }
168
169 void PPB_Context3D_Impl::ResizeBackingTexture(const gfx::Size& size) {
170 if (!platform_context_.get())
171 return;
172
173 platform_context_->ResizeBackingTexture(size);
174 }
175
176 void PPB_Context3D_Impl::Destroy() {
177 gles2_impl_ = NULL;
178 platform_context_.reset();
179 }
180
181 } // namespace ppapi
182 } // namespace webkit
183
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698