summaryrefslogtreecommitdiffstats
path: root/webkit
diff options
context:
space:
mode:
authorpiman@google.com <piman@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-08 01:55:52 +0000
committerpiman@google.com <piman@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-08 01:55:52 +0000
commitc32a97f251e5d951e86d25815d989d4db2d59bdb (patch)
tree2d4384c2163a46e4c68d9ec0e6ede5dadcb14b33 /webkit
parent9ad566288f5f4972570cd52cf6258d2ab0fe5090 (diff)
downloadchromium_src-c32a97f251e5d951e86d25815d989d4db2d59bdb.zip
chromium_src-c32a97f251e5d951e86d25815d989d4db2d59bdb.tar.gz
chromium_src-c32a97f251e5d951e86d25815d989d4db2d59bdb.tar.bz2
Clarify/fix fullscreen semantics, and add GetScreenSize
BUG=none TEST=youtube, nba, amazon Review URL: http://codereview.chromium.org/6625034 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@77229 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r--webkit/plugins/ppapi/mock_plugin_delegate.cc4
-rw-r--r--webkit/plugins/ppapi/mock_plugin_delegate.h1
-rw-r--r--webkit/plugins/ppapi/plugin_delegate.h4
-rw-r--r--webkit/plugins/ppapi/ppapi_plugin_instance.cc67
-rw-r--r--webkit/plugins/ppapi/ppapi_plugin_instance.h31
-rw-r--r--webkit/plugins/ppapi/ppapi_webplugin_impl.cc6
-rw-r--r--webkit/plugins/ppapi/ppb_graphics_2d_impl.cc10
-rw-r--r--webkit/plugins/ppapi/ppb_surface_3d_impl.cc14
8 files changed, 110 insertions, 27 deletions
diff --git a/webkit/plugins/ppapi/mock_plugin_delegate.cc b/webkit/plugins/ppapi/mock_plugin_delegate.cc
index cac4cfc..930b681 100644
--- a/webkit/plugins/ppapi/mock_plugin_delegate.cc
+++ b/webkit/plugins/ppapi/mock_plugin_delegate.cc
@@ -178,6 +178,10 @@ FullscreenContainer* MockPluginDelegate::CreateFullscreenContainer(
return NULL;
}
+gfx::Size MockPluginDelegate::GetScreenSize() {
+ return gfx::Size(1024, 768);
+}
+
std::string MockPluginDelegate::GetDefaultEncoding() {
return "iso-8859-1";
}
diff --git a/webkit/plugins/ppapi/mock_plugin_delegate.h b/webkit/plugins/ppapi/mock_plugin_delegate.h
index a759296..7980918 100644
--- a/webkit/plugins/ppapi/mock_plugin_delegate.h
+++ b/webkit/plugins/ppapi/mock_plugin_delegate.h
@@ -83,6 +83,7 @@ class MockPluginDelegate : public PluginDelegate {
const gfx::Point& position);
virtual FullscreenContainer* CreateFullscreenContainer(
PluginInstance* instance);
+ virtual gfx::Size GetScreenSize();
virtual std::string GetDefaultEncoding();
virtual void ZoomLimitsChanged(double minimum_factor,
double maximum_factor);
diff --git a/webkit/plugins/ppapi/plugin_delegate.h b/webkit/plugins/ppapi/plugin_delegate.h
index 5695a70..2e367d1 100644
--- a/webkit/plugins/ppapi/plugin_delegate.h
+++ b/webkit/plugins/ppapi/plugin_delegate.h
@@ -308,6 +308,10 @@ class PluginDelegate {
virtual FullscreenContainer* CreateFullscreenContainer(
PluginInstance* instance) = 0;
+ // Gets the size of the screen. The fullscreen window will be created at that
+ // size.
+ virtual gfx::Size GetScreenSize() = 0;
+
// Returns a string with the name of the default 8-bit char encoding.
virtual std::string GetDefaultEncoding() = 0;
diff --git a/webkit/plugins/ppapi/ppapi_plugin_instance.cc b/webkit/plugins/ppapi/ppapi_plugin_instance.cc
index 7b93ca7..f1e4e26 100644
--- a/webkit/plugins/ppapi/ppapi_plugin_instance.cc
+++ b/webkit/plugins/ppapi/ppapi_plugin_instance.cc
@@ -5,6 +5,7 @@
#include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
#include "base/logging.h"
+#include "base/message_loop.h"
#include "base/metrics/histogram.h"
#include "base/scoped_ptr.h"
#include "base/utf_string_conversions.h"
@@ -247,12 +248,24 @@ PP_Bool SetFullscreen(PP_Instance instance_id, PP_Bool fullscreen) {
PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id);
if (!instance)
return PP_FALSE;
- return BoolToPPBool(instance->SetFullscreen(PPBoolToBool(fullscreen)));
+ instance->SetFullscreen(PPBoolToBool(fullscreen), true);
+ return PP_TRUE;
}
+PP_Bool GetScreenSize(PP_Instance instance_id, PP_Size* size) {
+ PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id);
+ if (!instance || !size)
+ return PP_FALSE;
+ gfx::Size screen_size = instance->delegate()->GetScreenSize();
+ *size = PP_MakeSize(screen_size.width(), screen_size.height());
+ return PP_TRUE;
+}
+
+
const PPB_Fullscreen_Dev ppb_fullscreen = {
&IsFullscreen,
&SetFullscreen,
+ &GetScreenSize
};
void ZoomChanged(PP_Instance instance_id, double factor) {
@@ -321,7 +334,8 @@ PluginInstance::PluginInstance(PluginDelegate* delegate,
plugin_print_interface_(NULL),
plugin_graphics_3d_interface_(NULL),
always_on_top_(false),
- fullscreen_container_(NULL) {
+ fullscreen_container_(NULL),
+ fullscreen_(false) {
pp_instance_ = ResourceTracker::Get()->AddInstance(this);
memset(&current_print_settings_, 0, sizeof(current_print_settings_));
@@ -433,7 +447,7 @@ void PluginInstance::InstanceCrashed() {
ResourceTracker::Get()->InstanceCrashed(pp_instance());
// Free any associated graphics.
- SetFullscreen(false);
+ SetFullscreen(false, false);
bound_graphics_ = NULL;
InvalidateRect(gfx::Rect());
@@ -479,6 +493,9 @@ bool PluginInstance::BindGraphics(PP_Resource graphics_id) {
Resource::GetAs<PPB_Surface3D_Impl>(graphics_id);
if (graphics_2d) {
+ // Refuse to bind if we're transitioning to fullscreen.
+ if (fullscreen_container_ && !fullscreen_)
+ return false;
if (!graphics_2d->BindToInstance(this))
return false; // Can't bind to more than one instance.
@@ -508,6 +525,9 @@ bool PluginInstance::BindGraphics(PP_Resource graphics_id) {
bound_graphics_ = graphics_2d;
// BindToInstance will have invalidated the plugin if necessary.
} else if (graphics_3d) {
+ // Refuse to bind if we're transitioning to fullscreen.
+ if (fullscreen_container_ && !fullscreen_)
+ return false;
// Make sure graphics can only be bound to the instance it is
// associated with.
if (graphics_3d->instance() != this)
@@ -635,6 +655,7 @@ PP_Var PluginInstance::GetInstanceObject() {
void PluginInstance::ViewChanged(const gfx::Rect& position,
const gfx::Rect& clip) {
+ fullscreen_ = (fullscreen_container_ != NULL);
position_ = position;
if (clip.IsEmpty()) {
@@ -838,6 +859,14 @@ bool PluginInstance::PluginHasFocus() const {
return has_webkit_focus_ && has_content_area_focus_;
}
+void PluginInstance::ReportGeometry() {
+ // If this call was delayed, we may have transitioned back to fullscreen in
+ // the mean time, so only report the geometry if we are actually in normal
+ // mode.
+ if (container_ && !fullscreen_container_)
+ container_->reportGeometry();
+}
+
bool PluginInstance::GetPreferredPrintOutputFormat(
PP_PrintOutputFormat_Dev* format) {
// Keep a reference on the stack. See NOTE above.
@@ -966,30 +995,40 @@ void PluginInstance::PrintEnd() {
}
bool PluginInstance::IsFullscreen() {
+ return fullscreen_;
+}
+
+bool PluginInstance::IsFullscreenOrPending() {
return fullscreen_container_ != NULL;
}
-bool PluginInstance::SetFullscreen(bool fullscreen) {
+void PluginInstance::SetFullscreen(bool fullscreen, bool delay_report) {
// Keep a reference on the stack. See NOTE above.
scoped_refptr<PluginInstance> ref(this);
- bool is_fullscreen = (fullscreen_container_ != NULL);
- if (fullscreen == is_fullscreen)
- return true;
+
+ // We check whether we are trying to switch to the state we're already going
+ // to (i.e. if we're already switching to fullscreen but the fullscreen
+ // container isn't ready yet, don't do anything more).
+ if (fullscreen == IsFullscreenOrPending())
+ return;
+
+ BindGraphics(0);
VLOG(1) << "Setting fullscreen to " << (fullscreen ? "on" : "off");
if (fullscreen) {
+ DCHECK(!fullscreen_container_);
fullscreen_container_ = delegate_->CreateFullscreenContainer(this);
} else {
+ DCHECK(fullscreen_container_);
fullscreen_container_->Destroy();
fullscreen_container_ = NULL;
- // TODO(piman): currently the fullscreen container resizes the plugin to the
- // fullscreen size so we need to reset the size here. Eventually it will
- // transparently scale and this won't be necessary.
- if (container_) {
- container_->reportGeometry();
- container_->invalidate();
+ fullscreen_ = false;
+ if (!delay_report) {
+ ReportGeometry();
+ } else {
+ MessageLoop::current()->PostTask(
+ FROM_HERE, NewRunnableMethod(this, &PluginInstance::ReportGeometry));
}
}
- return true;
}
bool PluginInstance::NavigateToURL(const char* url, const char* target) {
diff --git a/webkit/plugins/ppapi/ppapi_plugin_instance.h b/webkit/plugins/ppapi/ppapi_plugin_instance.h
index f96abc7..356eb4c 100644
--- a/webkit/plugins/ppapi/ppapi_plugin_instance.h
+++ b/webkit/plugins/ppapi/ppapi_plugin_instance.h
@@ -186,8 +186,26 @@ class PluginInstance : public base::RefCounted<PluginInstance> {
void Graphics3DContextLost();
// Implementation of PPB_Fullscreen_Dev.
+
+ // Because going to fullscreen is asynchronous (but going out is not), there
+ // are 3 states:
+ // - normal (fullscreen_container_ == NULL)
+ // - fullscreen pending (fullscreen_container_ != NULL, fullscreen_ == false)
+ // - fullscreen (fullscreen_container_ != NULL, fullscreen_ = true)
+ //
+ // In normal state, events come from webkit and painting goes back to it.
+ // In fullscreen state, events come from the fullscreen container, and
+ // painting goes back to it
+ // In pending state, events from webkit are ignored, and as soon as we receive
+ // events from the fullscreen container, we go to the fullscreen state.
bool IsFullscreen();
- bool SetFullscreen(bool fullscreen);
+ bool IsFullscreenOrPending();
+
+ // Switches between fullscreen and normal mode. If |delay_report| is set to
+ // false, it may report the new state through DidChangeView immediately. If
+ // true, it will delay it. When called from the plugin, delay_report should be
+ // true to avoid re-entrancy.
+ void SetFullscreen(bool fullscreen, bool delay_report);
// Implementation of PPB_Flash.
bool NavigateToURL(const char* url, const char* target);
@@ -220,6 +238,10 @@ class PluginInstance : public base::RefCounted<PluginInstance> {
// (see has_webkit_focus_ below).
bool PluginHasFocus() const;
+ // Reports the current plugin geometry to the plugin by calling
+ // DidChangeView.
+ void ReportGeometry();
+
// Queries the plugin for supported print formats and sets |format| to the
// best format to use. Returns false if the plugin does not support any
// print format that we can handle (we can handle raster and PDF).
@@ -328,9 +350,14 @@ class PluginInstance : public base::RefCounted<PluginInstance> {
// to use a more optimized painting path in some cases.
bool always_on_top_;
- // Plugin container for fullscreen mode. NULL if not in fullscreen mode.
+ // Plugin container for fullscreen mode. NULL if not in fullscreen mode. Note:
+ // there is a transition state where fullscreen_container_ is non-NULL but
+ // fullscreen_ is false (see above).
FullscreenContainer* fullscreen_container_;
+ // True if we are in fullscreen mode. Note: it is false during the transition.
+ bool fullscreen_;
+
typedef std::set<PluginObject*> PluginObjectSet;
PluginObjectSet live_plugin_objects_;
diff --git a/webkit/plugins/ppapi/ppapi_webplugin_impl.cc b/webkit/plugins/ppapi/ppapi_webplugin_impl.cc
index 5bdc4ca..8adbcf4 100644
--- a/webkit/plugins/ppapi/ppapi_webplugin_impl.cc
+++ b/webkit/plugins/ppapi/ppapi_webplugin_impl.cc
@@ -96,7 +96,7 @@ NPObject* WebPluginImpl::scriptableObject() {
}
void WebPluginImpl::paint(WebCanvas* canvas, const WebRect& rect) {
- if (!instance_->IsFullscreen())
+ if (!instance_->IsFullscreenOrPending())
instance_->Paint(canvas, plugin_rect_, rect);
}
@@ -106,7 +106,7 @@ void WebPluginImpl::updateGeometry(
const WebVector<WebRect>& cut_outs_rects,
bool is_visible) {
plugin_rect_ = window_rect;
- if (!instance_->IsFullscreen())
+ if (!instance_->IsFullscreenOrPending())
instance_->ViewChanged(plugin_rect_, clip_rect);
}
@@ -127,7 +127,7 @@ bool WebPluginImpl::acceptsInputEvents() {
bool WebPluginImpl::handleInputEvent(const WebKit::WebInputEvent& event,
WebKit::WebCursorInfo& cursor_info) {
- if (instance_->IsFullscreen())
+ if (instance_->IsFullscreenOrPending())
return false;
return instance_->HandleInputEvent(event, &cursor_info);
}
diff --git a/webkit/plugins/ppapi/ppb_graphics_2d_impl.cc b/webkit/plugins/ppapi/ppb_graphics_2d_impl.cc
index 43a3467..efeb544 100644
--- a/webkit/plugins/ppapi/ppb_graphics_2d_impl.cc
+++ b/webkit/plugins/ppapi/ppb_graphics_2d_impl.cc
@@ -459,12 +459,14 @@ bool PPB_Graphics2D_Impl::BindToInstance(PluginInstance* new_instance) {
// we need to clear the list, but we still want to issue any pending
// callbacks to the plugin.
if (!unpainted_flush_callback_.is_null()) {
- ScheduleOffscreenCallback(unpainted_flush_callback_);
- unpainted_flush_callback_.Clear();
+ FlushCallbackData callback;
+ std::swap(callback, unpainted_flush_callback_);
+ ScheduleOffscreenCallback(callback);
}
if (!painted_flush_callback_.is_null()) {
- ScheduleOffscreenCallback(painted_flush_callback_);
- painted_flush_callback_.Clear();
+ FlushCallbackData callback;
+ std::swap(callback, painted_flush_callback_);
+ ScheduleOffscreenCallback(callback);
}
} else if (flushed_any_data_) {
// Only schedule a paint if this backing store has had any data flushed to
diff --git a/webkit/plugins/ppapi/ppb_surface_3d_impl.cc b/webkit/plugins/ppapi/ppb_surface_3d_impl.cc
index e79fcd7..0c81c1a 100644
--- a/webkit/plugins/ppapi/ppb_surface_3d_impl.cc
+++ b/webkit/plugins/ppapi/ppb_surface_3d_impl.cc
@@ -144,9 +144,6 @@ int32_t PPB_Surface3D_Impl::SwapBuffers(PP_CompletionCallback callback) {
}
void PPB_Surface3D_Impl::ViewInitiatedPaint() {
- if (swap_callback_.func) {
- swap_initiated_ = true;
- }
}
void PPB_Surface3D_Impl::ViewFlushedPaint() {
@@ -166,8 +163,17 @@ unsigned int PPB_Surface3D_Impl::GetBackingTextureId() {
}
void PPB_Surface3D_Impl::OnSwapBuffers() {
- if (bound_to_instance_)
+ if (bound_to_instance_) {
instance()->CommitBackingTexture();
+ swap_initiated_ = true;
+ } else if (swap_callback_.func) {
+ // If we're off-screen, no need to trigger compositing so run the callback
+ // immediately.
+ PP_CompletionCallback callback = PP_BlockUntilComplete();
+ std::swap(callback, swap_callback_);
+ swap_initiated_ = false;
+ PP_RunCompletionCallback(&callback, PP_OK);
+ }
}
} // namespace ppapi