OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "components/test_runner/test_plugin.h" | 5 #include "components/test_runner/test_plugin.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 |
9 #include <utility> | 10 #include <utility> |
10 | 11 |
11 #include "base/bind.h" | 12 #include "base/bind.h" |
12 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/memory/ptr_util.h" |
13 #include "base/memory/shared_memory.h" | 15 #include "base/memory/shared_memory.h" |
14 #include "base/strings/stringprintf.h" | 16 #include "base/strings/stringprintf.h" |
15 #include "cc/blink/web_layer_impl.h" | 17 #include "cc/blink/web_layer_impl.h" |
16 #include "cc/layers/texture_layer.h" | 18 #include "cc/layers/texture_layer.h" |
17 #include "cc/resources/shared_bitmap_manager.h" | 19 #include "cc/resources/shared_bitmap_manager.h" |
18 #include "components/test_runner/web_test_delegate.h" | 20 #include "components/test_runner/web_test_delegate.h" |
19 #include "gpu/command_buffer/client/gles2_interface.h" | 21 #include "gpu/command_buffer/client/gles2_interface.h" |
20 #include "third_party/WebKit/public/platform/Platform.h" | 22 #include "third_party/WebKit/public/platform/Platform.h" |
21 #include "third_party/WebKit/public/platform/WebCompositorSupport.h" | 23 #include "third_party/WebKit/public/platform/WebCompositorSupport.h" |
22 #include "third_party/WebKit/public/platform/WebGraphicsContext3D.h" | 24 #include "third_party/WebKit/public/platform/WebGraphicsContext3D.h" |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 const blink::WebString& string) { | 101 const blink::WebString& string) { |
100 if (string == blink::WebString::fromUTF8("raw")) | 102 if (string == blink::WebString::fromUTF8("raw")) |
101 return blink::WebPluginContainer::TouchEventRequestTypeRaw; | 103 return blink::WebPluginContainer::TouchEventRequestTypeRaw; |
102 if (string == blink::WebString::fromUTF8("synthetic")) | 104 if (string == blink::WebString::fromUTF8("synthetic")) |
103 return blink::WebPluginContainer::TouchEventRequestTypeSynthesizedMouse; | 105 return blink::WebPluginContainer::TouchEventRequestTypeSynthesizedMouse; |
104 return blink::WebPluginContainer::TouchEventRequestTypeNone; | 106 return blink::WebPluginContainer::TouchEventRequestTypeNone; |
105 } | 107 } |
106 | 108 |
107 class DeferredDeleteTask : public blink::WebTaskRunner::Task { | 109 class DeferredDeleteTask : public blink::WebTaskRunner::Task { |
108 public: | 110 public: |
109 DeferredDeleteTask(scoped_ptr<TestPlugin> plugin) | 111 DeferredDeleteTask(std::unique_ptr<TestPlugin> plugin) |
110 : plugin_(std::move(plugin)) {} | 112 : plugin_(std::move(plugin)) {} |
111 | 113 |
112 void run() override {} | 114 void run() override {} |
113 | 115 |
114 private: | 116 private: |
115 scoped_ptr<TestPlugin> plugin_; | 117 std::unique_ptr<TestPlugin> plugin_; |
116 }; | 118 }; |
117 | 119 |
118 } // namespace | 120 } // namespace |
119 | 121 |
120 TestPlugin::TestPlugin(blink::WebFrame* frame, | 122 TestPlugin::TestPlugin(blink::WebFrame* frame, |
121 const blink::WebPluginParams& params, | 123 const blink::WebPluginParams& params, |
122 WebTestDelegate* delegate) | 124 WebTestDelegate* delegate) |
123 : frame_(frame), | 125 : frame_(frame), |
124 delegate_(delegate), | 126 delegate_(delegate), |
125 container_(nullptr), | 127 container_(nullptr), |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 DCHECK(container); | 179 DCHECK(container); |
178 DCHECK_EQ(this, container->plugin()); | 180 DCHECK_EQ(this, container->plugin()); |
179 | 181 |
180 container_ = container; | 182 container_ = container; |
181 | 183 |
182 blink::Platform::ContextAttributes attrs; | 184 blink::Platform::ContextAttributes attrs; |
183 DCHECK(!container->element().isNull()); | 185 DCHECK(!container->element().isNull()); |
184 DCHECK(!container->element().document().isNull()); | 186 DCHECK(!container->element().document().isNull()); |
185 blink::WebURL url = container->element().document().url(); | 187 blink::WebURL url = container->element().document().url(); |
186 blink::Platform::GraphicsInfo gl_info; | 188 blink::Platform::GraphicsInfo gl_info; |
187 context_provider_ = make_scoped_ptr( | 189 context_provider_ = base::WrapUnique( |
188 blink::Platform::current()->createOffscreenGraphicsContext3DProvider( | 190 blink::Platform::current()->createOffscreenGraphicsContext3DProvider( |
189 attrs, url, nullptr, &gl_info)); | 191 attrs, url, nullptr, &gl_info)); |
190 context_ = context_provider_ ? context_provider_->context3d() : nullptr; | 192 context_ = context_provider_ ? context_provider_->context3d() : nullptr; |
191 gl_ = context_provider_ ? context_provider_->contextGL() : nullptr; | 193 gl_ = context_provider_ ? context_provider_->contextGL() : nullptr; |
192 | 194 |
193 if (!InitScene()) | 195 if (!InitScene()) |
194 return false; | 196 return false; |
195 | 197 |
196 layer_ = cc::TextureLayer::CreateForMailbox(this); | 198 layer_ = cc::TextureLayer::CreateForMailbox(this); |
197 web_layer_ = make_scoped_ptr(new cc_blink::WebLayerImpl(layer_)); | 199 web_layer_ = base::WrapUnique(new cc_blink::WebLayerImpl(layer_)); |
198 container_->setWebLayer(web_layer_.get()); | 200 container_->setWebLayer(web_layer_.get()); |
199 if (re_request_touch_events_) { | 201 if (re_request_touch_events_) { |
200 container_->requestTouchEventType( | 202 container_->requestTouchEventType( |
201 blink::WebPluginContainer::TouchEventRequestTypeSynthesizedMouse); | 203 blink::WebPluginContainer::TouchEventRequestTypeSynthesizedMouse); |
202 container_->requestTouchEventType( | 204 container_->requestTouchEventType( |
203 blink::WebPluginContainer::TouchEventRequestTypeRaw); | 205 blink::WebPluginContainer::TouchEventRequestTypeRaw); |
204 } | 206 } |
205 container_->requestTouchEventType(touch_event_request_); | 207 container_->requestTouchEventType(touch_event_request_); |
206 container_->setWantsWheelEvents(true); | 208 container_->setWantsWheelEvents(true); |
207 return true; | 209 return true; |
208 } | 210 } |
209 | 211 |
210 void TestPlugin::destroy() { | 212 void TestPlugin::destroy() { |
211 if (layer_.get()) | 213 if (layer_.get()) |
212 layer_->ClearTexture(); | 214 layer_->ClearTexture(); |
213 if (container_) | 215 if (container_) |
214 container_->setWebLayer(0); | 216 container_->setWebLayer(0); |
215 web_layer_.reset(); | 217 web_layer_.reset(); |
216 layer_ = NULL; | 218 layer_ = NULL; |
217 DestroyScene(); | 219 DestroyScene(); |
218 | 220 |
219 gl_ = nullptr; | 221 gl_ = nullptr; |
220 context_provider_.reset(); | 222 context_provider_.reset(); |
221 | 223 |
222 container_ = nullptr; | 224 container_ = nullptr; |
223 frame_ = nullptr; | 225 frame_ = nullptr; |
224 | 226 |
225 blink::Platform::current()->mainThread()->getWebTaskRunner()->postTask( | 227 blink::Platform::current()->mainThread()->getWebTaskRunner()->postTask( |
226 blink::WebTraceLocation(__FUNCTION__, __FILE__), | 228 blink::WebTraceLocation(__FUNCTION__, __FILE__), |
227 new DeferredDeleteTask(make_scoped_ptr(this))); | 229 new DeferredDeleteTask(base::WrapUnique(this))); |
228 } | 230 } |
229 | 231 |
230 blink::WebPluginContainer* TestPlugin::container() const { | 232 blink::WebPluginContainer* TestPlugin::container() const { |
231 return container_; | 233 return container_; |
232 } | 234 } |
233 | 235 |
234 bool TestPlugin::canProcessDrag() const { | 236 bool TestPlugin::canProcessDrag() const { |
235 return can_process_drag_; | 237 return can_process_drag_; |
236 } | 238 } |
237 | 239 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 gpu::Mailbox mailbox; | 272 gpu::Mailbox mailbox; |
271 gl_->GenMailboxCHROMIUM(mailbox.name); | 273 gl_->GenMailboxCHROMIUM(mailbox.name); |
272 gl_->ProduceTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name); | 274 gl_->ProduceTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name); |
273 const GLuint64 fence_sync = gl_->InsertFenceSyncCHROMIUM(); | 275 const GLuint64 fence_sync = gl_->InsertFenceSyncCHROMIUM(); |
274 gl_->Flush(); | 276 gl_->Flush(); |
275 | 277 |
276 gpu::SyncToken sync_token; | 278 gpu::SyncToken sync_token; |
277 gl_->GenSyncTokenCHROMIUM(fence_sync, sync_token.GetData()); | 279 gl_->GenSyncTokenCHROMIUM(fence_sync, sync_token.GetData()); |
278 texture_mailbox_ = cc::TextureMailbox(mailbox, sync_token, GL_TEXTURE_2D); | 280 texture_mailbox_ = cc::TextureMailbox(mailbox, sync_token, GL_TEXTURE_2D); |
279 } else { | 281 } else { |
280 scoped_ptr<cc::SharedBitmap> bitmap = | 282 std::unique_ptr<cc::SharedBitmap> bitmap = |
281 delegate_->GetSharedBitmapManager()->AllocateSharedBitmap( | 283 delegate_->GetSharedBitmapManager()->AllocateSharedBitmap( |
282 gfx::Rect(rect_).size()); | 284 gfx::Rect(rect_).size()); |
283 if (!bitmap) { | 285 if (!bitmap) { |
284 texture_mailbox_ = cc::TextureMailbox(); | 286 texture_mailbox_ = cc::TextureMailbox(); |
285 } else { | 287 } else { |
286 DrawSceneSoftware(bitmap->pixels()); | 288 DrawSceneSoftware(bitmap->pixels()); |
287 texture_mailbox_ = cc::TextureMailbox( | 289 texture_mailbox_ = cc::TextureMailbox( |
288 bitmap.get(), gfx::Size(rect_.width, rect_.height)); | 290 bitmap.get(), gfx::Size(rect_.width, rect_.height)); |
289 shared_bitmap_ = std::move(bitmap); | 291 shared_bitmap_ = std::move(bitmap); |
290 } | 292 } |
291 } | 293 } |
292 | 294 |
293 mailbox_changed_ = true; | 295 mailbox_changed_ = true; |
294 layer_->SetNeedsDisplay(); | 296 layer_->SetNeedsDisplay(); |
295 } | 297 } |
296 | 298 |
297 bool TestPlugin::isPlaceholder() { | 299 bool TestPlugin::isPlaceholder() { |
298 return false; | 300 return false; |
299 } | 301 } |
300 | 302 |
301 static void IgnoreReleaseCallback(const gpu::SyncToken& sync_token, bool lost) { | 303 static void IgnoreReleaseCallback(const gpu::SyncToken& sync_token, bool lost) { |
302 } | 304 } |
303 | 305 |
304 static void ReleaseSharedMemory(scoped_ptr<cc::SharedBitmap> bitmap, | 306 static void ReleaseSharedMemory(std::unique_ptr<cc::SharedBitmap> bitmap, |
305 const gpu::SyncToken& sync_token, | 307 const gpu::SyncToken& sync_token, |
306 bool lost) {} | 308 bool lost) {} |
307 | 309 |
308 bool TestPlugin::PrepareTextureMailbox( | 310 bool TestPlugin::PrepareTextureMailbox( |
309 cc::TextureMailbox* mailbox, | 311 cc::TextureMailbox* mailbox, |
310 scoped_ptr<cc::SingleReleaseCallback>* release_callback, | 312 std::unique_ptr<cc::SingleReleaseCallback>* release_callback, |
311 bool use_shared_memory) { | 313 bool use_shared_memory) { |
312 if (!mailbox_changed_) | 314 if (!mailbox_changed_) |
313 return false; | 315 return false; |
314 *mailbox = texture_mailbox_; | 316 *mailbox = texture_mailbox_; |
315 if (texture_mailbox_.IsTexture()) { | 317 if (texture_mailbox_.IsTexture()) { |
316 *release_callback = | 318 *release_callback = |
317 cc::SingleReleaseCallback::Create(base::Bind(&IgnoreReleaseCallback)); | 319 cc::SingleReleaseCallback::Create(base::Bind(&IgnoreReleaseCallback)); |
318 } else if (texture_mailbox_.IsSharedMemory()) { | 320 } else if (texture_mailbox_.IsSharedMemory()) { |
319 *release_callback = cc::SingleReleaseCallback::Create( | 321 *release_callback = cc::SingleReleaseCallback::Create( |
320 base::Bind(&ReleaseSharedMemory, base::Passed(&shared_bitmap_))); | 322 base::Bind(&ReleaseSharedMemory, base::Passed(&shared_bitmap_))); |
(...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
732 return kPluginPersistsMimeType; | 734 return kPluginPersistsMimeType; |
733 } | 735 } |
734 | 736 |
735 bool TestPlugin::IsSupportedMimeType(const blink::WebString& mime_type) { | 737 bool TestPlugin::IsSupportedMimeType(const blink::WebString& mime_type) { |
736 return mime_type == TestPlugin::MimeType() || | 738 return mime_type == TestPlugin::MimeType() || |
737 mime_type == PluginPersistsMimeType() || | 739 mime_type == PluginPersistsMimeType() || |
738 mime_type == CanCreateWithoutRendererMimeType(); | 740 mime_type == CanCreateWithoutRendererMimeType(); |
739 } | 741 } |
740 | 742 |
741 } // namespace test_runner | 743 } // namespace test_runner |
OLD | NEW |