diff options
author | apatrick@chromium.org <apatrick@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-06 00:00:07 +0000 |
---|---|---|
committer | apatrick@chromium.org <apatrick@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-06 00:00:07 +0000 |
commit | 5aa6a312dc935c3392e025e97daded48f5363a05 (patch) | |
tree | 2c1a286841459eba6b8b38528e2a18057f03c9d4 /webkit/glue/plugins/pepper_plugin_instance.cc | |
parent | 7bc4b5d06145e8753fdc8b2db04a5fb20ab86299 (diff) | |
download | chromium_src-5aa6a312dc935c3392e025e97daded48f5363a05.zip chromium_src-5aa6a312dc935c3392e025e97daded48f5363a05.tar.gz chromium_src-5aa6a312dc935c3392e025e97daded48f5363a05.tar.bz2 |
Reland r65152 with mac and linux fix.
Original review URL: http://codereview.chromium.org/3531008
TEST=try, ui_tests
BUG=none
Review URL: http://codereview.chromium.org/4545003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@65283 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/glue/plugins/pepper_plugin_instance.cc')
-rw-r--r-- | webkit/glue/plugins/pepper_plugin_instance.cc | 104 |
1 files changed, 72 insertions, 32 deletions
diff --git a/webkit/glue/plugins/pepper_plugin_instance.cc b/webkit/glue/plugins/pepper_plugin_instance.cc index 31ef4da..8a20e74 100644 --- a/webkit/glue/plugins/pepper_plugin_instance.cc +++ b/webkit/glue/plugins/pepper_plugin_instance.cc @@ -50,6 +50,7 @@ #include "webkit/glue/plugins/pepper_buffer.h" #include "webkit/glue/plugins/pepper_common.h" #include "webkit/glue/plugins/pepper_graphics_2d.h" +#include "webkit/glue/plugins/pepper_graphics_3d.h" #include "webkit/glue/plugins/pepper_event_conversion.h" #include "webkit/glue/plugins/pepper_fullscreen_container.h" #include "webkit/glue/plugins/pepper_image_data.h" @@ -161,11 +162,11 @@ PP_Var GetOwnerElementObject(PP_Instance instance_id) { return instance->GetOwnerElementObject(); } -PP_Bool BindGraphics(PP_Instance instance_id, PP_Resource device_id) { +PP_Bool BindGraphics(PP_Instance instance_id, PP_Resource graphics_id) { PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id); if (!instance) return PP_FALSE; - return BoolToPPBool(instance->BindGraphics(device_id)); + return BoolToPPBool(instance->BindGraphics(graphics_id)); } PP_Bool IsFullFrame(PP_Instance instance_id) { @@ -339,8 +340,8 @@ const PPB_Zoom_Dev* PluginInstance::GetZoomInterface() { void PluginInstance::Paint(WebCanvas* canvas, const gfx::Rect& plugin_rect, const gfx::Rect& paint_rect) { - if (bound_graphics_2d_) - bound_graphics_2d_->Paint(canvas, plugin_rect, paint_rect); + if (bound_graphics_2d()) + bound_graphics_2d()->Paint(canvas, plugin_rect, paint_rect); } void PluginInstance::InvalidateRect(const gfx::Rect& rect) { @@ -373,6 +374,17 @@ void PluginInstance::ScrollRect(int dx, int dy, const gfx::Rect& rect) { } } +unsigned PluginInstance::GetBackingTextureId() { + if (!bound_graphics_3d()) + return 0; + + return bound_graphics_3d()->GetBackingTextureId(); +} + +void PluginInstance::CommitBackingTexture() { + container_->commitBackingTexture(); +} + PP_Var PluginInstance::GetWindowObject() { if (!container_) return PP_MakeUndefined(); @@ -391,35 +403,44 @@ PP_Var PluginInstance::GetOwnerElementObject() { container_->scriptableObjectForElement()); } -bool PluginInstance::BindGraphics(PP_Resource device_id) { - if (!device_id) { +bool PluginInstance::BindGraphics(PP_Resource graphics_id) { + if (!graphics_id) { // Special-case clearing the current device. - if (bound_graphics_2d_) { - bound_graphics_2d_->BindToInstance(NULL); - bound_graphics_2d_ = NULL; + if (bound_graphics_.get()) { + if (bound_graphics_2d()) { + bound_graphics_2d()->BindToInstance(NULL); + } else if (bound_graphics_.get()) { + bound_graphics_3d()->SetSwapBuffersCallback(NULL); + bound_graphics_3d()->BindToInstance(NULL); + } InvalidateRect(gfx::Rect()); } + bound_graphics_ = NULL; return true; } - scoped_refptr<Graphics2D> device_2d = Resource::GetAs<Graphics2D>(device_id); + scoped_refptr<Graphics2D> graphics_2d = + Resource::GetAs<Graphics2D>(graphics_id); + scoped_refptr<Graphics3D> graphics_3d = + Resource::GetAs<Graphics3D>(graphics_id); - if (device_2d) { - if (!device_2d->BindToInstance(this)) + if (graphics_2d) { + if (!graphics_2d->BindToInstance(this)) return false; // Can't bind to more than one instance. + bound_graphics_ = graphics_2d; // See http://crbug.com/49403: this can be further optimized by keeping the // old device around and painting from it. - if (bound_graphics_2d_.get()) { + if (bound_graphics_2d()) { // Start the new image with the content of the old image until the plugin // repaints. const SkBitmap* old_backing_bitmap = - bound_graphics_2d_->image_data()->GetMappedBitmap(); + bound_graphics_2d()->image_data()->GetMappedBitmap(); SkRect old_size = SkRect::MakeWH( SkScalar(static_cast<float>(old_backing_bitmap->width())), SkScalar(static_cast<float>(old_backing_bitmap->height()))); - SkCanvas canvas(*device_2d->image_data()->GetMappedBitmap()); + SkCanvas canvas(*graphics_2d->image_data()->GetMappedBitmap()); canvas.drawBitmap(*old_backing_bitmap, 0, 0); // Fill in any extra space with white. @@ -427,8 +448,14 @@ bool PluginInstance::BindGraphics(PP_Resource device_id) { canvas.drawARGB(255, 255, 255, 255); } - bound_graphics_2d_ = device_2d; // BindToInstance will have invalidated the plugin if necessary. + } else if (graphics_3d) { + if (!graphics_3d->BindToInstance(this)) + return false; + + bound_graphics_ = graphics_3d; + bound_graphics_3d()->SetSwapBuffersCallback( + NewCallback(this, &PluginInstance::CommitBackingTexture)); } return true; @@ -538,7 +565,17 @@ PP_Var PluginInstance::GetInstanceObject() { void PluginInstance::ViewChanged(const gfx::Rect& position, const gfx::Rect& clip) { + if (position.size() != position_.size() && bound_graphics_3d()) { + // TODO(apatrick): This is a hack to force the back buffer to resize. + // It is obviously wrong to call SwapBuffers when a partial frame has + // potentially been rendered. Plan is to embed resize commands in the + // command buffer just before ViewChanged is called. + bound_graphics_3d()->ResizeBackingTexture(position.size()); + bound_graphics_3d()->SwapBuffers(); + } + position_ = position; + if (clip.IsEmpty()) { // WebKit can give weird (x,y) positions for empty clip rects (since the // position technically doesn't matter). But we want to make these @@ -580,13 +617,13 @@ void PluginInstance::SetContentAreaFocus(bool has_focus) { } void PluginInstance::ViewInitiatedPaint() { - if (bound_graphics_2d_) - bound_graphics_2d_->ViewInitiatedPaint(); + if (bound_graphics_2d()) + bound_graphics_2d()->ViewInitiatedPaint(); } void PluginInstance::ViewFlushedPaint() { - if (bound_graphics_2d_) - bound_graphics_2d_->ViewFlushedPaint(); + if (bound_graphics_2d()) + bound_graphics_2d()->ViewFlushedPaint(); } bool PluginInstance::GetBitmapForOptimizedPluginPaint( @@ -596,13 +633,13 @@ bool PluginInstance::GetBitmapForOptimizedPluginPaint( gfx::Rect* clip) { if (!always_on_top_) return false; - if (!bound_graphics_2d_ || !bound_graphics_2d_->is_always_opaque()) + if (!bound_graphics_2d() || !bound_graphics_2d()->is_always_opaque()) return false; // We specifically want to compare against the area covered by the backing // store when seeing if we cover the given paint bounds, since the backing // store could be smaller than the declared plugin area. - ImageData* image_data = bound_graphics_2d_->image_data(); + ImageData* image_data = bound_graphics_2d()->image_data(); gfx::Rect plugin_backing_store_rect(position_.origin(), gfx::Size(image_data->width(), image_data->height())); @@ -838,16 +875,6 @@ void PluginInstance::PrintEnd() { #endif // defined(OS_LINUX) } -void PluginInstance::Graphics3DContextLost() { - if (!plugin_graphics_3d_interface_) { - plugin_graphics_3d_interface_ = - reinterpret_cast<const PPP_Graphics3D_Dev*>(module_->GetPluginInterface( - PPP_GRAPHICS_3D_DEV_INTERFACE)); - } - if (plugin_graphics_3d_interface_) - plugin_graphics_3d_interface_->Graphics3DContextLost(pp_instance()); -} - bool PluginInstance::IsFullscreen() { return fullscreen_container_ != NULL; } @@ -1118,5 +1145,18 @@ void PluginInstance::DrawSkBitmapToCanvas( } #endif // defined(OS_MACOSX) +Graphics2D* PluginInstance::bound_graphics_2d() const { + if (bound_graphics_.get() == NULL) + return NULL; + + return bound_graphics_->Cast<Graphics2D>(); +} + +Graphics3D* PluginInstance::bound_graphics_3d() const { + if (bound_graphics_.get() == NULL) + return NULL; + + return bound_graphics_->Cast<Graphics3D>(); +} } // namespace pepper |