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/ppapi_plugin_instance.h" | 5 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 #if defined(OS_WIN) | 78 #if defined(OS_WIN) |
79 #include "skia/ext/vector_platform_device_emf_win.h" | 79 #include "skia/ext/vector_platform_device_emf_win.h" |
80 #include "ui/gfx/codec/jpeg_codec.h" | 80 #include "ui/gfx/codec/jpeg_codec.h" |
81 #include "ui/gfx/gdi_util.h" | 81 #include "ui/gfx/gdi_util.h" |
82 #endif | 82 #endif |
83 | 83 |
84 #if defined(OS_MACOSX) && defined(USE_SKIA) | 84 #if defined(OS_MACOSX) && defined(USE_SKIA) |
85 #include "skia/ext/skia_utils_mac.h" | 85 #include "skia/ext/skia_utils_mac.h" |
86 #endif | 86 #endif |
87 | 87 |
88 using ::ppapi::thunk::EnterResourceNoLock; | 88 using ppapi::thunk::EnterResourceNoLock; |
89 using ::ppapi::thunk::PPB_Buffer_API; | 89 using ppapi::thunk::PPB_Buffer_API; |
90 using ::ppapi::thunk::PPB_Graphics2D_API; | 90 using ppapi::thunk::PPB_Graphics2D_API; |
91 using ::ppapi::thunk::PPB_Instance_FunctionAPI; | 91 using ppapi::thunk::PPB_ImageData_API; |
| 92 using ppapi::thunk::PPB_Instance_FunctionAPI; |
| 93 using ppapi::thunk::PPB_Surface3D_API; |
92 using WebKit::WebBindings; | 94 using WebKit::WebBindings; |
93 using WebKit::WebCanvas; | 95 using WebKit::WebCanvas; |
94 using WebKit::WebCursorInfo; | 96 using WebKit::WebCursorInfo; |
95 using WebKit::WebDocument; | 97 using WebKit::WebDocument; |
96 using WebKit::WebFrame; | 98 using WebKit::WebFrame; |
97 using WebKit::WebInputEvent; | 99 using WebKit::WebInputEvent; |
98 using WebKit::WebPluginContainer; | 100 using WebKit::WebPluginContainer; |
99 using WebKit::WebString; | 101 using WebKit::WebString; |
100 using WebKit::WebURLRequest; | 102 using WebKit::WebURLRequest; |
101 using WebKit::WebView; | 103 using WebKit::WebView; |
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
393 PP_Resource custom_image, | 395 PP_Resource custom_image, |
394 const PP_Point* hot_spot) { | 396 const PP_Point* hot_spot) { |
395 if (type != PP_CURSORTYPE_CUSTOM) { | 397 if (type != PP_CURSORTYPE_CUSTOM) { |
396 cursor_.reset(new WebCursorInfo(static_cast<WebCursorInfo::Type>(type))); | 398 cursor_.reset(new WebCursorInfo(static_cast<WebCursorInfo::Type>(type))); |
397 return true; | 399 return true; |
398 } | 400 } |
399 | 401 |
400 if (!hot_spot) | 402 if (!hot_spot) |
401 return false; | 403 return false; |
402 | 404 |
403 scoped_refptr<PPB_ImageData_Impl> image_data( | 405 EnterResourceNoLock<PPB_ImageData_API> enter(custom_image, true); |
404 Resource::GetAs<PPB_ImageData_Impl>(custom_image)); | 406 if (enter.failed()) |
405 if (!image_data.get()) | |
406 return false; | 407 return false; |
| 408 PPB_ImageData_Impl* image_data = |
| 409 static_cast<PPB_ImageData_Impl*>(enter.object()); |
407 | 410 |
408 if (image_data->format() != PPB_ImageData_Impl::GetNativeImageDataFormat()) { | 411 if (image_data->format() != PPB_ImageData_Impl::GetNativeImageDataFormat()) { |
409 // TODO(yzshen): Handle the case that the image format is different from the | 412 // TODO(yzshen): Handle the case that the image format is different from the |
410 // native format. | 413 // native format. |
411 NOTIMPLEMENTED(); | 414 NOTIMPLEMENTED(); |
412 return false; | 415 return false; |
413 } | 416 } |
414 | 417 |
415 ImageDataAutoMapper auto_mapper(image_data); | 418 ImageDataAutoMapper auto_mapper(image_data); |
416 if (!auto_mapper.is_valid()) | 419 if (!auto_mapper.is_valid()) |
(...skipping 712 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1129 size_in_pixels.height(), true, false, true, true); | 1132 size_in_pixels.height(), true, false, true, true); |
1130 skia::EndPlatformPaint(canvas); | 1133 skia::EndPlatformPaint(canvas); |
1131 } | 1134 } |
1132 #endif // defined(OS_WIN) | 1135 #endif // defined(OS_WIN) |
1133 | 1136 |
1134 return ret; | 1137 return ret; |
1135 } | 1138 } |
1136 | 1139 |
1137 bool PluginInstance::PrintRasterOutput(PP_Resource print_output, | 1140 bool PluginInstance::PrintRasterOutput(PP_Resource print_output, |
1138 WebKit::WebCanvas* canvas) { | 1141 WebKit::WebCanvas* canvas) { |
1139 scoped_refptr<PPB_ImageData_Impl> image( | 1142 EnterResourceNoLock<PPB_ImageData_API> enter(print_output, true); |
1140 Resource::GetAs<PPB_ImageData_Impl>(print_output)); | 1143 if (enter.failed()) |
1141 if (!image.get() || !image->is_mapped()) | 1144 return false; |
| 1145 PPB_ImageData_Impl* image = |
| 1146 static_cast<PPB_ImageData_Impl*>(enter.object()); |
| 1147 |
| 1148 // TODO(brettw) this should not require the image to be mapped. It should |
| 1149 // instead map on demand. The DCHECK here is to remind you if you see the |
| 1150 // assert fire, fix the bug rather than mapping the data. |
| 1151 DCHECK(image->is_mapped()); |
| 1152 if (!image->is_mapped()) |
1142 return false; | 1153 return false; |
1143 | 1154 |
1144 const SkBitmap* bitmap = image->GetMappedBitmap(); | 1155 const SkBitmap* bitmap = image->GetMappedBitmap(); |
1145 if (!bitmap) | 1156 if (!bitmap) |
1146 return false; | 1157 return false; |
1147 | 1158 |
1148 // Draw the printed image into the supplied canvas. | 1159 // Draw the printed image into the supplied canvas. |
1149 SkIRect src_rect; | 1160 SkIRect src_rect; |
1150 src_rect.set(0, 0, bitmap->width(), bitmap->height()); | 1161 src_rect.set(0, 0, bitmap->width(), bitmap->height()); |
1151 SkRect dest_rect; | 1162 SkRect dest_rect; |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1271 | 1282 |
1272 CGContextDrawImage(canvas, bounds, image); | 1283 CGContextDrawImage(canvas, bounds, image); |
1273 CGContextRestoreGState(canvas); | 1284 CGContextRestoreGState(canvas); |
1274 } | 1285 } |
1275 #endif // defined(OS_MACOSX) && !defined(USE_SKIA) | 1286 #endif // defined(OS_MACOSX) && !defined(USE_SKIA) |
1276 | 1287 |
1277 PPB_Graphics2D_Impl* PluginInstance::bound_graphics_2d() const { | 1288 PPB_Graphics2D_Impl* PluginInstance::bound_graphics_2d() const { |
1278 if (bound_graphics_.get() == NULL) | 1289 if (bound_graphics_.get() == NULL) |
1279 return NULL; | 1290 return NULL; |
1280 | 1291 |
1281 return bound_graphics_->Cast<PPB_Graphics2D_Impl>(); | 1292 if (bound_graphics_->AsPPB_Graphics2D_API()) |
| 1293 return static_cast<PPB_Graphics2D_Impl*>(bound_graphics_.get()); |
| 1294 return NULL; |
1282 } | 1295 } |
1283 | 1296 |
1284 PPB_Surface3D_Impl* PluginInstance::bound_graphics_3d() const { | 1297 PPB_Surface3D_Impl* PluginInstance::bound_graphics_3d() const { |
1285 if (bound_graphics_.get() == NULL) | 1298 if (bound_graphics_.get() == NULL) |
1286 return NULL; | 1299 return NULL; |
1287 | 1300 |
1288 return bound_graphics_->Cast<PPB_Surface3D_Impl>(); | 1301 if (bound_graphics_->AsPPB_Surface3D_API()) |
| 1302 return static_cast<PPB_Surface3D_Impl*>(bound_graphics_.get()); |
| 1303 return NULL; |
1289 } | 1304 } |
1290 | 1305 |
1291 void PluginInstance::setBackingTextureId(unsigned int id) { | 1306 void PluginInstance::setBackingTextureId(unsigned int id) { |
1292 // If we have a full-screen container_ then the plugin is fullscreen, | 1307 // If we have a full-screen container_ then the plugin is fullscreen, |
1293 // and the parent context is not the one for the browser page, but for the | 1308 // and the parent context is not the one for the browser page, but for the |
1294 // full-screen window, and so the parent texture ID doesn't correspond to | 1309 // full-screen window, and so the parent texture ID doesn't correspond to |
1295 // anything in the page's context. | 1310 // anything in the page's context. |
1296 // | 1311 // |
1297 // TODO(alokp): It would be better at some point to have the equivalent | 1312 // TODO(alokp): It would be better at some point to have the equivalent |
1298 // in the FullscreenContainer so that we don't need to poll | 1313 // in the FullscreenContainer so that we don't need to poll |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1365 setBackingTextureId(0); | 1380 setBackingTextureId(0); |
1366 InvalidateRect(gfx::Rect()); | 1381 InvalidateRect(gfx::Rect()); |
1367 } | 1382 } |
1368 bound_graphics_ = NULL; | 1383 bound_graphics_ = NULL; |
1369 return PP_TRUE; | 1384 return PP_TRUE; |
1370 } | 1385 } |
1371 | 1386 |
1372 EnterResourceNoLock<PPB_Graphics2D_API> enter_2d(device, false); | 1387 EnterResourceNoLock<PPB_Graphics2D_API> enter_2d(device, false); |
1373 PPB_Graphics2D_Impl* graphics_2d = enter_2d.succeeded() ? | 1388 PPB_Graphics2D_Impl* graphics_2d = enter_2d.succeeded() ? |
1374 static_cast<PPB_Graphics2D_Impl*>(enter_2d.object()) : NULL; | 1389 static_cast<PPB_Graphics2D_Impl*>(enter_2d.object()) : NULL; |
1375 // Surface3D not converted to API yet. | 1390 EnterResourceNoLock<PPB_Surface3D_API> enter_3d(device, false); |
1376 scoped_refptr<PPB_Surface3D_Impl> graphics_3d = | 1391 PPB_Surface3D_Impl* graphics_3d = enter_3d.succeeded() ? |
1377 Resource::GetAs<PPB_Surface3D_Impl>(device); | 1392 static_cast<PPB_Surface3D_Impl*>(enter_3d.object()) : NULL; |
1378 | 1393 |
1379 if (graphics_2d) { | 1394 if (graphics_2d) { |
1380 // Refuse to bind if we're transitioning to fullscreen. | 1395 // Refuse to bind if we're transitioning to fullscreen. |
1381 if (fullscreen_container_ && !fullscreen_) | 1396 if (fullscreen_container_ && !fullscreen_) |
1382 return PP_FALSE; | 1397 return PP_FALSE; |
1383 if (graphics_2d->instance() != this) | 1398 if (graphics_2d->instance() != this) |
1384 return PP_FALSE; // Can't bind other instance's contexts. | 1399 return PP_FALSE; // Can't bind other instance's contexts. |
1385 if (!graphics_2d->BindToInstance(this)) | 1400 if (!graphics_2d->BindToInstance(this)) |
1386 return PP_FALSE; // Can't bind to more than one instance. | 1401 return PP_FALSE; // Can't bind to more than one instance. |
1387 | 1402 |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1504 } | 1519 } |
1505 | 1520 |
1506 PP_Bool PluginInstance::GetScreenSize(PP_Instance instance, PP_Size* size) { | 1521 PP_Bool PluginInstance::GetScreenSize(PP_Instance instance, PP_Size* size) { |
1507 gfx::Size screen_size = delegate()->GetScreenSize(); | 1522 gfx::Size screen_size = delegate()->GetScreenSize(); |
1508 *size = PP_MakeSize(screen_size.width(), screen_size.height()); | 1523 *size = PP_MakeSize(screen_size.width(), screen_size.height()); |
1509 return PP_TRUE; | 1524 return PP_TRUE; |
1510 } | 1525 } |
1511 | 1526 |
1512 } // namespace ppapi | 1527 } // namespace ppapi |
1513 } // namespace webkit | 1528 } // namespace webkit |
OLD | NEW |