Commit 8e369096 authored by spang's avatar spang Committed by Commit bot

ozone: dri: Implement cursor animation

This adds a timer that steps through the cursor animation.

R=dnicoara
BUG=343245
TEST=viewed css "wait" cursor on cros link_freon
NOTRY=true

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

Cr-Commit-Position: refs/heads/master@{#294183}
parent c179dd06
...@@ -55,7 +55,10 @@ DriSurfaceFactory::DriSurfaceFactory(DriWrapper* drm, ...@@ -55,7 +55,10 @@ DriSurfaceFactory::DriSurfaceFactory(DriWrapper* drm,
screen_manager_(screen_manager), screen_manager_(screen_manager),
window_manager_(window_manager), window_manager_(window_manager),
state_(UNINITIALIZED), state_(UNINITIALIZED),
cursor_frontbuffer_(0) { cursor_frontbuffer_(0),
cursor_widget_(0),
cursor_frame_(0),
cursor_frame_delay_ms_(0) {
} }
DriSurfaceFactory::~DriSurfaceFactory() { DriSurfaceFactory::~DriSurfaceFactory() {
...@@ -96,8 +99,6 @@ void DriSurfaceFactory::ShutdownHardware() { ...@@ -96,8 +99,6 @@ void DriSurfaceFactory::ShutdownHardware() {
scoped_ptr<ui::SurfaceOzoneCanvas> DriSurfaceFactory::CreateCanvasForWidget( scoped_ptr<ui::SurfaceOzoneCanvas> DriSurfaceFactory::CreateCanvasForWidget(
gfx::AcceleratedWidget widget) { gfx::AcceleratedWidget widget) {
DCHECK(state_ == INITIALIZED); DCHECK(state_ == INITIALIZED);
// Initial cursor set.
ResetCursor(widget);
return scoped_ptr<ui::SurfaceOzoneCanvas>( return scoped_ptr<ui::SurfaceOzoneCanvas>(
new DriSurface(window_manager_->GetWindowDelegate(widget), drm_)); new DriSurface(window_manager_->GetWindowDelegate(widget), drm_));
...@@ -113,17 +114,24 @@ void DriSurfaceFactory::SetHardwareCursor(gfx::AcceleratedWidget widget, ...@@ -113,17 +114,24 @@ void DriSurfaceFactory::SetHardwareCursor(gfx::AcceleratedWidget widget,
const std::vector<SkBitmap>& bitmaps, const std::vector<SkBitmap>& bitmaps,
const gfx::Point& location, const gfx::Point& location,
int frame_delay_ms) { int frame_delay_ms) {
cursor_widget_ = widget;
cursor_bitmaps_ = bitmaps; cursor_bitmaps_ = bitmaps;
cursor_location_ = location; cursor_location_ = location;
cursor_frame_ = 0;
cursor_frame_delay_ms_ = frame_delay_ms; cursor_frame_delay_ms_ = frame_delay_ms;
cursor_timer_.Stop();
if (bitmaps.size() > 1) if (cursor_frame_delay_ms_)
NOTIMPLEMENTED(); // No animation of animated cursors. cursor_timer_.Start(
FROM_HERE,
base::TimeDelta::FromMilliseconds(cursor_frame_delay_ms_),
this,
&DriSurfaceFactory::OnCursorAnimationTimeout);
if (state_ != INITIALIZED) if (state_ != INITIALIZED)
return; return;
ResetCursor(widget); ResetCursor();
} }
void DriSurfaceFactory::MoveHardwareCursor(gfx::AcceleratedWidget widget, void DriSurfaceFactory::MoveHardwareCursor(gfx::AcceleratedWidget widget,
...@@ -142,14 +150,16 @@ void DriSurfaceFactory::MoveHardwareCursor(gfx::AcceleratedWidget widget, ...@@ -142,14 +150,16 @@ void DriSurfaceFactory::MoveHardwareCursor(gfx::AcceleratedWidget widget,
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// DriSurfaceFactory private // DriSurfaceFactory private
void DriSurfaceFactory::ResetCursor(gfx::AcceleratedWidget widget) { void DriSurfaceFactory::ResetCursor() {
HardwareDisplayController* controller = if (!cursor_widget_)
window_manager_->GetWindowDelegate(widget)->GetController(); return;
HardwareDisplayController* controller =
window_manager_->GetWindowDelegate(cursor_widget_)->GetController();
if (cursor_bitmaps_.size()) { if (cursor_bitmaps_.size()) {
// Draw new cursor into backbuffer. // Draw new cursor into backbuffer.
UpdateCursorImage(cursor_buffers_[cursor_frontbuffer_ ^ 1].get(), UpdateCursorImage(cursor_buffers_[cursor_frontbuffer_ ^ 1].get(),
cursor_bitmaps_[0]); cursor_bitmaps_[cursor_frame_]);
// Reset location & buffer. // Reset location & buffer.
if (controller) { if (controller) {
...@@ -164,4 +174,11 @@ void DriSurfaceFactory::ResetCursor(gfx::AcceleratedWidget widget) { ...@@ -164,4 +174,11 @@ void DriSurfaceFactory::ResetCursor(gfx::AcceleratedWidget widget) {
} }
} }
void DriSurfaceFactory::OnCursorAnimationTimeout() {
cursor_frame_++;
cursor_frame_ %= cursor_bitmaps_.size();
ResetCursor();
}
} // namespace ui } // namespace ui
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include <map> #include <map>
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "base/timer/timer.h"
#include "third_party/skia/include/core/SkBitmap.h" #include "third_party/skia/include/core/SkBitmap.h"
#include "ui/ozone/platform/dri/hardware_cursor_delegate.h" #include "ui/ozone/platform/dri/hardware_cursor_delegate.h"
#include "ui/ozone/public/surface_factory_ozone.h" #include "ui/ozone/public/surface_factory_ozone.h"
...@@ -63,7 +64,10 @@ class DriSurfaceFactory : public SurfaceFactoryOzone, ...@@ -63,7 +64,10 @@ class DriSurfaceFactory : public SurfaceFactoryOzone,
protected: protected:
// 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();
// Draw next frame in an animated cursor.
void OnCursorAnimationTimeout();
DriWrapper* drm_; // Not owned. DriWrapper* drm_; // Not owned.
ScreenManager* screen_manager_; // Not owned. ScreenManager* screen_manager_; // Not owned.
...@@ -73,9 +77,12 @@ class DriSurfaceFactory : public SurfaceFactoryOzone, ...@@ -73,9 +77,12 @@ class DriSurfaceFactory : public SurfaceFactoryOzone,
scoped_refptr<DriBuffer> cursor_buffers_[2]; scoped_refptr<DriBuffer> cursor_buffers_[2];
int cursor_frontbuffer_; int cursor_frontbuffer_;
gfx::AcceleratedWidget cursor_widget_;
std::vector<SkBitmap> cursor_bitmaps_; std::vector<SkBitmap> cursor_bitmaps_;
gfx::Point cursor_location_; gfx::Point cursor_location_;
int cursor_frame_;
int cursor_frame_delay_ms_; int cursor_frame_delay_ms_;
base::RepeatingTimer<DriSurfaceFactory> cursor_timer_;
DISALLOW_COPY_AND_ASSIGN(DriSurfaceFactory); DISALLOW_COPY_AND_ASSIGN(DriSurfaceFactory);
}; };
......
...@@ -150,8 +150,6 @@ scoped_ptr<SurfaceOzoneEGL> GbmSurfaceFactory::CreateEGLSurfaceForWidget( ...@@ -150,8 +150,6 @@ scoped_ptr<SurfaceOzoneEGL> GbmSurfaceFactory::CreateEGLSurfaceForWidget(
DriWindowDelegate* delegate = GetOrCreateWindowDelegate(widget); DriWindowDelegate* delegate = GetOrCreateWindowDelegate(widget);
ResetCursor(widget);
scoped_ptr<GbmSurface> surface(new GbmSurface(delegate, device_, drm_)); scoped_ptr<GbmSurface> surface(new GbmSurface(delegate, device_, drm_));
if (!surface->Initialize()) if (!surface->Initialize())
return scoped_ptr<SurfaceOzoneEGL>(); return scoped_ptr<SurfaceOzoneEGL>();
......
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