summaryrefslogtreecommitdiffstats
path: root/aura
diff options
context:
space:
mode:
authorben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-08-25 22:35:13 +0000
committerben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-08-25 22:35:13 +0000
commit8d8c773c297d22dbf01e2bbb69b7335f52208845 (patch)
treed45e8affaa57b2dd2516e14c03c3a5f9238247f0 /aura
parent93543752960447decfc8f0ca38ef9f44f7209cfd (diff)
downloadchromium_src-8d8c773c297d22dbf01e2bbb69b7335f52208845.zip
chromium_src-8d8c773c297d22dbf01e2bbb69b7335f52208845.tar.gz
chromium_src-8d8c773c297d22dbf01e2bbb69b7335f52208845.tar.bz2
Re-land: Create a new views_aura_desktop.
Get views::Widget rendering working against an aura::Window NativeWidget. http://crbug.com/93944 TEST=none Original review URL: http://codereview.chromium.org/7741027 Review URL: http://codereview.chromium.org/7747032 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@98331 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'aura')
-rw-r--r--aura/demo/demo_main.cc62
-rw-r--r--aura/desktop.cc29
-rw-r--r--aura/desktop.h12
-rw-r--r--aura/window.cc30
-rw-r--r--aura/window.h14
-rw-r--r--aura/window_delegate.h9
6 files changed, 95 insertions, 61 deletions
diff --git a/aura/demo/demo_main.cc b/aura/demo/demo_main.cc
index e8ef169..09cfc29 100644
--- a/aura/demo/demo_main.cc
+++ b/aura/demo/demo_main.cc
@@ -3,14 +3,12 @@
// found in the LICENSE file.
#include "aura/desktop.h"
-#include "aura/desktop_host.h"
#include "aura/window.h"
#include "aura/window_delegate.h"
#include "base/at_exit.h"
#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"
@@ -20,32 +18,21 @@
namespace {
-// Trivial WindowDelegate implementation that draws a blue background.
+// Trivial WindowDelegate implementation that draws a colored background.
class DemoWindowDelegate : public aura::WindowDelegate {
public:
- explicit DemoWindowDelegate(aura::Window* window, SkColor color);
+ explicit DemoWindowDelegate(SkColor color) : color_(color) {}
- virtual void OnPaint(const gfx::Rect& bounds) OVERRIDE;
+ virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE {
+ canvas->AsCanvasSkia()->drawColor(color_, SkXfermode::kSrc_Mode);
+ }
private:
- aura::Window* window_;
-
SkColor color_;
DISALLOW_COPY_AND_ASSIGN(DemoWindowDelegate);
};
-DemoWindowDelegate::DemoWindowDelegate(aura::Window* window, SkColor color)
- : window_(window),
- color_(color) {
-}
-
-void DemoWindowDelegate::OnPaint(const gfx::Rect& bounds) {
- scoped_ptr<gfx::Canvas> canvas(
- gfx::Canvas::CreateCanvas(bounds.width(), bounds.height(), false));
- canvas->AsCanvasSkia()->drawColor(color_, SkXfermode::kSrc_Mode);
- window_->SetCanvas(*canvas->AsCanvasSkia(), bounds.origin());
-}
} // namespace
@@ -63,43 +50,34 @@ int main(int argc, char** argv) {
base::MessagePumpX::DisableGtkMessagePump();
#endif
- // Create the DesktopHost and Desktop.
- scoped_ptr<aura::DesktopHost> host(
- aura::DesktopHost::Create(gfx::Rect(200, 200, 1024, 768)));
- aura::Desktop desktop(host->GetAcceleratedWidget(), host->GetSize());
- host->SetDesktop(&desktop);
+ aura::Desktop::GetInstance();
// Create a hierarchy of test windows.
- aura::Window window1(&desktop);
+ DemoWindowDelegate window_delegate1(SK_ColorBLUE);
+ aura::Window window1(&window_delegate1);
window1.set_id(1);
+ window1.Init();
window1.SetBounds(gfx::Rect(100, 100, 400, 400), 0);
window1.SetVisibility(aura::Window::VISIBILITY_SHOWN);
- DemoWindowDelegate window_delegate1(&window1, SK_ColorBLUE);
- window1.set_delegate(&window_delegate1);
-
- desktop.window()->AddChild(&window1);
+ window1.SetParent(NULL);
- aura::Window window2(&desktop);
+ DemoWindowDelegate window_delegate2(SK_ColorRED);
+ aura::Window window2(&window_delegate2);
window2.set_id(2);
+ window2.Init();
window2.SetBounds(gfx::Rect(200, 200, 350, 350), 0);
window2.SetVisibility(aura::Window::VISIBILITY_SHOWN);
- DemoWindowDelegate window_delegate2(&window2, SK_ColorRED);
- window2.set_delegate(&window_delegate2);
+ window2.SetParent(NULL);
- desktop.window()->AddChild(&window2);
-
- aura::Window window3(&desktop);
+ DemoWindowDelegate window_delegate3(SK_ColorGREEN);
+ aura::Window window3(&window_delegate3);
window3.set_id(3);
+ window3.Init();
window3.SetBounds(gfx::Rect(10, 10, 50, 50), 0);
window3.SetVisibility(aura::Window::VISIBILITY_SHOWN);
- DemoWindowDelegate window_delegate3(&window3, SK_ColorGREEN);
- window3.set_delegate(&window_delegate3);
-
- window2.AddChild(&window3);
+ window3.SetParent(&window2);
- host->Show();
-
- MessageLoop main_message_loop(MessageLoop::TYPE_UI);
- MessageLoopForUI::current()->Run(host.get());
+ aura::Desktop::GetInstance()->Run();
return 0;
}
+
diff --git a/aura/desktop.cc b/aura/desktop.cc
index 00b130f..f427daf 100644
--- a/aura/desktop.cc
+++ b/aura/desktop.cc
@@ -4,21 +4,35 @@
#include "aura/desktop.h"
+#include "aura/desktop_host.h"
#include "aura/window.h"
#include "base/logging.h"
+#include "base/message_loop.h"
#include "ui/gfx/compositor/compositor.h"
namespace aura {
-Desktop::Desktop(gfx::AcceleratedWidget widget, const gfx::Size& size)
- : compositor_(ui::Compositor::Create(widget, size)) {
+// static
+Desktop* Desktop::instance_ = NULL;
+
+Desktop::Desktop()
+ : host_(aura::DesktopHost::Create(gfx::Rect(200, 200, 1024, 768))) {
+ compositor_ = ui::Compositor::Create(host_->GetAcceleratedWidget(),
+ host_->GetSize());
+ host_->SetDesktop(this);
DCHECK(compositor_.get());
- window_.reset(new Window(this));
+ window_.reset(new Window(NULL));
}
Desktop::~Desktop() {
}
+void Desktop::Run() {
+ host_->Show();
+ MessageLoop main_message_loop(MessageLoop::TYPE_UI);
+ MessageLoopForUI::current()->Run(host_);
+}
+
void Desktop::Draw() {
// Second pass renders the layers.
compositor_->NotifyStart();
@@ -30,4 +44,13 @@ bool Desktop::OnMouseEvent(const MouseEvent& event) {
return window_->OnMouseEvent(event);
}
+// static
+Desktop* Desktop::GetInstance() {
+ if (!instance_) {
+ instance_ = new Desktop;
+ instance_->window_->Init();
+ }
+ return instance_;
+}
+
} // namespace aura
diff --git a/aura/desktop.h b/aura/desktop.h
index 1eb89ca..a894e24 100644
--- a/aura/desktop.h
+++ b/aura/desktop.h
@@ -21,15 +21,19 @@ class Compositor;
namespace aura {
+class DesktopHost;
class MouseEvent;
class Window;
// Desktop is responsible for hosting a set of windows.
class Desktop {
public:
- Desktop(gfx::AcceleratedWidget widget, const gfx::Size& size);
+ Desktop();
~Desktop();
+ // Shows the desktop host and runs an event loop for it.
+ void Run();
+
// Draws the necessary set of windows.
void Draw();
@@ -41,11 +45,17 @@ class Desktop {
Window* window() { return window_.get(); }
+ static Desktop* GetInstance();
+
private:
scoped_refptr<ui::Compositor> compositor_;
scoped_ptr<Window> window_;
+ DesktopHost* host_;
+
+ static Desktop* instance_;
+
DISALLOW_COPY_AND_ASSIGN(Desktop);
};
diff --git a/aura/window.cc b/aura/window.cc
index 11e9b31..e6f62a8 100644
--- a/aura/window.cc
+++ b/aura/window.cc
@@ -9,17 +9,15 @@
#include "aura/desktop.h"
#include "aura/window_delegate.h"
#include "base/logging.h"
-#include "third_party/skia/include/core/SkCanvas.h"
+#include "ui/gfx/canvas_skia.h"
#include "ui/gfx/compositor/compositor.h"
#include "ui/gfx/compositor/layer.h"
namespace aura {
-// TODO: do we need to support child windows?
-Window::Window(Desktop* desktop)
- : delegate_(NULL),
+Window::Window(WindowDelegate* delegate)
+ : delegate_(delegate),
visibility_(VISIBILITY_HIDDEN),
- layer_(new ui::Layer(desktop->compositor())),
needs_paint_all_(true),
parent_(NULL),
id_(-1) {
@@ -28,6 +26,10 @@ Window::Window(Desktop* desktop)
Window::~Window() {
}
+void Window::Init() {
+ layer_.reset(new ui::Layer(Desktop::GetInstance()->compositor()));
+}
+
void Window::SetVisibility(Visibility visibility) {
if (visibility_ == visibility)
return;
@@ -51,12 +53,19 @@ void Window::SchedulePaint(const gfx::Rect& bounds) {
void Window::SetCanvas(const SkCanvas& canvas, const gfx::Point& origin) {
// TODO: figure out how this is going to work when animating the layer. In
- // particular if we're animating the size then the underyling Texture is going
+ // particular if we're animating the size then the underlying Texture is going
// to be unhappy if we try to set a texture on a size bigger than the size of
// the texture.
layer_->SetCanvas(canvas, origin);
}
+void Window::SetParent(Window* parent) {
+ if (parent)
+ parent->AddChild(this);
+ else
+ Desktop::GetInstance()->window()->AddChild(this);
+}
+
void Window::DrawTree() {
UpdateLayerCanvas();
Draw();
@@ -96,8 +105,13 @@ void Window::UpdateLayerCanvas() {
dirty_rect_.SetRect(0, 0, 0, 0);
if (dirty_rect.IsEmpty())
return;
- if (delegate_)
- delegate_->OnPaint(dirty_rect);
+ if (delegate_) {
+ scoped_ptr<gfx::Canvas> canvas(gfx::Canvas::CreateCanvas(
+ dirty_rect.width(), dirty_rect.height(), false));
+ canvas->TranslateInt(dirty_rect.x(), dirty_rect.y());
+ delegate_->OnPaint(canvas.get());
+ SetCanvas(*canvas->AsCanvasSkia(), bounds().origin());
+ }
}
void Window::Draw() {
diff --git a/aura/window.h b/aura/window.h
index f72b2b6..871ceb6 100644
--- a/aura/window.h
+++ b/aura/window.h
@@ -10,7 +10,6 @@
#include "base/basictypes.h"
#include "base/memory/scoped_ptr.h"
-#include "ui/gfx/native_widget_types.h"
#include "ui/gfx/rect.h"
class SkCanvas;
@@ -42,14 +41,17 @@ class Window {
VISIBILITY_SHOWN_NO_INPUT = 3,
};
- explicit Window(Desktop* desktop);
+ explicit Window(WindowDelegate* delegate);
~Window();
- void set_delegate(WindowDelegate* d) { delegate_ = d; }
+ void Init();
int id() const { return id_; }
void set_id(int id) { id_ = id; }
+ ui::Layer* layer() { return layer_.get(); }
+ const ui::Layer* layer() const { return layer_.get(); }
+
// Changes the visibility of the window.
void SetVisibility(Visibility visibility);
Visibility visibility() const { return visibility_; }
@@ -64,6 +66,11 @@ class Window {
// Sets the contents of the window.
void SetCanvas(const SkCanvas& canvas, const gfx::Point& origin);
+ // Sets the parent window of the window. If NULL, the window is parented to
+ // the desktop's window.
+ void SetParent(Window* parent);
+ Window* parent() { return parent_; }
+
// Draw the window and its children.
void DrawTree();
@@ -72,7 +79,6 @@ class Window {
// should change this.
void AddChild(Window* child);
void RemoveChild(Window* child);
- Window* parent() { return parent_; }
// Handles a mouse event. Returns true if handled.
bool OnMouseEvent(const MouseEvent& event);
diff --git a/aura/window_delegate.h b/aura/window_delegate.h
index 69637cf..ffa3191 100644
--- a/aura/window_delegate.h
+++ b/aura/window_delegate.h
@@ -6,14 +6,17 @@
#define AURA_WINDOW_DELEGATE_H_
#pragma once
+namespace gfx {
+class Canvas;
+}
+
namespace aura {
// Delegate interface for aura::Window.
class WindowDelegate {
public:
- // Asks the delegate to paint to the window. The delegate should call back
- // to the window with SetCanvas.
- virtual void OnPaint(const gfx::Rect& bounds) = 0;
+ // Asks the delegate to paint window contents into the supplied canvas.
+ virtual void OnPaint(gfx::Canvas* canvas) = 0;
protected:
virtual ~WindowDelegate() {}