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_context_3d_impl.h" | 5 #include "webkit/plugins/ppapi/ppb_context_3d_impl.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/shared_memory.h" | 8 #include "base/shared_memory.h" |
9 #include "gpu/command_buffer/client/gles2_cmd_helper.h" | 9 #include "gpu/command_buffer/client/gles2_cmd_helper.h" |
10 #include "gpu/command_buffer/client/gles2_implementation.h" | 10 #include "gpu/command_buffer/client/gles2_implementation.h" |
11 #include "gpu/command_buffer/common/command_buffer.h" | 11 #include "gpu/command_buffer/common/command_buffer.h" |
12 #include "ppapi/c/dev/ppb_context_3d_trusted_dev.h" | 12 #include "ppapi/c/dev/ppb_context_3d_trusted_dev.h" |
13 #include "ppapi/thunk/enter.h" | 13 #include "ppapi/thunk/enter.h" |
14 #include "webkit/plugins/ppapi/common.h" | 14 #include "webkit/plugins/ppapi/common.h" |
15 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" | 15 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" |
16 #include "webkit/plugins/ppapi/ppb_surface_3d_impl.h" | 16 #include "webkit/plugins/ppapi/ppb_surface_3d_impl.h" |
| 17 #include "webkit/plugins/ppapi/resource_helper.h" |
17 | 18 |
18 using ppapi::thunk::EnterResourceNoLock; | 19 using ppapi::thunk::EnterResourceNoLock; |
19 using ppapi::thunk::PPB_Context3D_API; | 20 using ppapi::thunk::PPB_Context3D_API; |
20 using ppapi::thunk::PPB_Surface3D_API; | 21 using ppapi::thunk::PPB_Surface3D_API; |
21 | 22 |
22 namespace webkit { | 23 namespace webkit { |
23 namespace ppapi { | 24 namespace ppapi { |
24 | 25 |
25 namespace { | 26 namespace { |
26 | 27 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 s.put_offset, | 60 s.put_offset, |
60 s.token, | 61 s.token, |
61 static_cast<PPB_Context3DTrustedError>(s.error), | 62 static_cast<PPB_Context3DTrustedError>(s.error), |
62 s.generation | 63 s.generation |
63 }; | 64 }; |
64 return state; | 65 return state; |
65 } | 66 } |
66 | 67 |
67 } // namespace | 68 } // namespace |
68 | 69 |
69 PPB_Context3D_Impl::PPB_Context3D_Impl(PluginInstance* instance) | 70 PPB_Context3D_Impl::PPB_Context3D_Impl(PP_Instance instance) |
70 : Resource(instance), | 71 : Resource(instance), |
71 instance_(instance), | |
72 transfer_buffer_id_(0), | 72 transfer_buffer_id_(0), |
73 draw_surface_(NULL), | 73 draw_surface_(NULL), |
74 read_surface_(NULL), | 74 read_surface_(NULL), |
75 callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { | 75 callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
76 } | 76 } |
77 | 77 |
78 PPB_Context3D_Impl::~PPB_Context3D_Impl() { | 78 PPB_Context3D_Impl::~PPB_Context3D_Impl() { |
79 Destroy(); | 79 Destroy(); |
80 } | 80 } |
81 | 81 |
82 // static | 82 // static |
83 PP_Resource PPB_Context3D_Impl::Create(PP_Instance pp_instance, | 83 PP_Resource PPB_Context3D_Impl::Create(PP_Instance instance, |
84 PP_Config3D_Dev config, | 84 PP_Config3D_Dev config, |
85 PP_Resource share_context, | 85 PP_Resource share_context, |
86 const int32_t* attrib_list) { | 86 const int32_t* attrib_list) { |
87 // TODO(alokp): Support shared context. | 87 // TODO(alokp): Support shared context. |
88 DCHECK_EQ(0, share_context); | 88 DCHECK_EQ(0, share_context); |
89 if (share_context != 0) | 89 if (share_context != 0) |
90 return 0; | 90 return 0; |
91 | 91 |
92 PluginInstance* instance = ResourceTracker::Get()->GetInstance(pp_instance); | 92 scoped_refptr<PPB_Context3D_Impl> context(new PPB_Context3D_Impl(instance)); |
93 if (!instance) | |
94 return 0; | |
95 | |
96 scoped_refptr<PPB_Context3D_Impl> context( | |
97 new PPB_Context3D_Impl(instance)); | |
98 if (!context->Init(config, share_context, attrib_list)) | 93 if (!context->Init(config, share_context, attrib_list)) |
99 return 0; | 94 return 0; |
100 | 95 |
101 return context->GetReference(); | 96 return context->GetReference(); |
102 } | 97 } |
103 | 98 |
104 // static | 99 // static |
105 PP_Resource PPB_Context3D_Impl::CreateRaw(PP_Instance pp_instance, | 100 PP_Resource PPB_Context3D_Impl::CreateRaw(PP_Instance instance, |
106 PP_Config3D_Dev config, | 101 PP_Config3D_Dev config, |
107 PP_Resource share_context, | 102 PP_Resource share_context, |
108 const int32_t* attrib_list) { | 103 const int32_t* attrib_list) { |
109 // TODO(alokp): Support shared context. | 104 // TODO(alokp): Support shared context. |
110 DCHECK_EQ(0, share_context); | 105 DCHECK_EQ(0, share_context); |
111 if (share_context != 0) | 106 if (share_context != 0) |
112 return 0; | 107 return 0; |
113 | 108 |
114 PluginInstance* instance = ResourceTracker::Get()->GetInstance(pp_instance); | 109 scoped_refptr<PPB_Context3D_Impl> context(new PPB_Context3D_Impl(instance)); |
115 if (!instance) | |
116 return 0; | |
117 | |
118 scoped_refptr<PPB_Context3D_Impl> context( | |
119 new PPB_Context3D_Impl(instance)); | |
120 if (!context->InitRaw(config, share_context, attrib_list)) | 110 if (!context->InitRaw(config, share_context, attrib_list)) |
121 return 0; | 111 return 0; |
122 | 112 |
123 return context->GetReference(); | 113 return context->GetReference(); |
124 } | 114 } |
125 | 115 |
126 PPB_Context3D_API* PPB_Context3D_Impl::AsPPB_Context3D_API() { | 116 PPB_Context3D_API* PPB_Context3D_Impl::AsPPB_Context3D_API() { |
127 return this; | 117 return this; |
128 } | 118 } |
129 | 119 |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 Destroy(); | 270 Destroy(); |
281 return false; | 271 return false; |
282 } | 272 } |
283 | 273 |
284 return true; | 274 return true; |
285 } | 275 } |
286 | 276 |
287 bool PPB_Context3D_Impl::InitRaw(PP_Config3D_Dev config, | 277 bool PPB_Context3D_Impl::InitRaw(PP_Config3D_Dev config, |
288 PP_Resource share_context, | 278 PP_Resource share_context, |
289 const int32_t* attrib_list) { | 279 const int32_t* attrib_list) { |
| 280 PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(this); |
| 281 if (!plugin_instance) |
| 282 return false; |
| 283 |
290 // Create and initialize the objects required to issue GLES2 calls. | 284 // Create and initialize the objects required to issue GLES2 calls. |
291 platform_context_.reset(instance()->CreateContext3D()); | 285 platform_context_.reset(plugin_instance->CreateContext3D()); |
292 if (!platform_context_.get()) { | 286 if (!platform_context_.get()) { |
293 Destroy(); | 287 Destroy(); |
294 return false; | 288 return false; |
295 } | 289 } |
296 | 290 |
297 static const int32 kAttribs[] = { | 291 static const int32 kAttribs[] = { |
298 PP_GRAPHICS3DATTRIB_ALPHA_SIZE, 8, | 292 PP_GRAPHICS3DATTRIB_ALPHA_SIZE, 8, |
299 PP_GRAPHICS3DATTRIB_DEPTH_SIZE, 24, | 293 PP_GRAPHICS3DATTRIB_DEPTH_SIZE, 24, |
300 PP_GRAPHICS3DATTRIB_STENCIL_SIZE, 8, | 294 PP_GRAPHICS3DATTRIB_STENCIL_SIZE, 8, |
301 PP_GRAPHICS3DATTRIB_SAMPLES, 0, | 295 PP_GRAPHICS3DATTRIB_SAMPLES, 0, |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
369 | 363 |
370 void PPB_Context3D_Impl::OnContextLost() { | 364 void PPB_Context3D_Impl::OnContextLost() { |
371 if (draw_surface_) | 365 if (draw_surface_) |
372 draw_surface_->OnContextLost(); | 366 draw_surface_->OnContextLost(); |
373 if (read_surface_) | 367 if (read_surface_) |
374 read_surface_->OnContextLost(); | 368 read_surface_->OnContextLost(); |
375 } | 369 } |
376 | 370 |
377 } // namespace ppapi | 371 } // namespace ppapi |
378 } // namespace webkit | 372 } // namespace webkit |
OLD | NEW |