Commit 8ec3fe31 authored by spang@chromium.org's avatar spang@chromium.org

ozone: caca: Preparatory work for resize / multiple windows

Let's let caca decide the bitmap size. Also scopify caca objects.

BUG=none
TEST=use_ozone=1 chromeos=1 caca build
NOTRY=true

Review URL: https://codereview.chromium.org/387993002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@282970 0039d316-1c4b-4281-b951-d872f2087c98
parent 836930b8
...@@ -39,6 +39,8 @@ ...@@ -39,6 +39,8 @@
'caca_surface_factory.h', 'caca_surface_factory.h',
'ozone_platform_caca.cc', 'ozone_platform_caca.cc',
'ozone_platform_caca.h', 'ozone_platform_caca.h',
'scoped_caca_types.cc',
'scoped_caca_types.h',
], ],
}, },
], ],
......
...@@ -8,33 +8,50 @@ ...@@ -8,33 +8,50 @@
namespace ui { namespace ui {
// TODO(dnicoara) As an optimization, |bitmap_size_| should be scaled based on namespace {
// |physical_size_| and font size.
CacaConnection::CacaConnection() // Size of initial cnavas (in characters).
: canvas_(NULL), const int kDefaultCanvasWidth = 160;
display_(NULL), const int kDefaultCanvasHeight = 48;
physical_size_(160, 48),
bitmap_size_(800, 600) {} } // namespace
CacaConnection::CacaConnection() {
}
CacaConnection::~CacaConnection() { CacaConnection::~CacaConnection() {
if (display_) {
caca_free_display(display_);
caca_free_canvas(canvas_);
}
} }
void CacaConnection::Initialize() { bool CacaConnection::Initialize() {
if (display_) if (display_)
return; 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;
}
canvas_ = caca_create_canvas(physical_size_.width(), physical_size_.height()); caca_set_cursor(display_.get(), 1);
display_ = caca_create_display(canvas_); caca_set_display_title(display_.get(), "Ozone Content Shell");
UpdateDisplaySize();
return true;
}
physical_size_.SetSize(caca_get_canvas_width(canvas_), void CacaConnection::UpdateDisplaySize() {
caca_get_canvas_height(canvas_)); physical_size_.SetSize(caca_get_canvas_width(canvas_.get()),
caca_get_canvas_height(canvas_.get()));
caca_set_cursor(display_, 1); bitmap_size_.SetSize(caca_get_display_width(display_.get()),
caca_set_display_title(display_, "Ozone Content Shell"); caca_get_display_height(display_.get()));
} }
} // namespace ui } // namespace ui
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "base/macros.h" #include "base/macros.h"
#include "ui/gfx/geometry/size.h" #include "ui/gfx/geometry/size.h"
#include "ui/ozone/platform/caca/scoped_caca_types.h"
namespace ui { namespace ui {
...@@ -21,16 +22,19 @@ class CacaConnection { ...@@ -21,16 +22,19 @@ class CacaConnection {
CacaConnection(); CacaConnection();
~CacaConnection(); ~CacaConnection();
void Initialize(); bool Initialize();
// This is the Caca canvas size. // This is the Caca canvas size.
gfx::Size physical_size() const { return physical_size_; } gfx::Size physical_size() const { return physical_size_; }
gfx::Size bitmap_size() const { return bitmap_size_; } gfx::Size bitmap_size() const { return bitmap_size_; }
caca_display_t* display() const { return display_; } caca_display_t* display() const { return display_.get(); }
private: private:
caca_canvas_t* canvas_; // Sync sizes with libcaca.
caca_display_t* display_; void UpdateDisplaySize();
ScopedCacaCanvas canvas_;
ScopedCacaDisplay display_;
// Size of the console in characters. This can be changed by setting // Size of the console in characters. This can be changed by setting
// CACA_GEOMETRY environment variable. // CACA_GEOMETRY environment variable.
......
// 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/scoped_caca_types.h"
#include <caca.h>
namespace ui {
void CacaCanvasDeleter::operator()(caca_canvas_t* canvas) const {
caca_free_canvas(canvas);
}
void CacaDisplayDeleter::operator()(caca_display_t* display) const {
caca_free_display(display);
}
void CacaDitherDeleter::operator()(caca_dither_t* dither) const {
caca_free_dither(dither);
}
} // namespace ui
// 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.
#ifndef UI_OZONE_PLATFORM_CACA_SCOPED_CACA_TYPES_H_
#define UI_OZONE_PLATFORM_CACA_SCOPED_CACA_TYPES_H_
#include "base/memory/scoped_ptr.h"
typedef struct caca_canvas caca_canvas_t;
typedef struct caca_dither caca_dither_t;
typedef struct caca_display caca_display_t;
namespace ui {
struct CacaCanvasDeleter {
void operator()(caca_canvas_t* canvas) const;
};
struct CacaDisplayDeleter {
void operator()(caca_display_t* display) const;
};
struct CacaDitherDeleter {
void operator()(caca_dither_t* dither) const;
};
typedef scoped_ptr<caca_canvas_t, CacaCanvasDeleter> ScopedCacaCanvas;
typedef scoped_ptr<caca_display_t, CacaDisplayDeleter> ScopedCacaDisplay;
typedef scoped_ptr<caca_dither_t, CacaDitherDeleter> ScopedCacaDither;
} // namespace ui
#endif // UI_OZONE_PLATFORM_CACA_SCOPED_CACA_TYPES_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment