Commit b794b3fa authored by dnicoara@chromium.org's avatar dnicoara@chromium.org

[Ozone-DRI] Migrate cursor to using ScanoutBuffer

BUG=none
NOTRY=true

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@284176 0039d316-1c4b-4281-b951-d872f2087c98
parent 6627e73f
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "third_party/skia/include/core/SkDevice.h" #include "third_party/skia/include/core/SkDevice.h"
#include "third_party/skia/include/core/SkSurface.h" #include "third_party/skia/include/core/SkSurface.h"
#include "ui/gfx/native_widget_types.h" #include "ui/gfx/native_widget_types.h"
#include "ui/ozone/platform/dri/dri_buffer.h"
#include "ui/ozone/platform/dri/dri_surface.h" #include "ui/ozone/platform/dri/dri_surface.h"
#include "ui/ozone/platform/dri/dri_util.h" #include "ui/ozone/platform/dri/dri_util.h"
#include "ui/ozone/platform/dri/dri_vsync_provider.h" #include "ui/ozone/platform/dri/dri_vsync_provider.h"
...@@ -27,12 +28,12 @@ namespace { ...@@ -27,12 +28,12 @@ namespace {
// TODO(dnicoara) Read the cursor plane size from the hardware. // TODO(dnicoara) Read the cursor plane size from the hardware.
const gfx::Size kCursorSize(64, 64); const gfx::Size kCursorSize(64, 64);
void UpdateCursorImage(DriSurface* cursor, const SkBitmap& image) { void UpdateCursorImage(DriBuffer* cursor, const SkBitmap& image) {
SkRect damage; SkRect damage;
image.getBounds(&damage); image.getBounds(&damage);
// Clear to transparent in case |image| is smaller than the canvas. // Clear to transparent in case |image| is smaller than the canvas.
SkCanvas* canvas = cursor->GetDrawableForWidget(); SkCanvas* canvas = cursor->GetCanvas();
canvas->clear(SK_ColorTRANSPARENT); canvas->clear(SK_ColorTRANSPARENT);
SkRect clip; SkRect clip;
...@@ -120,7 +121,8 @@ DriSurfaceFactory::DriSurfaceFactory(DriWrapper* drm, ...@@ -120,7 +121,8 @@ DriSurfaceFactory::DriSurfaceFactory(DriWrapper* drm,
: drm_(drm), : drm_(drm),
screen_manager_(screen_manager), screen_manager_(screen_manager),
state_(UNINITIALIZED), state_(UNINITIALIZED),
allocated_widgets_(0) { allocated_widgets_(0),
cursor_frontbuffer_(0) {
} }
DriSurfaceFactory::~DriSurfaceFactory() { DriSurfaceFactory::~DriSurfaceFactory() {
...@@ -138,12 +140,16 @@ ui::SurfaceFactoryOzone::HardwareState DriSurfaceFactory::InitializeHardware() { ...@@ -138,12 +140,16 @@ ui::SurfaceFactoryOzone::HardwareState DriSurfaceFactory::InitializeHardware() {
return state_; return state_;
} }
cursor_surface_.reset(CreateSurface(kCursorSize)); SkImageInfo info = SkImageInfo::MakeN32Premul(kCursorSize.width(),
if (!cursor_surface_->Initialize()) { kCursorSize.height());
LOG(ERROR) << "Failed to initialize cursor surface"; for (size_t i = 0; i < arraysize(cursor_buffers_); ++i) {
cursor_buffers_[i] = new DriBuffer(drm_);
if (!cursor_buffers_[i]->Initialize(info)) {
LOG(ERROR) << "Failed to initialize cursor buffer";
state_ = FAILED; state_ = FAILED;
return state_; return state_;
} }
}
state_ = INITIALIZED; state_ = INITIALIZED;
return state_; return state_;
...@@ -216,22 +222,20 @@ void DriSurfaceFactory::MoveHardwareCursor(gfx::AcceleratedWidget window, ...@@ -216,22 +222,20 @@ void DriSurfaceFactory::MoveHardwareCursor(gfx::AcceleratedWidget window,
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// DriSurfaceFactory private // DriSurfaceFactory private
DriSurface* DriSurfaceFactory::CreateSurface(const gfx::Size& size) {
return new DriSurface(drm_, size);
}
void DriSurfaceFactory::ResetCursor(gfx::AcceleratedWidget w) { void DriSurfaceFactory::ResetCursor(gfx::AcceleratedWidget w) {
base::WeakPtr<HardwareDisplayController> controller = base::WeakPtr<HardwareDisplayController> controller =
screen_manager_->GetDisplayController(w); screen_manager_->GetDisplayController(w);
if (!cursor_bitmap_.empty()) { if (!cursor_bitmap_.empty()) {
// Draw new cursor into backbuffer. // Draw new cursor into backbuffer.
UpdateCursorImage(cursor_surface_.get(), cursor_bitmap_); UpdateCursorImage(cursor_buffers_[cursor_frontbuffer_ ^ 1].get(),
cursor_bitmap_);
// Reset location & buffer. // Reset location & buffer.
if (controller) { if (controller) {
controller->MoveCursor(cursor_location_); controller->MoveCursor(cursor_location_);
controller->SetCursor(cursor_surface_.get()); controller->SetCursor(cursor_buffers_[cursor_frontbuffer_ ^ 1]);
cursor_frontbuffer_ ^= 1;
} }
} else { } else {
// No cursor set. // No cursor set.
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
namespace ui { namespace ui {
class DriSurface; class DriBuffer;
class DriWrapper; class DriWrapper;
class HardwareDisplayController; class HardwareDisplayController;
class ScreenManager; class ScreenManager;
...@@ -57,8 +57,6 @@ class DriSurfaceFactory : public ui::SurfaceFactoryOzone, ...@@ -57,8 +57,6 @@ class DriSurfaceFactory : public ui::SurfaceFactoryOzone,
// Draw the last set cursor & update the cursor plane. // Draw the last set cursor & update the cursor plane.
void ResetCursor(gfx::AcceleratedWidget w); void ResetCursor(gfx::AcceleratedWidget w);
virtual DriSurface* CreateSurface(const gfx::Size& size);
DriWrapper* drm_; // Not owned. DriWrapper* drm_; // Not owned.
ScreenManager* screen_manager_; // Not owned. ScreenManager* screen_manager_; // Not owned.
HardwareState state_; HardwareState state_;
...@@ -66,7 +64,8 @@ class DriSurfaceFactory : public ui::SurfaceFactoryOzone, ...@@ -66,7 +64,8 @@ class DriSurfaceFactory : public ui::SurfaceFactoryOzone,
// Active outputs. // Active outputs.
int allocated_widgets_; int allocated_widgets_;
scoped_ptr<DriSurface> cursor_surface_; scoped_refptr<DriBuffer> cursor_buffers_[2];
int cursor_frontbuffer_;
SkBitmap cursor_bitmap_; SkBitmap cursor_bitmap_;
gfx::Point cursor_location_; gfx::Point cursor_location_;
......
...@@ -198,15 +198,14 @@ ScopedDrmPropertyBlobPtr DriWrapper::GetPropertyBlob( ...@@ -198,15 +198,14 @@ ScopedDrmPropertyBlobPtr DriWrapper::GetPropertyBlob(
bool DriWrapper::SetCursor(uint32_t crtc_id, bool DriWrapper::SetCursor(uint32_t crtc_id,
uint32_t handle, uint32_t handle,
uint32_t width, const gfx::Size& size) {
uint32_t height) {
CHECK(fd_ >= 0); CHECK(fd_ >= 0);
return !drmModeSetCursor(fd_, crtc_id, handle, width, height); return !drmModeSetCursor(fd_, crtc_id, handle, size.width(), size.height());
} }
bool DriWrapper::MoveCursor(uint32_t crtc_id, int x, int y) { bool DriWrapper::MoveCursor(uint32_t crtc_id, const gfx::Point& point) {
CHECK(fd_ >= 0); CHECK(fd_ >= 0);
return !drmModeMoveCursor(fd_, crtc_id, x, y); return !drmModeMoveCursor(fd_, crtc_id, point.x(), point.y());
} }
void DriWrapper::HandleEvent(drmEventContext& event) { void DriWrapper::HandleEvent(drmEventContext& event) {
......
...@@ -104,12 +104,11 @@ class DriWrapper { ...@@ -104,12 +104,11 @@ class DriWrapper {
// cursor size pointed by |handle|. // cursor size pointed by |handle|.
virtual bool SetCursor(uint32_t crtc_id, virtual bool SetCursor(uint32_t crtc_id,
uint32_t handle, uint32_t handle,
uint32_t width, const gfx::Size& size);
uint32_t height);
// Move the cursor on CRTC |crtc_id| to (x, y); // Move the cursor on CRTC |crtc_id| to (x, y);
virtual bool MoveCursor(uint32_t crtc_id, int x, int y); virtual bool MoveCursor(uint32_t crtc_id, const gfx::Point& point);
virtual void HandleEvent(drmEventContext& event); virtual void HandleEvent(drmEventContext& event);
......
...@@ -202,24 +202,24 @@ void HardwareDisplayController::OnPageFlipEvent(unsigned int frame, ...@@ -202,24 +202,24 @@ void HardwareDisplayController::OnPageFlipEvent(unsigned int frame,
surface_->SwapBuffers(); surface_->SwapBuffers();
} }
bool HardwareDisplayController::SetCursor(ScanoutSurface* surface) { bool HardwareDisplayController::SetCursor(scoped_refptr<ScanoutBuffer> buffer) {
bool ret = drm_->SetCursor(crtc_id_, bool ret = drm_->SetCursor(crtc_id_,
surface->GetHandle(), buffer->GetHandle(),
surface->Size().width(), buffer->GetSize());
surface->Size().height()); cursor_buffer_ = buffer;
surface->SwapBuffers();
return ret; return ret;
} }
bool HardwareDisplayController::UnsetCursor() { bool HardwareDisplayController::UnsetCursor() {
return drm_->SetCursor(crtc_id_, 0, 0, 0); cursor_buffer_ = NULL;
return drm_->SetCursor(crtc_id_, 0, gfx::Size());
} }
bool HardwareDisplayController::MoveCursor(const gfx::Point& location) { bool HardwareDisplayController::MoveCursor(const gfx::Point& location) {
if (is_disabled_) if (is_disabled_)
return true; return true;
return drm_->MoveCursor(crtc_id_, location.x(), location.y()); return drm_->MoveCursor(crtc_id_, location);
} }
} // namespace ui } // namespace ui
...@@ -22,6 +22,7 @@ class Point; ...@@ -22,6 +22,7 @@ class Point;
namespace ui { namespace ui {
class NativePixmap; class NativePixmap;
class ScanoutBuffer;
class ScanoutSurface; class ScanoutSurface;
typedef std::vector<scoped_refptr<NativePixmap> > NativePixmapList; typedef std::vector<scoped_refptr<NativePixmap> > NativePixmapList;
...@@ -150,7 +151,7 @@ class HardwareDisplayController ...@@ -150,7 +151,7 @@ class HardwareDisplayController
unsigned int useconds); unsigned int useconds);
// Set the hardware cursor to show the contents of |surface|. // Set the hardware cursor to show the contents of |surface|.
bool SetCursor(ScanoutSurface* surface); bool SetCursor(scoped_refptr<ScanoutBuffer> buffer);
bool UnsetCursor(); bool UnsetCursor();
...@@ -187,6 +188,8 @@ class HardwareDisplayController ...@@ -187,6 +188,8 @@ class HardwareDisplayController
scoped_ptr<ScanoutSurface> surface_; scoped_ptr<ScanoutSurface> surface_;
scoped_refptr<ScanoutBuffer> cursor_buffer_;
uint64_t time_of_last_flip_; uint64_t time_of_last_flip_;
// Keeps track of the CRTC state. If a surface has been bound, then the value // Keeps track of the CRTC state. If a surface has been bound, then the value
......
...@@ -110,12 +110,11 @@ ScopedDrmPropertyBlobPtr MockDriWrapper::GetPropertyBlob( ...@@ -110,12 +110,11 @@ ScopedDrmPropertyBlobPtr MockDriWrapper::GetPropertyBlob(
bool MockDriWrapper::SetCursor(uint32_t crtc_id, bool MockDriWrapper::SetCursor(uint32_t crtc_id,
uint32_t handle, uint32_t handle,
uint32_t width, const gfx::Size& size) {
uint32_t height) {
return true; return true;
} }
bool MockDriWrapper::MoveCursor(uint32_t crtc_id, int x, int y) { bool MockDriWrapper::MoveCursor(uint32_t crtc_id, const gfx::Point& point) {
return true; return true;
} }
......
...@@ -75,9 +75,8 @@ class MockDriWrapper : public ui::DriWrapper { ...@@ -75,9 +75,8 @@ class MockDriWrapper : public ui::DriWrapper {
const char* name) OVERRIDE; const char* name) OVERRIDE;
virtual bool SetCursor(uint32_t crtc_id, virtual bool SetCursor(uint32_t crtc_id,
uint32_t handle, uint32_t handle,
uint32_t width, const gfx::Size& size) OVERRIDE;
uint32_t height) OVERRIDE; virtual bool MoveCursor(uint32_t crtc_id, const gfx::Point& point) OVERRIDE;
virtual bool MoveCursor(uint32_t crtc_id, int x, int y) OVERRIDE;
virtual void HandleEvent(drmEventContext& event) OVERRIDE; virtual void HandleEvent(drmEventContext& event) OVERRIDE;
virtual bool CreateDumbBuffer(const SkImageInfo& info, virtual bool CreateDumbBuffer(const SkImageInfo& info,
uint32_t* handle, uint32_t* handle,
......
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