Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(138)

Side by Side Diff: ui/ozone/platform/caca/caca_window.cc

Issue 387953004: ozone: caca: Convert to PlatformWindow (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "ui/ozone/platform/caca/caca_window.h"
6
7 #include "base/bind.h"
8 #include "base/debug/trace_event.h"
9 #include "base/logging.h"
10 #include "base/message_loop/message_loop.h"
11 #include "ui/ozone/platform/caca/caca_event_factory.h"
12 #include "ui/ozone/platform/caca/caca_window_manager.h"
13 #include "ui/window/platform_window_delegate.h"
14
15 namespace ui {
16
17 namespace {
18
19 // Size of initial cnavas (in characters).
20 const int kDefaultCanvasWidth = 160;
21 const int kDefaultCanvasHeight = 48;
22
23 } // namespace
24
25 // TODO(dnicoara) As an optimization, |bitmap_size_| should be scaled based on
26 // |physical_size_| and font size.
27 CacaWindow::CacaWindow(PlatformWindowDelegate* delegate,
28 CacaWindowManager* manager,
29 CacaEventFactory* event_factory,
30 const gfx::Rect& bounds)
31 : delegate_(delegate),
32 manager_(manager),
33 event_factory_(event_factory),
34 weak_ptr_factory_(this) {
35 widget_ = manager_->AddWindow(this);
36 }
37
38 CacaWindow::~CacaWindow() {
39 manager_->RemoveWindow(widget_, this);
40 }
41
42 bool CacaWindow::Initialize() {
43 if (display_)
44 return true;
45
46 canvas_.reset(caca_create_canvas(kDefaultCanvasWidth, kDefaultCanvasHeight));
47 if (!canvas_) {
48 PLOG(ERROR) << "failed to create libcaca canvas";
49 return false;
50 }
51
52 display_.reset(caca_create_display(canvas_.get()));
53 if (!display_) {
54 PLOG(ERROR) << "failed to initialize libcaca display";
55 return false;
56 }
57
58 caca_set_cursor(display_.get(), 1);
59 caca_set_display_title(display_.get(), "Ozone Content Shell");
60
61 UpdateDisplaySize();
62
63 TryProcessingEvent();
64
65 return true;
66 }
67
68 virtual gfx::AcceleratedWidget CacaWindow::GetAcceleratedWidget() {
69 return widget_;
70 }
71
72 virtual gfx::Rect GetBounds() const {
73 return gfx::Rect(bitmap_size_);
74 }
75
76 void CacaWindow::TryProcessingEvent() {
77 event_factory_->TryProcessingEvent(this, delegate_);
78
79 // Caca uses a poll based event retrieval. Since we don't want to block we'd
80 // either need to spin up a new thread or just poll. For simplicity just poll
81 // for a message every |delay_| time delta.
dnicoara 2014/07/17 17:27:54 nit: Replace |delay_| with 10ms ... or just make t
spang 2014/07/17 19:50:41 Done.
82 base::MessageLoop::current()->PostDelayedTask(
83 FROM_HERE,
84 base::Bind(&CacaWindow::TryProcessingEvent,
85 weak_ptr_factory_.GetWeakPtr()),
86 base::TimeDelta::FromMilliseconds(10));
87 }
88
89 void CacaWindow::UpdateDisplaySize() {
90 physical_size_.SetSize(caca_get_canvas_width(canvas_.get()),
91 caca_get_canvas_height(canvas_.get()));
92
93 bitmap_size_.SetSize(caca_get_display_width(display_.get()),
94 caca_get_display_height(display_.get()));
95 }
96
97 void CacaWindow::OnCacaResize() {
98 UpdateDisplaySize();
99
100 delegate_->OnBoundsChanged(gfx::Rect(bitmap_size_));
101 }
102
103 void CacaWindow::OnCacaQuit() {
104 delegate_->OnCloseRequest();
105 }
106
107 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698