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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: ui/ozone/platform/caca/caca_window.cc
diff --git a/ui/ozone/platform/caca/caca_window.cc b/ui/ozone/platform/caca/caca_window.cc
new file mode 100644
index 0000000000000000000000000000000000000000..c947b44767b7a21d0ad948dac3815afa3c03af6d
--- /dev/null
+++ b/ui/ozone/platform/caca/caca_window.cc
@@ -0,0 +1,107 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ui/ozone/platform/caca/caca_window.h"
+
+#include "base/bind.h"
+#include "base/debug/trace_event.h"
+#include "base/logging.h"
+#include "base/message_loop/message_loop.h"
+#include "ui/ozone/platform/caca/caca_event_factory.h"
+#include "ui/ozone/platform/caca/caca_window_manager.h"
+#include "ui/window/platform_window_delegate.h"
+
+namespace ui {
+
+namespace {
+
+// Size of initial cnavas (in characters).
+const int kDefaultCanvasWidth = 160;
+const int kDefaultCanvasHeight = 48;
+
+} // namespace
+
+// TODO(dnicoara) As an optimization, |bitmap_size_| should be scaled based on
+// |physical_size_| and font size.
+CacaWindow::CacaWindow(PlatformWindowDelegate* delegate,
+ CacaWindowManager* manager,
+ CacaEventFactory* event_factory,
+ const gfx::Rect& bounds)
+ : delegate_(delegate),
+ manager_(manager),
+ event_factory_(event_factory),
+ weak_ptr_factory_(this) {
+ widget_ = manager_->AddWindow(this);
+}
+
+CacaWindow::~CacaWindow() {
+ manager_->RemoveWindow(widget_, this);
+}
+
+bool CacaWindow::Initialize() {
+ if (display_)
+ return true;
+
+ canvas_.reset(caca_create_canvas(kDefaultCanvasWidth, kDefaultCanvasHeight));
+ if (!canvas_) {
+ PLOG(ERROR) << "failed to create libcaca canvas";
+ return false;
+ }
+
+ display_.reset(caca_create_display(canvas_.get()));
+ if (!display_) {
+ PLOG(ERROR) << "failed to initialize libcaca display";
+ return false;
+ }
+
+ caca_set_cursor(display_.get(), 1);
+ caca_set_display_title(display_.get(), "Ozone Content Shell");
+
+ UpdateDisplaySize();
+
+ TryProcessingEvent();
+
+ return true;
+}
+
+virtual gfx::AcceleratedWidget CacaWindow::GetAcceleratedWidget() {
+ return widget_;
+}
+
+virtual gfx::Rect GetBounds() const {
+ return gfx::Rect(bitmap_size_);
+}
+
+void CacaWindow::TryProcessingEvent() {
+ event_factory_->TryProcessingEvent(this, delegate_);
+
+ // Caca uses a poll based event retrieval. Since we don't want to block we'd
+ // either need to spin up a new thread or just poll. For simplicity just poll
+ // 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.
+ base::MessageLoop::current()->PostDelayedTask(
+ FROM_HERE,
+ base::Bind(&CacaWindow::TryProcessingEvent,
+ weak_ptr_factory_.GetWeakPtr()),
+ base::TimeDelta::FromMilliseconds(10));
+}
+
+void CacaWindow::UpdateDisplaySize() {
+ physical_size_.SetSize(caca_get_canvas_width(canvas_.get()),
+ caca_get_canvas_height(canvas_.get()));
+
+ bitmap_size_.SetSize(caca_get_display_width(display_.get()),
+ caca_get_display_height(display_.get()));
+}
+
+void CacaWindow::OnCacaResize() {
+ UpdateDisplaySize();
+
+ delegate_->OnBoundsChanged(gfx::Rect(bitmap_size_));
+}
+
+void CacaWindow::OnCacaQuit() {
+ delegate_->OnCloseRequest();
+}
+
+} // namespace ui

Powered by Google App Engine
This is Rietveld 408576698