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

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

Issue 7669055: Remove webkit::ppapi::Resource. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Nulls auditeed Created 9 years, 4 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 | « webkit/plugins/ppapi/ppb_surface_3d_impl.h ('k') | webkit/plugins/ppapi/ppb_transport_impl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 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 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_surface_3d_impl.h" 5 #include "webkit/plugins/ppapi/ppb_surface_3d_impl.h"
6 6
7 #include "base/message_loop.h" 7 #include "base/message_loop.h"
8 #include "gpu/command_buffer/client/gles2_implementation.h" 8 #include "gpu/command_buffer/client/gles2_implementation.h"
9 #include "gpu/command_buffer/common/command_buffer.h" 9 #include "gpu/command_buffer/common/command_buffer.h"
10 #include "ppapi/c/dev/ppb_graphics_3d_dev.h" 10 #include "ppapi/c/dev/ppb_graphics_3d_dev.h"
11 #include "ppapi/c/dev/ppp_graphics_3d_dev.h" 11 #include "ppapi/c/dev/ppp_graphics_3d_dev.h"
12 #include "webkit/plugins/ppapi/common.h" 12 #include "webkit/plugins/ppapi/common.h"
13 #include "webkit/plugins/ppapi/plugin_module.h" 13 #include "webkit/plugins/ppapi/plugin_module.h"
14 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" 14 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
15 #include "webkit/plugins/ppapi/ppb_context_3d_impl.h" 15 #include "webkit/plugins/ppapi/ppb_context_3d_impl.h"
16 #include "webkit/plugins/ppapi/resource_helper.h"
16 17
17 using ppapi::thunk::PPB_Surface3D_API; 18 using ppapi::thunk::PPB_Surface3D_API;
18 19
19 namespace webkit { 20 namespace webkit {
20 namespace ppapi { 21 namespace ppapi {
21 22
22 PPB_Surface3D_Impl::PPB_Surface3D_Impl(PluginInstance* instance) 23 PPB_Surface3D_Impl::PPB_Surface3D_Impl(PP_Instance instance)
23 : Resource(instance), 24 : Resource(instance),
24 bound_to_instance_(false), 25 bound_to_instance_(false),
25 swap_initiated_(false), 26 swap_initiated_(false),
26 context_(NULL) { 27 context_(NULL) {
27 } 28 }
28 29
29 PPB_Surface3D_Impl::~PPB_Surface3D_Impl() { 30 PPB_Surface3D_Impl::~PPB_Surface3D_Impl() {
30 if (context_) 31 if (context_)
31 context_->BindSurfacesImpl(NULL, NULL); 32 context_->BindSurfacesImpl(NULL, NULL);
32 } 33 }
33 34
34 // static 35 // static
35 PP_Resource PPB_Surface3D_Impl::Create(PluginInstance* instance, 36 PP_Resource PPB_Surface3D_Impl::Create(PP_Instance instance,
36 PP_Config3D_Dev config, 37 PP_Config3D_Dev config,
37 const int32_t* attrib_list) { 38 const int32_t* attrib_list) {
38 scoped_refptr<PPB_Surface3D_Impl> surface( 39 scoped_refptr<PPB_Surface3D_Impl> surface(
39 new PPB_Surface3D_Impl(instance)); 40 new PPB_Surface3D_Impl(instance));
40 if (!surface->Init(config, attrib_list)) 41 if (!surface->Init(config, attrib_list))
41 return 0; 42 return 0;
42 return surface->GetReference(); 43 return surface->GetReference();
43 } 44 }
44 45
45 PPB_Surface3D_API* PPB_Surface3D_Impl::AsPPB_Surface3D_API() { 46 PPB_Surface3D_API* PPB_Surface3D_Impl::AsPPB_Surface3D_API() {
(...skipping 18 matching lines...) Expand all
64 } 65 }
65 66
66 if (swap_callback_.get() && !swap_callback_->completed()) { 67 if (swap_callback_.get() && !swap_callback_->completed()) {
67 // Already a pending SwapBuffers that hasn't returned yet. 68 // Already a pending SwapBuffers that hasn't returned yet.
68 return PP_ERROR_INPROGRESS; 69 return PP_ERROR_INPROGRESS;
69 } 70 }
70 71
71 if (!context_) 72 if (!context_)
72 return PP_ERROR_FAILED; 73 return PP_ERROR_FAILED;
73 74
75 PluginModule* plugin_module = ResourceHelper::GetPluginModule(this);
76 if (!plugin_module)
77 return PP_ERROR_FAILED;
78
74 swap_callback_ = new TrackedCompletionCallback( 79 swap_callback_ = new TrackedCompletionCallback(
75 instance()->module()->GetCallbackTracker(), pp_resource(), callback); 80 plugin_module->GetCallbackTracker(), pp_resource(), callback);
76 gpu::gles2::GLES2Implementation* impl = context_->gles2_impl(); 81 gpu::gles2::GLES2Implementation* impl = context_->gles2_impl();
77 if (impl) 82 if (impl)
78 context_->gles2_impl()->SwapBuffers(); 83 context_->gles2_impl()->SwapBuffers();
79 // |SwapBuffers()| should not call us back synchronously, but double-check. 84 // |SwapBuffers()| should not call us back synchronously, but double-check.
80 DCHECK(!swap_callback_->completed()); 85 DCHECK(!swap_callback_->completed());
81 return PP_OK_COMPLETIONPENDING; 86 return PP_OK_COMPLETIONPENDING;
82 } 87 }
83 88
84 bool PPB_Surface3D_Impl::Init(PP_Config3D_Dev config, 89 bool PPB_Surface3D_Impl::Init(PP_Config3D_Dev config,
85 const int32_t* attrib_list) { 90 const int32_t* attrib_list) {
86 return true; 91 return true;
87 } 92 }
88 93
89 bool PPB_Surface3D_Impl::BindToInstance(bool bind) { 94 bool PPB_Surface3D_Impl::BindToInstance(bool bind) {
90 bound_to_instance_ = bind; 95 bound_to_instance_ = bind;
91 return true; 96 return true;
92 } 97 }
93 98
94 bool PPB_Surface3D_Impl::BindToContext(PPB_Context3D_Impl* context) { 99 bool PPB_Surface3D_Impl::BindToContext(PPB_Context3D_Impl* context) {
95 if (context == context_) 100 if (context == context_)
96 return true; 101 return true;
97 102
103 PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(this);
104 if (!plugin_instance)
105 return false;
106
98 if (!context && bound_to_instance_) 107 if (!context && bound_to_instance_)
99 instance()->BindGraphics(instance()->pp_instance(), 0); 108 plugin_instance->BindGraphics(pp_instance(), 0);
100 109
101 // Unbind from the current context. 110 // Unbind from the current context.
102 if (context_ && context_->platform_context()) 111 if (context_ && context_->platform_context())
103 context_->platform_context()->SetSwapBuffersCallback(NULL); 112 context_->platform_context()->SetSwapBuffersCallback(NULL);
104 if (context && context->platform_context()) { 113 if (context && context->platform_context()) {
105 // Resize the backing texture to the size of the instance when it is bound. 114 // Resize the backing texture to the size of the instance when it is bound.
106 // TODO(alokp): This should be the responsibility of plugins. 115 // TODO(alokp): This should be the responsibility of plugins.
107 gpu::gles2::GLES2Implementation* impl = context->gles2_impl(); 116 gpu::gles2::GLES2Implementation* impl = context->gles2_impl();
108 if (impl) { 117 if (impl) {
109 const gfx::Size& size = instance()->position().size(); 118 const gfx::Size& size = plugin_instance->position().size();
110 impl->ResizeCHROMIUM(size.width(), size.height()); 119 impl->ResizeCHROMIUM(size.width(), size.height());
111 } 120 }
112 121
113 context->platform_context()->SetSwapBuffersCallback( 122 context->platform_context()->SetSwapBuffersCallback(
114 NewCallback(this, &PPB_Surface3D_Impl::OnSwapBuffers)); 123 NewCallback(this, &PPB_Surface3D_Impl::OnSwapBuffers));
115 } 124 }
116 context_ = context; 125 context_ = context;
117 return true; 126 return true;
118 } 127 }
119 128
(...skipping 10 matching lines...) Expand all
130 callback.swap(swap_callback_); 139 callback.swap(swap_callback_);
131 callback->Run(PP_OK); // Will complete abortively if necessary. 140 callback->Run(PP_OK); // Will complete abortively if necessary.
132 } 141 }
133 } 142 }
134 143
135 unsigned int PPB_Surface3D_Impl::GetBackingTextureId() { 144 unsigned int PPB_Surface3D_Impl::GetBackingTextureId() {
136 return context_ ? context_->platform_context()->GetBackingTextureId() : 0; 145 return context_ ? context_->platform_context()->GetBackingTextureId() : 0;
137 } 146 }
138 147
139 void PPB_Surface3D_Impl::OnSwapBuffers() { 148 void PPB_Surface3D_Impl::OnSwapBuffers() {
140 if (bound_to_instance_) { 149 PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(this);
141 instance()->CommitBackingTexture(); 150 if (!plugin_instance)
151 return;
152
153 if (bound_to_instance_ && plugin_instance) {
154 plugin_instance->CommitBackingTexture();
142 swap_initiated_ = true; 155 swap_initiated_ = true;
143 } else if (swap_callback_.get() && !swap_callback_->completed()) { 156 } else if (swap_callback_.get() && !swap_callback_->completed()) {
144 // If we're off-screen, no need to trigger compositing so run the callback 157 // If we're off-screen, no need to trigger compositing so run the callback
145 // immediately. 158 // immediately.
146 swap_initiated_ = false; 159 swap_initiated_ = false;
147 scoped_refptr<TrackedCompletionCallback> callback; 160 scoped_refptr<TrackedCompletionCallback> callback;
148 callback.swap(swap_callback_); 161 callback.swap(swap_callback_);
149 callback->Run(PP_OK); // Will complete abortively if necessary. 162 callback->Run(PP_OK); // Will complete abortively if necessary.
150 } 163 }
151 } 164 }
152 165
153 void PPB_Surface3D_Impl::OnContextLost() { 166 void PPB_Surface3D_Impl::OnContextLost() {
154 if (bound_to_instance_) 167 PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(this);
155 instance()->BindGraphics(instance()->pp_instance(), 0); 168 if (bound_to_instance_ && plugin_instance)
169 plugin_instance->BindGraphics(pp_instance(), 0);
156 170
157 // Send context lost to plugin. This may have been caused by a PPAPI call, so 171 // Send context lost to plugin. This may have been caused by a PPAPI call, so
158 // avoid re-entering. 172 // avoid re-entering.
159 MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod( 173 MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod(
160 this, &PPB_Surface3D_Impl::SendContextLost)); 174 this, &PPB_Surface3D_Impl::SendContextLost));
161 } 175 }
162 176
163 void PPB_Surface3D_Impl::SendContextLost() { 177 void PPB_Surface3D_Impl::SendContextLost() {
178 PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(this);
179
164 // By the time we run this, the instance may have been deleted, or in the 180 // By the time we run this, the instance may have been deleted, or in the
165 // process of being deleted. Even in the latter case, we don't want to send a 181 // process of being deleted. Even in the latter case, we don't want to send a
166 // callback after DidDestroy. 182 // callback after DidDestroy.
167 if (!instance() || !instance()->container()) 183 if (!plugin_instance || !plugin_instance->container())
168 return; 184 return;
169 const PPP_Graphics3D_Dev* ppp_graphics_3d = 185 const PPP_Graphics3D_Dev* ppp_graphics_3d =
170 static_cast<const PPP_Graphics3D_Dev*>( 186 static_cast<const PPP_Graphics3D_Dev*>(
171 instance()->module()->GetPluginInterface( 187 plugin_instance->module()->GetPluginInterface(
172 PPP_GRAPHICS_3D_DEV_INTERFACE)); 188 PPP_GRAPHICS_3D_DEV_INTERFACE));
173 if (ppp_graphics_3d) 189 if (ppp_graphics_3d)
174 ppp_graphics_3d->Graphics3DContextLost(instance()->pp_instance()); 190 ppp_graphics_3d->Graphics3DContextLost(pp_instance());
175 } 191 }
176 192
177 } // namespace ppapi 193 } // namespace ppapi
178 } // namespace webkit 194 } // namespace webkit
OLDNEW
« no previous file with comments | « webkit/plugins/ppapi/ppb_surface_3d_impl.h ('k') | webkit/plugins/ppapi/ppb_transport_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698