| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "aura/window.h" | 5 #include "aura/window.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "aura/desktop.h" | 9 #include "aura/desktop.h" |
| 10 #include "aura/window_delegate.h" | 10 #include "aura/window_delegate.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "ui/gfx/canvas_skia.h" | 12 #include "third_party/skia/include/core/SkCanvas.h" |
| 13 #include "ui/gfx/compositor/compositor.h" | 13 #include "ui/gfx/compositor/compositor.h" |
| 14 #include "ui/gfx/compositor/layer.h" | 14 #include "ui/gfx/compositor/layer.h" |
| 15 | 15 |
| 16 namespace aura { | 16 namespace aura { |
| 17 | 17 |
| 18 Window::Window(WindowDelegate* delegate) | 18 // TODO: do we need to support child windows? |
| 19 : delegate_(delegate), | 19 Window::Window(Desktop* desktop) |
| 20 : delegate_(NULL), |
| 20 visibility_(VISIBILITY_HIDDEN), | 21 visibility_(VISIBILITY_HIDDEN), |
| 22 layer_(new ui::Layer(desktop->compositor())), |
| 21 needs_paint_all_(true), | 23 needs_paint_all_(true), |
| 22 parent_(NULL), | 24 parent_(NULL), |
| 23 id_(-1) { | 25 id_(-1) { |
| 24 } | 26 } |
| 25 | 27 |
| 26 Window::~Window() { | 28 Window::~Window() { |
| 27 } | 29 } |
| 28 | 30 |
| 29 void Window::Init() { | |
| 30 layer_.reset(new ui::Layer(Desktop::GetInstance()->compositor())); | |
| 31 } | |
| 32 | |
| 33 void Window::SetVisibility(Visibility visibility) { | 31 void Window::SetVisibility(Visibility visibility) { |
| 34 if (visibility_ == visibility) | 32 if (visibility_ == visibility) |
| 35 return; | 33 return; |
| 36 | 34 |
| 37 visibility_ = visibility; | 35 visibility_ = visibility; |
| 38 } | 36 } |
| 39 | 37 |
| 40 void Window::SetBounds(const gfx::Rect& bounds, int anim_ms) { | 38 void Window::SetBounds(const gfx::Rect& bounds, int anim_ms) { |
| 41 // TODO: support anim_ms | 39 // TODO: support anim_ms |
| 42 // TODO: funnel this through the Desktop. | 40 // TODO: funnel this through the Desktop. |
| 43 bounds_ = bounds; | 41 bounds_ = bounds; |
| 44 layer_->SetBounds(bounds); | 42 layer_->SetBounds(bounds); |
| 45 } | 43 } |
| 46 | 44 |
| 47 void Window::SchedulePaint(const gfx::Rect& bounds) { | 45 void Window::SchedulePaint(const gfx::Rect& bounds) { |
| 48 if (dirty_rect_.IsEmpty()) | 46 if (dirty_rect_.IsEmpty()) |
| 49 dirty_rect_ = bounds; | 47 dirty_rect_ = bounds; |
| 50 else | 48 else |
| 51 dirty_rect_ = dirty_rect_.Union(bounds); | 49 dirty_rect_ = dirty_rect_.Union(bounds); |
| 52 } | 50 } |
| 53 | 51 |
| 54 void Window::SetCanvas(const SkCanvas& canvas, const gfx::Point& origin) { | 52 void Window::SetCanvas(const SkCanvas& canvas, const gfx::Point& origin) { |
| 55 // TODO: figure out how this is going to work when animating the layer. In | 53 // TODO: figure out how this is going to work when animating the layer. In |
| 56 // particular if we're animating the size then the underlying Texture is going | 54 // particular if we're animating the size then the underyling Texture is going |
| 57 // to be unhappy if we try to set a texture on a size bigger than the size of | 55 // to be unhappy if we try to set a texture on a size bigger than the size of |
| 58 // the texture. | 56 // the texture. |
| 59 layer_->SetCanvas(canvas, origin); | 57 layer_->SetCanvas(canvas, origin); |
| 60 } | 58 } |
| 61 | 59 |
| 62 void Window::SetParent(Window* parent) { | |
| 63 if (parent) | |
| 64 parent->AddChild(this); | |
| 65 else | |
| 66 Desktop::GetInstance()->window()->AddChild(this); | |
| 67 } | |
| 68 | |
| 69 void Window::DrawTree() { | 60 void Window::DrawTree() { |
| 70 UpdateLayerCanvas(); | 61 UpdateLayerCanvas(); |
| 71 Draw(); | 62 Draw(); |
| 72 | 63 |
| 73 // First pass updates the layer bitmaps. | 64 // First pass updates the layer bitmaps. |
| 74 for (Windows::iterator i = children_.begin(); i != children_.end(); ++i) | 65 for (Windows::iterator i = children_.begin(); i != children_.end(); ++i) |
| 75 (*i)->DrawTree(); | 66 (*i)->DrawTree(); |
| 76 } | 67 } |
| 77 | 68 |
| 78 void Window::AddChild(Window* child) { | 69 void Window::AddChild(Window* child) { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 98 void Window::UpdateLayerCanvas() { | 89 void Window::UpdateLayerCanvas() { |
| 99 if (needs_paint_all_) { | 90 if (needs_paint_all_) { |
| 100 needs_paint_all_ = false; | 91 needs_paint_all_ = false; |
| 101 dirty_rect_ = gfx::Rect(0, 0, bounds().width(), bounds().height()); | 92 dirty_rect_ = gfx::Rect(0, 0, bounds().width(), bounds().height()); |
| 102 } | 93 } |
| 103 gfx::Rect dirty_rect = dirty_rect_.Intersect( | 94 gfx::Rect dirty_rect = dirty_rect_.Intersect( |
| 104 gfx::Rect(0, 0, bounds().width(), bounds().height())); | 95 gfx::Rect(0, 0, bounds().width(), bounds().height())); |
| 105 dirty_rect_.SetRect(0, 0, 0, 0); | 96 dirty_rect_.SetRect(0, 0, 0, 0); |
| 106 if (dirty_rect.IsEmpty()) | 97 if (dirty_rect.IsEmpty()) |
| 107 return; | 98 return; |
| 108 if (delegate_) { | 99 if (delegate_) |
| 109 scoped_ptr<gfx::Canvas> canvas(gfx::Canvas::CreateCanvas( | 100 delegate_->OnPaint(dirty_rect); |
| 110 dirty_rect.width(), dirty_rect.height(), false)); | |
| 111 canvas->TranslateInt(dirty_rect.x(), dirty_rect.y()); | |
| 112 delegate_->OnPaint(canvas.get()); | |
| 113 SetCanvas(*canvas->AsCanvasSkia(), bounds().origin()); | |
| 114 } | |
| 115 } | 101 } |
| 116 | 102 |
| 117 void Window::Draw() { | 103 void Window::Draw() { |
| 118 if (visibility_ != VISIBILITY_HIDDEN) | 104 if (visibility_ != VISIBILITY_HIDDEN) |
| 119 layer_->Draw(); | 105 layer_->Draw(); |
| 120 } | 106 } |
| 121 | 107 |
| 122 } // namespace aura | 108 } // namespace aura |
| OLD | NEW |