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 #include <utility> | 9 #include <utility> |
10 | 10 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/memory/shared_memory.h" | 13 #include "base/memory/shared_memory.h" |
14 #include "base/strings/stringprintf.h" | 14 #include "base/strings/stringprintf.h" |
15 #include "cc/blink/web_layer_impl.h" | 15 #include "cc/blink/web_layer_impl.h" |
16 #include "cc/layers/texture_layer.h" | 16 #include "cc/layers/texture_layer.h" |
17 #include "cc/resources/shared_bitmap_manager.h" | 17 #include "cc/resources/shared_bitmap_manager.h" |
18 #include "components/test_runner/web_test_delegate.h" | 18 #include "components/test_runner/web_test_delegate.h" |
| 19 #include "gpu/command_buffer/client/gles2_interface.h" |
19 #include "third_party/WebKit/public/platform/Platform.h" | 20 #include "third_party/WebKit/public/platform/Platform.h" |
20 #include "third_party/WebKit/public/platform/WebCompositorSupport.h" | 21 #include "third_party/WebKit/public/platform/WebCompositorSupport.h" |
21 #include "third_party/WebKit/public/platform/WebGraphicsContext3D.h" | 22 #include "third_party/WebKit/public/platform/WebGraphicsContext3D.h" |
22 #include "third_party/WebKit/public/platform/WebTaskRunner.h" | 23 #include "third_party/WebKit/public/platform/WebTaskRunner.h" |
23 #include "third_party/WebKit/public/platform/WebThread.h" | 24 #include "third_party/WebKit/public/platform/WebThread.h" |
24 #include "third_party/WebKit/public/platform/WebTraceLocation.h" | 25 #include "third_party/WebKit/public/platform/WebTraceLocation.h" |
25 #include "third_party/WebKit/public/web/WebFrame.h" | 26 #include "third_party/WebKit/public/web/WebFrame.h" |
26 #include "third_party/WebKit/public/web/WebInputEvent.h" | 27 #include "third_party/WebKit/public/web/WebInputEvent.h" |
27 #include "third_party/WebKit/public/web/WebKit.h" | 28 #include "third_party/WebKit/public/web/WebKit.h" |
28 #include "third_party/WebKit/public/web/WebPluginParams.h" | 29 #include "third_party/WebKit/public/web/WebPluginParams.h" |
29 #include "third_party/WebKit/public/web/WebTouchPoint.h" | 30 #include "third_party/WebKit/public/web/WebTouchPoint.h" |
30 #include "third_party/WebKit/public/web/WebUserGestureIndicator.h" | 31 #include "third_party/WebKit/public/web/WebUserGestureIndicator.h" |
31 #include "third_party/skia/include/core/SkBitmap.h" | 32 #include "third_party/skia/include/core/SkBitmap.h" |
32 #include "third_party/skia/include/core/SkCanvas.h" | 33 #include "third_party/skia/include/core/SkCanvas.h" |
33 #include "third_party/skia/include/core/SkColor.h" | 34 #include "third_party/skia/include/core/SkColor.h" |
34 #include "third_party/skia/include/core/SkPaint.h" | 35 #include "third_party/skia/include/core/SkPaint.h" |
35 #include "third_party/skia/include/core/SkPath.h" | 36 #include "third_party/skia/include/core/SkPath.h" |
36 | 37 |
37 namespace test_runner { | 38 namespace test_runner { |
38 | 39 |
39 namespace { | 40 namespace { |
40 | 41 |
41 // GLenum values copied from gl2.h. | |
42 #define GL_FALSE 0 | |
43 #define GL_TRUE 1 | |
44 #define GL_ONE 1 | |
45 #define GL_TRIANGLES 0x0004 | |
46 #define GL_ONE_MINUS_SRC_ALPHA 0x0303 | |
47 #define GL_DEPTH_TEST 0x0B71 | |
48 #define GL_BLEND 0x0BE2 | |
49 #define GL_SCISSOR_TEST 0x0B90 | |
50 #define GL_TEXTURE_2D 0x0DE1 | |
51 #define GL_FLOAT 0x1406 | |
52 #define GL_RGBA 0x1908 | |
53 #define GL_UNSIGNED_BYTE 0x1401 | |
54 #define GL_TEXTURE_MAG_FILTER 0x2800 | |
55 #define GL_TEXTURE_MIN_FILTER 0x2801 | |
56 #define GL_TEXTURE_WRAP_S 0x2802 | |
57 #define GL_TEXTURE_WRAP_T 0x2803 | |
58 #define GL_NEAREST 0x2600 | |
59 #define GL_COLOR_BUFFER_BIT 0x4000 | |
60 #define GL_CLAMP_TO_EDGE 0x812F | |
61 #define GL_ARRAY_BUFFER 0x8892 | |
62 #define GL_STATIC_DRAW 0x88E4 | |
63 #define GL_FRAGMENT_SHADER 0x8B30 | |
64 #define GL_VERTEX_SHADER 0x8B31 | |
65 #define GL_COMPILE_STATUS 0x8B81 | |
66 #define GL_LINK_STATUS 0x8B82 | |
67 #define GL_COLOR_ATTACHMENT0 0x8CE0 | |
68 #define GL_FRAMEBUFFER_COMPLETE 0x8CD5 | |
69 #define GL_FRAMEBUFFER 0x8D40 | |
70 | |
71 void PremultiplyAlpha(const unsigned color_in[3], | 42 void PremultiplyAlpha(const unsigned color_in[3], |
72 float alpha, | 43 float alpha, |
73 float color_out[4]) { | 44 float color_out[4]) { |
74 for (int i = 0; i < 3; ++i) | 45 for (int i = 0; i < 3; ++i) |
75 color_out[i] = (color_in[i] / 255.0f) * alpha; | 46 color_out[i] = (color_in[i] / 255.0f) * alpha; |
76 | 47 |
77 color_out[3] = alpha; | 48 color_out[3] = alpha; |
78 } | 49 } |
79 | 50 |
80 const char* PointState(blink::WebTouchPoint::State state) { | 51 const char* PointState(blink::WebTouchPoint::State state) { |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 scoped_ptr<TestPlugin> plugin_; | 113 scoped_ptr<TestPlugin> plugin_; |
143 }; | 114 }; |
144 | 115 |
145 } // namespace | 116 } // namespace |
146 | 117 |
147 TestPlugin::TestPlugin(blink::WebFrame* frame, | 118 TestPlugin::TestPlugin(blink::WebFrame* frame, |
148 const blink::WebPluginParams& params, | 119 const blink::WebPluginParams& params, |
149 WebTestDelegate* delegate) | 120 WebTestDelegate* delegate) |
150 : frame_(frame), | 121 : frame_(frame), |
151 delegate_(delegate), | 122 delegate_(delegate), |
152 container_(0), | 123 container_(nullptr), |
153 context_(0), | 124 context_(nullptr), |
| 125 gl_(nullptr), |
154 color_texture_(0), | 126 color_texture_(0), |
155 mailbox_changed_(false), | 127 mailbox_changed_(false), |
156 framebuffer_(0), | 128 framebuffer_(0), |
157 touch_event_request_( | 129 touch_event_request_( |
158 blink::WebPluginContainer::TouchEventRequestTypeNone), | 130 blink::WebPluginContainer::TouchEventRequestTypeNone), |
159 re_request_touch_events_(false), | 131 re_request_touch_events_(false), |
160 print_event_details_(false), | 132 print_event_details_(false), |
161 print_user_gesture_status_(false), | 133 print_user_gesture_status_(false), |
162 can_process_drag_(false), | 134 can_process_drag_(false), |
163 supports_keyboard_focus_(false), | 135 supports_keyboard_focus_(false), |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 std::string("TestPlugin: canCreateWithoutRenderer\n")); | 168 std::string("TestPlugin: canCreateWithoutRenderer\n")); |
197 } | 169 } |
198 | 170 |
199 TestPlugin::~TestPlugin() { | 171 TestPlugin::~TestPlugin() { |
200 } | 172 } |
201 | 173 |
202 bool TestPlugin::initialize(blink::WebPluginContainer* container) { | 174 bool TestPlugin::initialize(blink::WebPluginContainer* container) { |
203 blink::WebGraphicsContext3D::Attributes attrs; | 175 blink::WebGraphicsContext3D::Attributes attrs; |
204 context_ = | 176 context_ = |
205 blink::Platform::current()->createOffscreenGraphicsContext3D(attrs); | 177 blink::Platform::current()->createOffscreenGraphicsContext3D(attrs); |
| 178 gl_ = context_->getGLES2Interface(); |
206 | 179 |
207 if (!InitScene()) | 180 if (!InitScene()) |
208 return false; | 181 return false; |
209 | 182 |
210 layer_ = cc::TextureLayer::CreateForMailbox(this); | 183 layer_ = cc::TextureLayer::CreateForMailbox(this); |
211 web_layer_ = make_scoped_ptr(new cc_blink::WebLayerImpl(layer_)); | 184 web_layer_ = make_scoped_ptr(new cc_blink::WebLayerImpl(layer_)); |
212 container_ = container; | 185 container_ = container; |
213 container_->setWebLayer(web_layer_.get()); | 186 container_->setWebLayer(web_layer_.get()); |
214 if (re_request_touch_events_) { | 187 if (re_request_touch_events_) { |
215 container_->requestTouchEventType( | 188 container_->requestTouchEventType( |
216 blink::WebPluginContainer::TouchEventRequestTypeSynthesizedMouse); | 189 blink::WebPluginContainer::TouchEventRequestTypeSynthesizedMouse); |
217 container_->requestTouchEventType( | 190 container_->requestTouchEventType( |
218 blink::WebPluginContainer::TouchEventRequestTypeRaw); | 191 blink::WebPluginContainer::TouchEventRequestTypeRaw); |
219 } | 192 } |
220 container_->requestTouchEventType(touch_event_request_); | 193 container_->requestTouchEventType(touch_event_request_); |
221 container_->setWantsWheelEvents(true); | 194 container_->setWantsWheelEvents(true); |
222 return true; | 195 return true; |
223 } | 196 } |
224 | 197 |
225 void TestPlugin::destroy() { | 198 void TestPlugin::destroy() { |
226 if (layer_.get()) | 199 if (layer_.get()) |
227 layer_->ClearTexture(); | 200 layer_->ClearTexture(); |
228 if (container_) | 201 if (container_) |
229 container_->setWebLayer(0); | 202 container_->setWebLayer(0); |
230 web_layer_.reset(); | 203 web_layer_.reset(); |
231 layer_ = NULL; | 204 layer_ = NULL; |
232 DestroyScene(); | 205 DestroyScene(); |
233 | 206 |
| 207 gl_ = nullptr; |
234 delete context_; | 208 delete context_; |
235 context_ = 0; | 209 context_ = nullptr; |
236 | 210 |
237 container_ = 0; | 211 container_ = nullptr; |
238 frame_ = 0; | 212 frame_ = nullptr; |
239 | 213 |
240 blink::Platform::current()->mainThread()->getWebTaskRunner()->postTask( | 214 blink::Platform::current()->mainThread()->getWebTaskRunner()->postTask( |
241 blink::WebTraceLocation(__FUNCTION__, __FILE__), | 215 blink::WebTraceLocation(__FUNCTION__, __FILE__), |
242 new DeferredDeleteTask(make_scoped_ptr(this))); | 216 new DeferredDeleteTask(make_scoped_ptr(this))); |
243 } | 217 } |
244 | 218 |
245 NPObject* TestPlugin::scriptableObject() { | 219 NPObject* TestPlugin::scriptableObject() { |
246 return 0; | 220 return 0; |
247 } | 221 } |
248 | 222 |
(...skipping 28 matching lines...) Expand all Loading... |
277 context_->texImage2D(GL_TEXTURE_2D, | 251 context_->texImage2D(GL_TEXTURE_2D, |
278 0, | 252 0, |
279 GL_RGBA, | 253 GL_RGBA, |
280 rect_.width, | 254 rect_.width, |
281 rect_.height, | 255 rect_.height, |
282 0, | 256 0, |
283 GL_RGBA, | 257 GL_RGBA, |
284 GL_UNSIGNED_BYTE, | 258 GL_UNSIGNED_BYTE, |
285 0); | 259 0); |
286 context_->bindFramebuffer(GL_FRAMEBUFFER, framebuffer_); | 260 context_->bindFramebuffer(GL_FRAMEBUFFER, framebuffer_); |
287 context_->framebufferTexture2D( | 261 gl_->FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, |
288 GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, color_texture_, 0); | 262 GL_TEXTURE_2D, color_texture_, 0); |
289 | 263 |
290 DrawSceneGL(); | 264 DrawSceneGL(); |
291 | 265 |
292 gpu::Mailbox mailbox; | 266 gpu::Mailbox mailbox; |
293 context_->genMailboxCHROMIUM(mailbox.name); | 267 context_->genMailboxCHROMIUM(mailbox.name); |
294 context_->produceTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name); | 268 context_->produceTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name); |
295 const blink::WGC3Duint64 fence_sync = context_->insertFenceSyncCHROMIUM(); | 269 const blink::WGC3Duint64 fence_sync = context_->insertFenceSyncCHROMIUM(); |
296 context_->flush(); | 270 context_->flush(); |
297 | 271 |
298 gpu::SyncToken sync_token; | 272 gpu::SyncToken sync_token; |
(...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
758 return kPluginPersistsMimeType; | 732 return kPluginPersistsMimeType; |
759 } | 733 } |
760 | 734 |
761 bool TestPlugin::IsSupportedMimeType(const blink::WebString& mime_type) { | 735 bool TestPlugin::IsSupportedMimeType(const blink::WebString& mime_type) { |
762 return mime_type == TestPlugin::MimeType() || | 736 return mime_type == TestPlugin::MimeType() || |
763 mime_type == PluginPersistsMimeType() || | 737 mime_type == PluginPersistsMimeType() || |
764 mime_type == CanCreateWithoutRendererMimeType(); | 738 mime_type == CanCreateWithoutRendererMimeType(); |
765 } | 739 } |
766 | 740 |
767 } // namespace test_runner | 741 } // namespace test_runner |
OLD | NEW |