OLD | NEW |
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 | 16 |
| 17 using ppapi::thunk::PPB_Surface3D_API; |
| 18 |
17 namespace webkit { | 19 namespace webkit { |
18 namespace ppapi { | 20 namespace ppapi { |
19 | 21 |
20 namespace { | 22 PPB_Surface3D_Impl::PPB_Surface3D_Impl(PluginInstance* instance) |
| 23 : Resource(instance), |
| 24 bound_to_instance_(false), |
| 25 swap_initiated_(false), |
| 26 swap_callback_(PP_BlockUntilComplete()), |
| 27 context_(NULL) { |
| 28 } |
21 | 29 |
22 PP_Resource Create(PP_Instance instance_id, | 30 PPB_Surface3D_Impl::~PPB_Surface3D_Impl() { |
23 PP_Config3D_Dev config, | 31 if (context_) |
24 const int32_t* attrib_list) { | 32 context_->BindSurfaces(NULL, NULL); |
| 33 } |
| 34 |
| 35 // static |
| 36 PP_Resource PPB_Surface3D_Impl::Create(PP_Instance instance_id, |
| 37 PP_Config3D_Dev config, |
| 38 const int32_t* attrib_list) { |
25 PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id); | 39 PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id); |
26 if (!instance) | 40 if (!instance) |
27 return 0; | 41 return 0; |
28 | 42 |
29 scoped_refptr<PPB_Surface3D_Impl> surface( | 43 scoped_refptr<PPB_Surface3D_Impl> surface( |
30 new PPB_Surface3D_Impl(instance)); | 44 new PPB_Surface3D_Impl(instance)); |
31 if (!surface->Init(config, attrib_list)) | 45 if (!surface->Init(config, attrib_list)) |
32 return 0; | 46 return 0; |
33 | |
34 return surface->GetReference(); | 47 return surface->GetReference(); |
35 } | 48 } |
36 | 49 |
37 PP_Bool IsSurface3D(PP_Resource resource) { | 50 PPB_Surface3D_API* PPB_Surface3D_Impl::AsPPB_Surface3D_API() { |
38 return BoolToPPBool(!!Resource::GetAs<PPB_Surface3D_Impl>(resource)); | 51 return this; |
39 } | 52 } |
40 | 53 |
41 int32_t SetAttrib(PP_Resource surface_id, | 54 int32_t PPB_Surface3D_Impl::SetAttrib(int32_t attribute, int32_t value) { |
42 int32_t attribute, | |
43 int32_t value) { | |
44 // TODO(alokp): Implement me. | 55 // TODO(alokp): Implement me. |
45 return 0; | 56 return 0; |
46 } | 57 } |
47 | 58 |
48 int32_t GetAttrib(PP_Resource surface_id, | 59 int32_t PPB_Surface3D_Impl::GetAttrib(int32_t attribute, int32_t* value) { |
49 int32_t attribute, | |
50 int32_t* value) { | |
51 // TODO(alokp): Implement me. | 60 // TODO(alokp): Implement me. |
52 return 0; | 61 return 0; |
53 } | 62 } |
54 | 63 |
55 int32_t SwapBuffers(PP_Resource surface_id, | 64 int32_t PPB_Surface3D_Impl::SwapBuffers(PP_CompletionCallback callback) { |
56 PP_CompletionCallback callback) { | 65 if (!context_) |
57 scoped_refptr<PPB_Surface3D_Impl> surface( | 66 return PP_ERROR_FAILED; |
58 Resource::GetAs<PPB_Surface3D_Impl>(surface_id)); | |
59 return surface->SwapBuffers(callback); | |
60 } | |
61 | 67 |
62 const PPB_Surface3D_Dev ppb_surface3d = { | 68 if (swap_callback_.func) { |
63 &Create, | 69 // Already a pending SwapBuffers that hasn't returned yet. |
64 &IsSurface3D, | 70 return PP_ERROR_INPROGRESS; |
65 &SetAttrib, | 71 } |
66 &GetAttrib, | |
67 &SwapBuffers | |
68 }; | |
69 | 72 |
70 } // namespace | 73 if (!callback.func) { |
| 74 // Blocking SwapBuffers isn't supported (since we have to be on the main |
| 75 // thread). |
| 76 return PP_ERROR_BADARGUMENT; |
| 77 } |
71 | 78 |
72 PPB_Surface3D_Impl::PPB_Surface3D_Impl(PluginInstance* instance) | 79 swap_callback_ = callback; |
73 : Resource(instance), | 80 gpu::gles2::GLES2Implementation* impl = context_->gles2_impl(); |
74 bound_to_instance_(false), | 81 if (impl) |
75 swap_initiated_(false), | 82 context_->gles2_impl()->SwapBuffers(); |
76 swap_callback_(PP_BlockUntilComplete()), | 83 return PP_OK_COMPLETIONPENDING; |
77 context_(NULL) { | |
78 } | |
79 | |
80 PPB_Surface3D_Impl::~PPB_Surface3D_Impl() { | |
81 if (context_) | |
82 context_->BindSurfaces(NULL, NULL); | |
83 } | |
84 | |
85 const PPB_Surface3D_Dev* PPB_Surface3D_Impl::GetInterface() { | |
86 return &ppb_surface3d; | |
87 } | |
88 | |
89 PPB_Surface3D_Impl* PPB_Surface3D_Impl::AsPPB_Surface3D_Impl() { | |
90 return this; | |
91 } | 84 } |
92 | 85 |
93 bool PPB_Surface3D_Impl::Init(PP_Config3D_Dev config, | 86 bool PPB_Surface3D_Impl::Init(PP_Config3D_Dev config, |
94 const int32_t* attrib_list) { | 87 const int32_t* attrib_list) { |
95 return true; | 88 return true; |
96 } | 89 } |
97 | 90 |
98 bool PPB_Surface3D_Impl::BindToInstance(bool bind) { | 91 bool PPB_Surface3D_Impl::BindToInstance(bool bind) { |
99 bound_to_instance_ = bind; | 92 bound_to_instance_ = bind; |
100 return true; | 93 return true; |
101 } | 94 } |
102 | 95 |
103 bool PPB_Surface3D_Impl::BindToContext( | 96 bool PPB_Surface3D_Impl::BindToContext(PPB_Context3D_Impl* context) { |
104 PPB_Context3D_Impl* context) { | |
105 if (context == context_) | 97 if (context == context_) |
106 return true; | 98 return true; |
107 | 99 |
108 // Unbind from the current context. | 100 // Unbind from the current context. |
109 if (context_) { | 101 if (context_ && context_->platform_context()) |
110 context_->platform_context()->SetSwapBuffersCallback(NULL); | 102 context_->platform_context()->SetSwapBuffersCallback(NULL); |
111 } | 103 if (context && context->platform_context()) { |
112 if (context) { | |
113 // Resize the backing texture to the size of the instance when it is bound. | 104 // Resize the backing texture to the size of the instance when it is bound. |
114 // TODO(alokp): This should be the responsibility of plugins. | 105 // TODO(alokp): This should be the responsibility of plugins. |
115 gpu::gles2::GLES2Implementation* impl = context->gles2_impl(); | 106 gpu::gles2::GLES2Implementation* impl = context->gles2_impl(); |
116 if (impl) { | 107 if (impl) { |
117 const gfx::Size& size = instance()->position().size(); | 108 const gfx::Size& size = instance()->position().size(); |
118 impl->ResizeCHROMIUM(size.width(), size.height()); | 109 impl->ResizeCHROMIUM(size.width(), size.height()); |
119 } | 110 } |
120 | 111 |
121 context->platform_context()->SetSwapBuffersCallback( | 112 context->platform_context()->SetSwapBuffersCallback( |
122 NewCallback(this, &PPB_Surface3D_Impl::OnSwapBuffers)); | 113 NewCallback(this, &PPB_Surface3D_Impl::OnSwapBuffers)); |
123 } | 114 } |
124 context_ = context; | 115 context_ = context; |
125 return true; | 116 return true; |
126 } | 117 } |
127 | 118 |
128 int32_t PPB_Surface3D_Impl::SwapBuffers(PP_CompletionCallback callback) { | |
129 if (!context_) | |
130 return PP_ERROR_FAILED; | |
131 | |
132 if (swap_callback_.func) { | |
133 // Already a pending SwapBuffers that hasn't returned yet. | |
134 return PP_ERROR_INPROGRESS; | |
135 } | |
136 | |
137 if (!callback.func) { | |
138 // Blocking SwapBuffers isn't supported (since we have to be on the main | |
139 // thread). | |
140 return PP_ERROR_BADARGUMENT; | |
141 } | |
142 | |
143 swap_callback_ = callback; | |
144 gpu::gles2::GLES2Implementation* impl = context_->gles2_impl(); | |
145 if (impl) { | |
146 context_->gles2_impl()->SwapBuffers(); | |
147 } | |
148 return PP_OK_COMPLETIONPENDING; | |
149 } | |
150 | |
151 void PPB_Surface3D_Impl::ViewInitiatedPaint() { | 119 void PPB_Surface3D_Impl::ViewInitiatedPaint() { |
152 } | 120 } |
153 | 121 |
154 void PPB_Surface3D_Impl::ViewFlushedPaint() { | 122 void PPB_Surface3D_Impl::ViewFlushedPaint() { |
155 if (swap_initiated_ && swap_callback_.func) { | 123 if (swap_initiated_ && swap_callback_.func) { |
156 // We must clear swap_callback_ before issuing the callback. It will be | 124 // We must clear swap_callback_ before issuing the callback. It will be |
157 // common for the plugin to issue another SwapBuffers in response to the | 125 // common for the plugin to issue another SwapBuffers in response to the |
158 // callback, and we don't want to think that a callback is already pending. | 126 // callback, and we don't want to think that a callback is already pending. |
159 swap_initiated_ = false; | 127 swap_initiated_ = false; |
160 PP_RunAndClearCompletionCallback(&swap_callback_, PP_OK); | 128 PP_RunAndClearCompletionCallback(&swap_callback_, PP_OK); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 const PPP_Graphics3D_Dev* ppp_graphics_3d = | 164 const PPP_Graphics3D_Dev* ppp_graphics_3d = |
197 static_cast<const PPP_Graphics3D_Dev*>( | 165 static_cast<const PPP_Graphics3D_Dev*>( |
198 instance()->module()->GetPluginInterface( | 166 instance()->module()->GetPluginInterface( |
199 PPP_GRAPHICS_3D_DEV_INTERFACE)); | 167 PPP_GRAPHICS_3D_DEV_INTERFACE)); |
200 if (ppp_graphics_3d) | 168 if (ppp_graphics_3d) |
201 ppp_graphics_3d->Graphics3DContextLost(instance()->pp_instance()); | 169 ppp_graphics_3d->Graphics3DContextLost(instance()->pp_instance()); |
202 } | 170 } |
203 | 171 |
204 } // namespace ppapi | 172 } // namespace ppapi |
205 } // namespace webkit | 173 } // namespace webkit |
OLD | NEW |