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