summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-09-07 02:17:53 +0000
committersadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-09-07 02:17:53 +0000
commit905e19a5d13fc8e2322cab9d01559b100591a4b9 (patch)
treeb32b9822ec7e63101909b4553da325b7eaaac8e4
parent4a6bef33b6897ceff27eee304afe1a6da5fee4ff (diff)
downloadchromium_src-905e19a5d13fc8e2322cab9d01559b100591a4b9.zip
chromium_src-905e19a5d13fc8e2322cab9d01559b100591a4b9.tar.gz
chromium_src-905e19a5d13fc8e2322cab9d01559b100591a4b9.tar.bz2
gfx::Compositor: SchedulePaint.
Add CompositorDelegate as an interface between the compositor and its owner, and implement SchedulePaint through the delegate. BUG=none TEST=none Review URL: http://codereview.chromium.org/7770002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@99899 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--aura/demo/demo_main.cc4
-rw-r--r--aura/desktop.cc15
-rw-r--r--aura/desktop.h14
-rw-r--r--aura/window_unittest.cc6
-rw-r--r--ui/gfx/compositor/compositor.cc3
-rw-r--r--ui/gfx/compositor/compositor.h21
-rw-r--r--ui/gfx/compositor/compositor_gl.cc15
-rw-r--r--ui/gfx/compositor/compositor_gl.h5
-rw-r--r--ui/gfx/compositor/compositor_win.cc20
-rw-r--r--views/aura_desktop/aura_desktop_main.cc3
-rw-r--r--views/widget/native_widget_gtk.cc6
-rw-r--r--views/widget/native_widget_gtk.h5
-rw-r--r--views/widget/native_widget_win.cc11
-rw-r--r--views/widget/native_widget_win.h5
14 files changed, 94 insertions, 39 deletions
diff --git a/aura/demo/demo_main.cc b/aura/demo/demo_main.cc
index 85a39cc..e7071c6 100644
--- a/aura/demo/demo_main.cc
+++ b/aura/demo/demo_main.cc
@@ -10,6 +10,7 @@
#include "base/command_line.h"
#include "base/i18n/icu_util.h"
#include "base/memory/scoped_ptr.h"
+#include "base/message_loop.h"
#include "third_party/skia/include/core/SkXfermode.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/base/ui_base_paths.h"
@@ -72,6 +73,9 @@ int main(int argc, char** argv) {
base::MessagePumpX::DisableGtkMessagePump();
#endif
+ // Create the message-loop here before creating the desktop.
+ MessageLoop message_loop(MessageLoop::TYPE_UI);
+
aura::Desktop::GetInstance();
// Create a hierarchy of test windows.
diff --git a/aura/desktop.cc b/aura/desktop.cc
index b0ffbad1..bca7fd5 100644
--- a/aura/desktop.cc
+++ b/aura/desktop.cc
@@ -17,8 +17,11 @@ namespace aura {
Desktop* Desktop::instance_ = NULL;
Desktop::Desktop()
- : host_(aura::DesktopHost::Create(gfx::Rect(200, 200, 1024, 768))) {
- compositor_ = ui::Compositor::Create(host_->GetAcceleratedWidget(),
+ : host_(aura::DesktopHost::Create(gfx::Rect(200, 200, 1024, 768))),
+ ALLOW_THIS_IN_INITIALIZER_LIST(schedule_paint_(this)) {
+ DCHECK(MessageLoopForUI::current())
+ << "The UI message loop must be initialized first.";
+ compositor_ = ui::Compositor::Create(this, host_->GetAcceleratedWidget(),
host_->GetSize());
host_->SetDesktop(this);
DCHECK(compositor_.get());
@@ -38,7 +41,6 @@ void Desktop::SetSize(const gfx::Size& size) {
void Desktop::Run() {
Show();
- MessageLoop main_message_loop(MessageLoop::TYPE_UI);
MessageLoopForUI::current()->Run(host_);
}
@@ -56,6 +58,13 @@ bool Desktop::OnKeyEvent(const KeyEvent& event) {
return window_->HandleKeyEvent(event);
}
+void Desktop::ScheduleCompositorPaint() {
+ if (schedule_paint_.empty()) {
+ MessageLoop::current()->PostTask(FROM_HERE,
+ schedule_paint_.NewRunnableMethod(&Desktop::Draw));
+ }
+}
+
// static
Desktop* Desktop::GetInstance() {
if (!instance_) {
diff --git a/aura/desktop.h b/aura/desktop.h
index 3d292af..4440842 100644
--- a/aura/desktop.h
+++ b/aura/desktop.h
@@ -10,23 +10,21 @@
#include "aura/aura_export.h"
#include "base/basictypes.h"
#include "base/memory/ref_counted.h"
+#include "base/task.h"
+#include "ui/gfx/compositor/compositor.h"
#include "ui/gfx/native_widget_types.h"
namespace gfx {
class Size;
}
-namespace ui {
-class Compositor;
-}
-
namespace aura {
class DesktopHost;
class MouseEvent;
// Desktop is responsible for hosting a set of windows.
-class AURA_EXPORT Desktop {
+class AURA_EXPORT Desktop : public ui::CompositorDelegate {
public:
Desktop();
~Desktop();
@@ -57,6 +55,9 @@ class AURA_EXPORT Desktop {
static Desktop* GetInstance();
private:
+ // Overridden from ui::CompositorDelegate
+ virtual void ScheduleCompositorPaint();
+
scoped_refptr<ui::Compositor> compositor_;
scoped_ptr<internal::RootWindow> window_;
@@ -65,6 +66,9 @@ class AURA_EXPORT Desktop {
static Desktop* instance_;
+ // Used to schedule painting.
+ ScopedRunnableMethodFactory<Desktop> schedule_paint_;
+
DISALLOW_COPY_AND_ASSIGN(Desktop);
};
diff --git a/aura/window_unittest.cc b/aura/window_unittest.cc
index 3035ee4..2aba4c5 100644
--- a/aura/window_unittest.cc
+++ b/aura/window_unittest.cc
@@ -58,7 +58,7 @@ class TestWindowDelegate : public WindowDelegate {
class WindowTest : public testing::Test {
public:
- WindowTest() {
+ WindowTest() : main_message_loop(MessageLoop::TYPE_UI) {
aura::Desktop::GetInstance()->Show();
aura::Desktop::GetInstance()->SetSize(gfx::Size(500, 500));
}
@@ -93,11 +93,13 @@ class WindowTest : public testing::Test {
}
void RunPendingMessages() {
- MessageLoop main_message_loop(MessageLoop::TYPE_UI);
+ MessageLoop message_loop(MessageLoop::TYPE_UI);
MessageLoopForUI::current()->Run(NULL);
}
private:
+ MessageLoop main_message_loop;
+
DISALLOW_COPY_AND_ASSIGN(WindowTest);
};
diff --git a/ui/gfx/compositor/compositor.cc b/ui/gfx/compositor/compositor.cc
index 1d68ffc..ed7a4dd 100644
--- a/ui/gfx/compositor/compositor.cc
+++ b/ui/gfx/compositor/compositor.cc
@@ -7,7 +7,8 @@
namespace ui {
// static
-Compositor* Compositor::Create(gfx::AcceleratedWidget widget,
+Compositor* Compositor::Create(CompositorDelegate* delegate,
+ gfx::AcceleratedWidget widget,
const gfx::Size& size) {
return NULL;
}
diff --git a/ui/gfx/compositor/compositor.h b/ui/gfx/compositor/compositor.h
index 01e20e7..a1210cd 100644
--- a/ui/gfx/compositor/compositor.h
+++ b/ui/gfx/compositor/compositor.h
@@ -63,6 +63,13 @@ class COMPOSITOR_EXPORT Texture : public base::RefCounted<Texture> {
friend class base::RefCounted<Texture>;
};
+// An interface to allow the compositor to communicate with its owner.
+class COMPOSITOR_EXPORT CompositorDelegate {
+ public:
+ // Requests the owner to schedule a paint.
+ virtual void ScheduleCompositorPaint() = 0;
+};
+
// Compositor object to take care of GPU painting.
// A Browser compositor object is responsible for generating the final
// displayable form of pixels comprising a single widget's contents. It draws an
@@ -71,7 +78,8 @@ class COMPOSITOR_EXPORT Texture : public base::RefCounted<Texture> {
class COMPOSITOR_EXPORT Compositor : public base::RefCounted<Compositor> {
public:
// Create a compositor from the provided handle.
- static Compositor* Create(gfx::AcceleratedWidget widget,
+ static Compositor* Create(CompositorDelegate* delegate,
+ gfx::AcceleratedWidget widget,
const gfx::Size& size);
// Creates a new texture. The caller owns the returned object.
@@ -87,7 +95,9 @@ class COMPOSITOR_EXPORT Compositor : public base::RefCounted<Compositor> {
virtual void Blur(const gfx::Rect& bounds) = 0;
// Schedules a paint on the widget this Compositor was created for.
- virtual void SchedulePaint() = 0;
+ virtual void SchedulePaint() {
+ delegate_->ScheduleCompositorPaint();
+ }
// Notifies the compositor that the size of the widget that it is
// drawing to has changed.
@@ -100,12 +110,17 @@ class COMPOSITOR_EXPORT Compositor : public base::RefCounted<Compositor> {
const gfx::Size& size() { return size_; }
protected:
- explicit Compositor(const gfx::Size& size) : size_(size) {}
+ Compositor(CompositorDelegate* delegate, const gfx::Size& size)
+ : delegate_(delegate),
+ size_(size) {}
virtual ~Compositor() {}
virtual void OnWidgetSizeChanged() = 0;
+ CompositorDelegate* delegate() { return delegate_; }
+
private:
+ CompositorDelegate* delegate_;
gfx::Size size_;
friend class base::RefCounted<Compositor>;
diff --git a/ui/gfx/compositor/compositor_gl.cc b/ui/gfx/compositor/compositor_gl.cc
index ee1a38d..1c4833f 100644
--- a/ui/gfx/compositor/compositor_gl.cc
+++ b/ui/gfx/compositor/compositor_gl.cc
@@ -441,9 +441,10 @@ void TextureGL::DrawInternal(const ui::TextureProgramGL& program,
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
}
-CompositorGL::CompositorGL(gfx::AcceleratedWidget widget,
+CompositorGL::CompositorGL(CompositorDelegate* delegate,
+ gfx::AcceleratedWidget widget,
const gfx::Size& size)
- : Compositor(size),
+ : Compositor(delegate, size),
started_(false) {
gl_surface_ = gfx::GLSurface::CreateViewGLSurface(false, widget);
gl_context_ = SharedResources::GetInstance()->
@@ -493,18 +494,14 @@ void CompositorGL::Blur(const gfx::Rect& bounds) {
NOTIMPLEMENTED();
}
-void CompositorGL::SchedulePaint() {
- // TODO: X doesn't provide coalescing of regions, its left to the toolkit.
- NOTIMPLEMENTED();
-}
-
// static
-Compositor* Compositor::Create(gfx::AcceleratedWidget widget,
+Compositor* Compositor::Create(CompositorDelegate* owner,
+ gfx::AcceleratedWidget widget,
const gfx::Size& size) {
if (SharedResources::GetInstance() == NULL)
return NULL;
else
- return new CompositorGL(widget, size);
+ return new CompositorGL(owner, widget, size);
}
} // namespace ui
diff --git a/ui/gfx/compositor/compositor_gl.h b/ui/gfx/compositor/compositor_gl.h
index c89d47b..cee38c4 100644
--- a/ui/gfx/compositor/compositor_gl.h
+++ b/ui/gfx/compositor/compositor_gl.h
@@ -93,7 +93,9 @@ class COMPOSITOR_EXPORT TextureGL : public Texture {
class COMPOSITOR_EXPORT CompositorGL : public Compositor {
public:
- CompositorGL(gfx::AcceleratedWidget widget, const gfx::Size& size);
+ CompositorGL(CompositorDelegate* delegate,
+ gfx::AcceleratedWidget widget,
+ const gfx::Size& size);
virtual ~CompositorGL();
void MakeCurrent();
@@ -108,7 +110,6 @@ class COMPOSITOR_EXPORT CompositorGL : public Compositor {
virtual void NotifyStart() OVERRIDE;
virtual void NotifyEnd() OVERRIDE;
virtual void Blur(const gfx::Rect& bounds) OVERRIDE;
- virtual void SchedulePaint() OVERRIDE;
// The GL context used for compositing.
scoped_refptr<gfx::GLSurface> gl_surface_;
diff --git a/ui/gfx/compositor/compositor_win.cc b/ui/gfx/compositor/compositor_win.cc
index 3c0a2ff..ae145a9 100644
--- a/ui/gfx/compositor/compositor_win.cc
+++ b/ui/gfx/compositor/compositor_win.cc
@@ -86,7 +86,8 @@ class ViewTexture : public Texture {
// D3D 10 Compositor implementation.
class CompositorWin : public Compositor {
public:
- CompositorWin(gfx::AcceleratedWidget widget,
+ CompositorWin(CompositorDelegate* delegate,
+ gfx::AcceleratedWidget widget,
const gfx::Size& size);
void Init();
@@ -104,7 +105,6 @@ class CompositorWin : public Compositor {
virtual void NotifyStart() OVERRIDE;
virtual void NotifyEnd() OVERRIDE;
virtual void Blur(const gfx::Rect& bounds) OVERRIDE;
- virtual void SchedulePaint() OVERRIDE;
protected:
virtual void OnWidgetSizeChanged() OVERRIDE;
@@ -321,9 +321,10 @@ void ViewTexture::CreateVertexBufferForRegion(const gfx::Rect& bounds) {
vertex_buffer_.Receive()));
}
-CompositorWin::CompositorWin(gfx::AcceleratedWidget widget,
+CompositorWin::CompositorWin(CompositorDelegate* delegate,
+ gfx::AcceleratedWidget widget,
const gfx::Size& size)
- : Compositor(size),
+ : Compositor(delegate, size),
host_(widget),
technique_(NULL) {
}
@@ -499,12 +500,6 @@ void CompositorWin::Blur(const gfx::Rect& bounds) {
#endif
}
-void CompositorWin::SchedulePaint() {
- RECT bounds;
- GetClientRect(host_, &bounds);
- InvalidateRect(host_, &bounds, FALSE);
-}
-
void CompositorWin::OnWidgetSizeChanged() {
dest_render_target_view_ = NULL;
depth_stencil_buffer_ = NULL;
@@ -796,9 +791,10 @@ ID3D10Buffer* CompositorWin::CreateVertexBufferForRegion(
} // namespace
// static
-Compositor* Compositor::Create(gfx::AcceleratedWidget widget,
+Compositor* Compositor::Create(CompositorDelegate* delegate,
+ gfx::AcceleratedWidget widget,
const gfx::Size& size) {
- CompositorWin* compositor = new CompositorWin(widget, size);
+ CompositorWin* compositor = new CompositorWin(delegate, widget, size);
compositor->Init();
return compositor;
}
diff --git a/views/aura_desktop/aura_desktop_main.cc b/views/aura_desktop/aura_desktop_main.cc
index 3d0e4f3..93e22fa 100644
--- a/views/aura_desktop/aura_desktop_main.cc
+++ b/views/aura_desktop/aura_desktop_main.cc
@@ -121,6 +121,9 @@ int main(int argc, char** argv) {
base::MessagePumpX::DisableGtkMessagePump();
#endif
+ // Create the message-loop here before creating the desktop.
+ MessageLoop message_loop(MessageLoop::TYPE_UI);
+
aura::Desktop::GetInstance();
// Create a hierarchy of test windows.
diff --git a/views/widget/native_widget_gtk.cc b/views/widget/native_widget_gtk.cc
index 3db5d91..2d761d6 100644
--- a/views/widget/native_widget_gtk.cc
+++ b/views/widget/native_widget_gtk.cc
@@ -674,7 +674,7 @@ void NativeWidgetGtk::InitNativeWidget(const Widget::InitParams& params) {
} else {
gint width, height;
gdk_drawable_get_size(window_contents_->window, &width, &height);
- compositor_ = ui::Compositor::Create(
+ compositor_ = ui::Compositor::Create(this,
GDK_WINDOW_XID(window_contents_->window),
gfx::Size(width, height));
}
@@ -1804,6 +1804,10 @@ void NativeWidgetGtk::HandleGtkGrabBroke() {
////////////////////////////////////////////////////////////////////////////////
// NativeWidgetGtk, private:
+void NativeWidgetGtk::ScheduleCompositorPaint() {
+ SchedulePaintInRect(gfx::Rect(gfx::Point(), size_));
+}
+
void NativeWidgetGtk::DispatchKeyEventPostIME(const KeyEvent& key) {
// Always reset |should_handle_menu_key_release_| unless we are handling a
// VKEY_MENU key release event. It ensures that VKEY_MENU accelerator can only
diff --git a/views/widget/native_widget_gtk.h b/views/widget/native_widget_gtk.h
index 798d035..eb5ec4a 100644
--- a/views/widget/native_widget_gtk.h
+++ b/views/widget/native_widget_gtk.h
@@ -12,6 +12,7 @@
#include "base/message_loop.h"
#include "ui/base/gtk/gtk_signal.h"
#include "ui/base/x/active_window_watcher_x.h"
+#include "ui/gfx/compositor/compositor.h"
#include "ui/gfx/size.h"
#include "views/focus/focus_manager.h"
#include "views/widget/native_widget_private.h"
@@ -41,6 +42,7 @@ class NativeWidgetDelegate;
// Widget implementation for GTK.
class VIEWS_EXPORT NativeWidgetGtk : public internal::NativeWidgetPrivate,
+ public ui::CompositorDelegate,
public ui::ActiveWindowWatcherX::Observer {
public:
explicit NativeWidgetGtk(internal::NativeWidgetDelegate* delegate);
@@ -297,6 +299,9 @@ class VIEWS_EXPORT NativeWidgetGtk : public internal::NativeWidgetPrivate,
class DropObserver;
friend class DropObserver;
+ // Overridden from ui::CompositorDelegate
+ virtual void ScheduleCompositorPaint();
+
// Overridden from internal::InputMethodDelegate
virtual void DispatchKeyEventPostIME(const KeyEvent& key) OVERRIDE;
diff --git a/views/widget/native_widget_win.cc b/views/widget/native_widget_win.cc
index 1efc0c9..074de4c 100644
--- a/views/widget/native_widget_win.cc
+++ b/views/widget/native_widget_win.cc
@@ -460,6 +460,15 @@ void NativeWidgetWin::PopForceHidden() {
}
////////////////////////////////////////////////////////////////////////////////
+// NativeWidgetWin, CompositorDelegate implementation:
+
+void NativeWidgetWin::ScheduleCompositorPaint() {
+ RECT rect;
+ ::GetClientRect(GetNativeView(), &rect);
+ InvalidateRect(GetNativeView(), &rect, FALSE);
+}
+
+////////////////////////////////////////////////////////////////////////////////
// NativeWidgetWin, NativeWidget implementation:
void NativeWidgetWin::InitNativeWidget(const Widget::InitParams& params) {
@@ -1247,7 +1256,7 @@ LRESULT NativeWidgetWin::OnCreate(CREATESTRUCT* create_struct) {
} else {
CRect window_rect;
GetClientRect(&window_rect);
- compositor_ = ui::Compositor::Create(
+ compositor_ = ui::Compositor::Create(this,
hwnd(),
gfx::Size(window_rect.Width(), window_rect.Height()));
}
diff --git a/views/widget/native_widget_win.h b/views/widget/native_widget_win.h
index 3cfa9c6..967ed85 100644
--- a/views/widget/native_widget_win.h
+++ b/views/widget/native_widget_win.h
@@ -21,6 +21,7 @@
#include "base/win/scoped_comptr.h"
#include "base/win/win_util.h"
#include "ui/base/win/window_impl.h"
+#include "ui/gfx/compositor/compositor.h"
#include "views/focus/focus_manager.h"
#include "views/layout/layout_manager.h"
#include "views/widget/native_widget_private.h"
@@ -79,6 +80,7 @@ const int WM_NCUAHDRAWFRAME = 0xAF;
///////////////////////////////////////////////////////////////////////////////
class VIEWS_EXPORT NativeWidgetWin : public ui::WindowImpl,
public MessageLoopForUI::Observer,
+ public ui::CompositorDelegate,
public internal::NativeWidgetPrivate {
public:
explicit NativeWidgetWin(internal::NativeWidgetDelegate* delegate);
@@ -180,6 +182,9 @@ class VIEWS_EXPORT NativeWidgetWin : public ui::WindowImpl,
return ::GetClientRect(GetNativeView(), rect);
}
+ // Overridden from ui::CompositorDelegate:
+ virtual void ScheduleCompositorPaint();
+
// Overridden from internal::NativeWidgetPrivate:
virtual void InitNativeWidget(const Widget::InitParams& params) OVERRIDE;
virtual NonClientFrameView* CreateNonClientFrameView() OVERRIDE;