diff options
author | derat@chromium.org <derat@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-18 22:26:40 +0000 |
---|---|---|
committer | derat@chromium.org <derat@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-18 22:26:40 +0000 |
commit | a3102766e725636ad23ad99faa1e8a481a1129e7 (patch) | |
tree | cea797379b158ff00fb8d4b2e86c67046b548946 /ui | |
parent | 8431abd52eb3f7cc0eb9812933fe3eb5e83def45 (diff) | |
download | chromium_src-a3102766e725636ad23ad99faa1e8a481a1129e7.zip chromium_src-a3102766e725636ad23ad99faa1e8a481a1129e7.tar.gz chromium_src-a3102766e725636ad23ad99faa1e8a481a1129e7.tar.bz2 |
aura/chromeos: Avoid suspending while video is playing.
This adds an ash::VideoDetector class that watches for layer
updates and attempts to detect the playback of video. A
Chrome OS-specific observer updates a _CHROME_VIDEO_TIME
property on the X root window, which is used by the power
manager to defer screen dimming or other power management
features. This matches the implementation currently in use
on Chrome OS, with Chrome taking the X window manager's role
for detecting video and setting the property.
BUG=110114
TEST=added; also manually checked that the property is updated
Review URL: http://codereview.chromium.org/9249004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@118171 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui')
-rw-r--r-- | ui/aura/window.cc | 12 | ||||
-rw-r--r-- | ui/aura/window.h | 4 | ||||
-rw-r--r-- | ui/aura/window_observer.h | 6 | ||||
-rw-r--r-- | ui/base/x/x11_util.cc | 36 | ||||
-rw-r--r-- | ui/base/x/x11_util.h | 9 | ||||
-rw-r--r-- | ui/gfx/compositor/layer.h | 4 |
6 files changed, 68 insertions, 3 deletions
diff --git a/ui/aura/window.cc b/ui/aura/window.cc index b0a1ed6..a168501 100644 --- a/ui/aura/window.cc +++ b/ui/aura/window.cc @@ -153,6 +153,8 @@ const gfx::Rect& Window::bounds() const { void Window::SchedulePaintInRect(const gfx::Rect& rect) { layer_->SchedulePaint(rect); + FOR_EACH_OBSERVER( + WindowObserver, observers_, OnWindowPaintScheduled(this, rect)); } void Window::SetCanvas(const SkCanvas& canvas, const gfx::Point& origin) { @@ -161,6 +163,16 @@ void Window::SetCanvas(const SkCanvas& canvas, const gfx::Point& origin) { // to be unhappy if we try to set a texture on a size bigger than the size of // the texture. layer_->SetCanvas(canvas, origin); + gfx::Rect region(gfx::Point(), bounds().size()); + FOR_EACH_OBSERVER( + WindowObserver, observers_, OnWindowPaintScheduled(this, region)); +} + +void Window::SetExternalTexture(ui::Texture* texture) { + layer_->SetExternalTexture(texture); + gfx::Rect region(gfx::Point(), bounds().size()); + FOR_EACH_OBSERVER( + WindowObserver, observers_, OnWindowPaintScheduled(this, region)); } void Window::SetParent(Window* parent) { diff --git a/ui/aura/window.h b/ui/aura/window.h index 73ba2dd..e83f531 100644 --- a/ui/aura/window.h +++ b/ui/aura/window.h @@ -27,6 +27,7 @@ class SkCanvas; namespace ui { class Layer; +class Texture; class Transform; } @@ -116,6 +117,9 @@ class AURA_EXPORT Window : public ui::LayerDelegate { // Sets the contents of the window. void SetCanvas(const SkCanvas& canvas, const gfx::Point& origin); + // Assigns a new external texture to the window's layer. + void SetExternalTexture(ui::Texture* texture); + // Sets the parent window of the window. If NULL, the window is parented to // the root window. void SetParent(Window* parent); diff --git a/ui/aura/window_observer.h b/ui/aura/window_observer.h index 3aa0c14..d2730c1 100644 --- a/ui/aura/window_observer.h +++ b/ui/aura/window_observer.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -46,6 +46,10 @@ class AURA_EXPORT WindowObserver { // has changed. virtual void OnWindowStackingChanged(Window* window) {} + // Invoked when a region of |window| is scheduled to be redrawn. + virtual void OnWindowPaintScheduled(Window* window, + const gfx::Rect& region) {} + // Invoked when the Window has been destroyed (i.e. from its destructor). virtual void OnWindowDestroyed(Window* window) {} diff --git a/ui/base/x/x11_util.cc b/ui/base/x/x11_util.cc index 9605fde..302ffd6 100644 --- a/ui/base/x/x11_util.cc +++ b/ui/base/x/x11_util.cc @@ -18,6 +18,7 @@ #include "base/bind.h" #include "base/command_line.h" #include "base/logging.h" +#include "base/memory/scoped_ptr.h" #include "base/memory/singleton.h" #include "base/message_loop.h" #include "base/string_number_conversions.h" @@ -514,11 +515,46 @@ bool GetStringProperty( return true; } +bool SetIntProperty(XID window, + const std::string& name, + const std::string& type, + int value) { + std::vector<int> values(1, value); + return SetIntArrayProperty(window, name, type, values); +} + +bool SetIntArrayProperty(XID window, + const std::string& name, + const std::string& type, + const std::vector<int>& value) { + DCHECK(!value.empty()); + Atom name_atom = GetAtom(name.c_str()); + Atom type_atom = GetAtom(type.c_str()); + + // XChangeProperty() expects values of type 32 to be longs. + scoped_array<long> data(new long[value.size()]); + for (size_t i = 0; i < value.size(); ++i) + data[i] = value[i]; + + gdk_error_trap_push(); + XChangeProperty(ui::GetXDisplay(), + window, + name_atom, + type_atom, + 32, // size in bits of items in 'value' + PropModeReplace, + reinterpret_cast<const unsigned char*>(data.get()), + value.size()); // num items + XSync(ui::GetXDisplay(), False); + return gdk_error_trap_pop() == 0; +} + Atom GetAtom(const char* name) { #if defined(TOOLKIT_USES_GTK) return gdk_x11_get_xatom_by_name_for_display( gdk_display_get_default(), name); #else + // TODO(derat): Cache atoms to avoid round-trips to the server. return XInternAtom(GetXDisplay(), name, false); #endif } diff --git a/ui/base/x/x11_util.h b/ui/base/x/x11_util.h index 757b149..411c941 100644 --- a/ui/base/x/x11_util.h +++ b/ui/base/x/x11_util.h @@ -124,6 +124,15 @@ UI_EXPORT bool GetAtomArrayProperty(XID window, UI_EXPORT bool GetStringProperty( XID window, const std::string& property_name, std::string* value); +UI_EXPORT bool SetIntProperty(XID window, + const std::string& name, + const std::string& type, + int value); +UI_EXPORT bool SetIntArrayProperty(XID window, + const std::string& name, + const std::string& type, + const std::vector<int>& value); + // Gets the X atom for default display corresponding to atom_name. Atom GetAtom(const char* atom_name); diff --git a/ui/gfx/compositor/layer.h b/ui/gfx/compositor/layer.h index 72f1beb..51dd4ca 100644 --- a/ui/gfx/compositor/layer.h +++ b/ui/gfx/compositor/layer.h @@ -163,8 +163,8 @@ class COMPOSITOR_EXPORT Layer : const ui::Texture* texture() const { return texture_.get(); } - // |texture| cannot be NULL, and this function cannot be called more than - // once. + // Assigns a new external texture. |texture| can be NULL to disable external + // updates. // TODO(beng): This can be removed from the API when we are in a // single-compositor world. void SetExternalTexture(ui::Texture* texture); |