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

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

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

Powered by Google App Engine
This is Rietveld 408576698