summaryrefslogtreecommitdiffstats
path: root/views/widget
diff options
context:
space:
mode:
authorsadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-15 02:18:36 +0000
committersadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-15 02:18:36 +0000
commitc797cd43680b525ea771dc226ca353078c5c56f1 (patch)
treea172b53773aec97a6c3dd9c4fcf93acc27d0cca2 /views/widget
parent8df9747bff840d1a63b9fe1309b18e5fb21e8340 (diff)
downloadchromium_src-c797cd43680b525ea771dc226ca353078c5c56f1.zip
chromium_src-c797cd43680b525ea771dc226ca353078c5c56f1.tar.gz
chromium_src-c797cd43680b525ea771dc226ca353078c5c56f1.tar.bz2
Start working on compositor tree painting.
As a first step, maintain a skia canvas in each transformed view. Each transformed view will acquire a texture-id for the canvas it owns. Whenever the canvas is updated, it will trigger a refresh in the compositor tree. BUG=none TEST=none Review URL: http://codereview.chromium.org/6594125 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@78149 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views/widget')
-rw-r--r--views/widget/native_widget.h4
-rw-r--r--views/widget/native_widget_delegate.h5
-rw-r--r--views/widget/root_view.h1
-rw-r--r--views/widget/widget.cc31
-rw-r--r--views/widget/widget.h15
-rw-r--r--views/widget/widget_gtk.cc7
-rw-r--r--views/widget/widget_gtk.h6
-rw-r--r--views/widget/widget_win.cc7
-rw-r--r--views/widget/widget_win.h3
9 files changed, 76 insertions, 3 deletions
diff --git a/views/widget/native_widget.h b/views/widget/native_widget.h
index 26dbd9b..a833664 100644
--- a/views/widget/native_widget.h
+++ b/views/widget/native_widget.h
@@ -72,6 +72,10 @@ class NativeWidget {
protected:
friend class Widget;
+ // Returns a handle for the underlying native widget that can be used for
+ // accelerated drawing.
+ virtual gfx::AcceleratedWidget GetAcceleratedWidget() = 0;
+
// Widget pass-thrus, private to Views. --------------------------------------
// See method documentation in Widget.
virtual gfx::Rect GetWindowScreenBounds() const = 0;
diff --git a/views/widget/native_widget_delegate.h b/views/widget/native_widget_delegate.h
index e14e32b..b21cd10 100644
--- a/views/widget/native_widget_delegate.h
+++ b/views/widget/native_widget_delegate.h
@@ -7,6 +7,7 @@
#pragma once
namespace gfx {
+class Canvas;
class Size;
}
@@ -35,6 +36,10 @@ class NativeWidgetDelegate {
// Returns true if the delegate has a FocusManager.
virtual bool HasFocusManager() const = 0;
+
+ // Paints the rootview in the canvas. This will also refresh the compositor
+ // tree if necessary when accelerated painting is enabled.
+ virtual void OnPaint(gfx::Canvas* canvas) = 0;
};
} // namespace internal
diff --git a/views/widget/root_view.h b/views/widget/root_view.h
index 3eac199..6658fe0 100644
--- a/views/widget/root_view.h
+++ b/views/widget/root_view.h
@@ -124,6 +124,7 @@ class RootView : public View,
private:
friend class View;
+ friend class Widget;
#if defined(TOUCH_UI)
// Required so the GestureManager can call the Process* entry points
diff --git a/views/widget/widget.cc b/views/widget/widget.cc
index 4a58b32..88c7bf3 100644
--- a/views/widget/widget.cc
+++ b/views/widget/widget.cc
@@ -6,6 +6,7 @@
#include "base/logging.h"
#include "base/message_loop.h"
+#include "ui/gfx/compositor.h"
#include "views/focus/view_storage.h"
#include "views/widget/default_theme_provider.h"
#include "views/widget/root_view.h"
@@ -264,6 +265,11 @@ bool Widget::HasFocusManager() const {
return !!focus_manager_.get();
}
+void Widget::OnPaint(gfx::Canvas* canvas) {
+ GetRootView()->Paint(canvas);
+ RefreshCompositeTree();
+}
+
////////////////////////////////////////////////////////////////////////////////
// Widget, FocusTraversable implementation:
@@ -311,4 +317,29 @@ void Widget::ReplaceFocusManager(FocusManager* focus_manager) {
focus_manager_.reset(focus_manager);
}
+////////////////////////////////////////////////////////////////////////////////
+// Widget, private:
+
+void Widget::RefreshCompositeTree() {
+ if (!EnsureCompositor())
+ return;
+
+ compositor_->NotifyStart();
+ root_view_->PaintComposite(compositor_.get());
+ compositor_->NotifyEnd();
+}
+
+bool Widget::EnsureCompositor() {
+ if (compositor_.get())
+ return true;
+
+ // TODO(sad): If there is a parent Widget, then use the same compositor
+ // instead of creating a new one here.
+ gfx::AcceleratedWidget widget = native_widget_->GetAcceleratedWidget();
+ if (widget != gfx::kNullAcceleratedWidget)
+ compositor_ = ui::Compositor::Create(widget);
+
+ return compositor_.get() != NULL;
+}
+
} // namespace views
diff --git a/views/widget/widget.h b/views/widget/widget.h
index 684cade..21f4f48 100644
--- a/views/widget/widget.h
+++ b/views/widget/widget.h
@@ -8,6 +8,7 @@
#include <vector>
+#include "base/ref_counted.h"
#include "base/scoped_ptr.h"
#include "ui/base/accessibility/accessibility_types.h"
#include "ui/gfx/native_widget_types.h"
@@ -15,6 +16,7 @@
#include "views/widget/native_widget_delegate.h"
namespace gfx {
+class Canvas;
class Path;
class Point;
class Rect;
@@ -22,6 +24,7 @@ class Rect;
namespace ui {
class Accelerator;
+class Compositor;
class OSExchangeData;
class ThemeProvider;
}
@@ -272,6 +275,7 @@ class Widget : public internal::NativeWidgetDelegate,
virtual void OnNativeWidgetCreated() OVERRIDE;
virtual void OnSizeChanged(const gfx::Size& new_size) OVERRIDE;
virtual bool HasFocusManager() const OVERRIDE;
+ virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE;
// Overridden from FocusTraversable:
virtual FocusSearch* GetFocusSearch() OVERRIDE;
@@ -299,6 +303,14 @@ class Widget : public internal::NativeWidgetDelegate,
void ReplaceFocusManager(FocusManager* focus_manager);
private:
+ // Refresh the compositor tree. This is called by a View whenever its texture
+ // is updated.
+ void RefreshCompositeTree();
+
+ // Try to create a compositor if one hasn't been created yet. Returns false if
+ // a compositor couldn't be created.
+ bool EnsureCompositor();
+
NativeWidget* native_widget_;
// Non-owned pointer to the Widget's delegate. May be NULL if no delegate is
@@ -323,6 +335,9 @@ class Widget : public internal::NativeWidgetDelegate,
// started from.
View* dragged_view_;
+ // The compositor for accelerated drawing.
+ scoped_refptr<ui::Compositor> compositor_;
+
DISALLOW_COPY_AND_ASSIGN(Widget);
};
diff --git a/views/widget/widget_gtk.cc b/views/widget/widget_gtk.cc
index 3ebd950..0a89fee 100644
--- a/views/widget/widget_gtk.cc
+++ b/views/widget/widget_gtk.cc
@@ -955,7 +955,7 @@ gboolean WidgetGtk::OnPaint(GtkWidget* widget, GdkEventExpose* event) {
gfx::CanvasSkiaPaint canvas(event);
if (!canvas.is_empty()) {
canvas.set_composite_alpha(is_transparent());
- GetRootView()->Paint(&canvas);
+ delegate_->OnPaint(&canvas);
}
return false; // False indicates other widgets should get the event as well.
}
@@ -1270,6 +1270,11 @@ RootView* WidgetGtk::CreateRootView() {
return new RootView(this);
}
+gfx::AcceleratedWidget WidgetGtk::GetAcceleratedWidget() {
+ DCHECK(window_contents_ && window_contents_->window);
+ return GDK_WINDOW_XID(window_contents_->window);
+}
+
gboolean WidgetGtk::OnWindowPaint(GtkWidget* widget, GdkEventExpose* event) {
// Clear the background to be totally transparent. We don't need to
// paint the root view here as that is done by OnPaint.
diff --git a/views/widget/widget_gtk.h b/views/widget/widget_gtk.h
index 142f2cd..370e9cf 100644
--- a/views/widget/widget_gtk.h
+++ b/views/widget/widget_gtk.h
@@ -287,7 +287,11 @@ class WidgetGtk : public Widget,
class DropObserver;
friend class DropObserver;
- virtual RootView* CreateRootView();
+ // Overridden from Widget
+ virtual RootView* CreateRootView() OVERRIDE;
+
+ // Overridden from NativeWidget
+ virtual gfx::AcceleratedWidget GetAcceleratedWidget() OVERRIDE;
CHROMEGTK_CALLBACK_1(WidgetGtk, gboolean, OnWindowPaint, GdkEventExpose*);
diff --git a/views/widget/widget_win.cc b/views/widget/widget_win.cc
index 657ece9..823f7d4 100644
--- a/views/widget/widget_win.cc
+++ b/views/widget/widget_win.cc
@@ -820,7 +820,7 @@ LRESULT WidgetWin::OnNotify(int w_param, NMHDR* l_param) {
void WidgetWin::OnPaint(HDC dc) {
scoped_ptr<gfx::CanvasPaint> canvas(
gfx::CanvasPaint::CreateCanvasPaint(hwnd()));
- GetRootView()->Paint(canvas->AsCanvas());
+ delegate_->OnPaint(canvas->AsCanvas());
}
LRESULT WidgetWin::OnPowerBroadcast(DWORD power_event, DWORD data) {
@@ -1123,6 +1123,11 @@ void WidgetWin::ClientAreaSizeChanged() {
}
}
+gfx::AcceleratedWidget WidgetWin::GetAcceleratedWidget() {
+ NOTIMPLEMENTED();
+ return gfx::kNullAcceleratedWidget;
+}
+
////////////////////////////////////////////////////////////////////////////////
// Widget, public:
diff --git a/views/widget/widget_win.h b/views/widget/widget_win.h
index ba78268..9779bd8 100644
--- a/views/widget/widget_win.h
+++ b/views/widget/widget_win.h
@@ -456,6 +456,9 @@ class WidgetWin : public ui::WindowImpl,
// or subsequently.
void ClientAreaSizeChanged();
+ // Overridden from NativeWidget.
+ virtual gfx::AcceleratedWidget GetAcceleratedWidget() OVERRIDE;
+
// A delegate implementation that handles events received here.
internal::NativeWidgetDelegate* delegate_;