Commit ba21e464 authored by spang's avatar spang Committed by Commit bot

ozone: Plumb animated cursors from BitmapCursorFactoryOzone to DriSurfaceFactory

Update BitmapCursorOzone type to store a vector of bitmaps, a hotspot,
and a frame delay. Plumb the vector through to the GPU process, where
we'll update the cursor on a timer. This is plumbing only; it does not
change the user-visible behavior of showing only the first cursor frame.

R=dnicoara, kenrb
BUG=343245
TEST=viewed css "wait" cursor on cros link_freon

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

Cr-Commit-Position: refs/heads/master@{#294045}
parent e783a653
......@@ -30,6 +30,39 @@ scoped_refptr<BitmapCursorOzone> CreateDefaultBitmapCursor(int type) {
} // namespace
BitmapCursorOzone::BitmapCursorOzone(const SkBitmap& bitmap,
const gfx::Point& hotspot)
: hotspot_(hotspot), frame_delay_ms_(0) {
bitmaps_.push_back(bitmap);
}
BitmapCursorOzone::BitmapCursorOzone(const std::vector<SkBitmap>& bitmaps,
const gfx::Point& hotspot,
int frame_delay_ms)
: bitmaps_(bitmaps), hotspot_(hotspot), frame_delay_ms_(frame_delay_ms) {
DCHECK_LT(0U, bitmaps.size());
DCHECK_LE(0, frame_delay_ms);
}
BitmapCursorOzone::~BitmapCursorOzone() {
}
const gfx::Point& BitmapCursorOzone::hotspot() {
return hotspot_;
}
const SkBitmap& BitmapCursorOzone::bitmap() {
return bitmaps_[0];
}
const std::vector<SkBitmap>& BitmapCursorOzone::bitmaps() {
return bitmaps_;
}
int BitmapCursorOzone::frame_delay_ms() {
return frame_delay_ms_;
}
BitmapCursorFactoryOzone::BitmapCursorFactoryOzone() {}
BitmapCursorFactoryOzone::~BitmapCursorFactoryOzone() {}
......@@ -57,8 +90,10 @@ PlatformCursor BitmapCursorFactoryOzone::CreateAnimatedCursor(
const gfx::Point& hotspot,
int frame_delay_ms) {
DCHECK_LT(0U, bitmaps.size());
NOTIMPLEMENTED();
return CreateImageCursor(bitmaps[0], hotspot);
BitmapCursorOzone* cursor =
new BitmapCursorOzone(bitmaps, hotspot, frame_delay_ms);
cursor->AddRef(); // Balanced by UnrefImageCursor.
return ToPlatformCursor(cursor);
}
void BitmapCursorFactoryOzone::RefImageCursor(PlatformCursor cursor) {
......
......@@ -20,18 +20,25 @@ namespace ui {
class UI_BASE_EXPORT BitmapCursorOzone
: public base::RefCounted<BitmapCursorOzone> {
public:
BitmapCursorOzone(const SkBitmap& bitmap, const gfx::Point& hotspot)
: bitmap_(bitmap), hotspot_(hotspot) {}
BitmapCursorOzone(const SkBitmap& bitmap, const gfx::Point& hotspot);
BitmapCursorOzone(const std::vector<SkBitmap>& bitmaps,
const gfx::Point& hotspot,
int frame_delay_ms);
const gfx::Point& hotspot();
const SkBitmap& bitmap();
const gfx::Point& hotspot() { return hotspot_; }
const SkBitmap& bitmap() { return bitmap_; }
// For animated cursors.
const std::vector<SkBitmap>& bitmaps();
int frame_delay_ms();
private:
friend class base::RefCounted<BitmapCursorOzone>;
~BitmapCursorOzone() {}
~BitmapCursorOzone();
SkBitmap bitmap_;
std::vector<SkBitmap> bitmaps_;
gfx::Point hotspot_;
int frame_delay_ms_;
DISALLOW_COPY_AND_ASSIGN(BitmapCursorOzone);
};
......
......@@ -52,8 +52,11 @@ IPC_STRUCT_TRAITS_END()
// These are messages from the browser to the GPU process.
// Update the HW cursor bitmap & move to specified location.
IPC_MESSAGE_CONTROL3(OzoneGpuMsg_CursorSet,
gfx::AcceleratedWidget, SkBitmap, gfx::Point)
IPC_MESSAGE_CONTROL4(OzoneGpuMsg_CursorSet,
gfx::AcceleratedWidget,
std::vector<SkBitmap>,
gfx::Point /* location */,
int /* frame_delay_ms */)
// Move the HW cursor to the specified location.
IPC_MESSAGE_CONTROL2(OzoneGpuMsg_CursorMove,
......
......@@ -32,16 +32,18 @@ void DriCursor::SetCursor(gfx::AcceleratedWidget widget,
cursor_ = cursor;
if (cursor_.get())
hardware_->SetHardwareCursor(
cursor_window_, cursor_->bitmap(), bitmap_location());
hardware_->SetHardwareCursor(cursor_window_,
cursor_->bitmaps(),
bitmap_location(),
cursor_->frame_delay_ms());
else
hardware_->SetHardwareCursor(cursor_window_, SkBitmap(), gfx::Point());
UnsetCursor(cursor_window_);
}
void DriCursor::MoveCursorTo(gfx::AcceleratedWidget widget,
const gfx::PointF& location) {
if (widget != cursor_window_)
hardware_->SetHardwareCursor(cursor_window_, SkBitmap(), gfx::Point());
UnsetCursor(cursor_window_);
cursor_window_ = widget;
cursor_location_ = location;
......@@ -75,4 +77,9 @@ gfx::Point DriCursor::bitmap_location() {
cursor_->hotspot().OffsetFromOrigin();
}
void DriCursor::UnsetCursor(gfx::AcceleratedWidget widget) {
hardware_->SetHardwareCursor(
widget, std::vector<SkBitmap>(), gfx::Point(), 0);
}
} // namespace ui
......@@ -37,6 +37,8 @@ class DriCursor : public CursorDelegateEvdev {
virtual gfx::PointF location() OVERRIDE;
private:
void UnsetCursor(gfx::AcceleratedWidget widget);
// The location of the bitmap (the cursor location is the hotspot location).
gfx::Point bitmap_location();
......
......@@ -110,10 +110,15 @@ bool DriSurfaceFactory::LoadEGLGLES2Bindings(
}
void DriSurfaceFactory::SetHardwareCursor(gfx::AcceleratedWidget widget,
const SkBitmap& image,
const gfx::Point& location) {
cursor_bitmap_ = image;
const std::vector<SkBitmap>& bitmaps,
const gfx::Point& location,
int frame_delay_ms) {
cursor_bitmaps_ = bitmaps;
cursor_location_ = location;
cursor_frame_delay_ms_ = frame_delay_ms;
if (bitmaps.size() > 1)
NOTIMPLEMENTED(); // No animation of animated cursors.
if (state_ != INITIALIZED)
return;
......@@ -141,10 +146,10 @@ void DriSurfaceFactory::ResetCursor(gfx::AcceleratedWidget widget) {
HardwareDisplayController* controller =
window_manager_->GetWindowDelegate(widget)->GetController();
if (!cursor_bitmap_.empty()) {
if (cursor_bitmaps_.size()) {
// Draw new cursor into backbuffer.
UpdateCursorImage(cursor_buffers_[cursor_frontbuffer_ ^ 1].get(),
cursor_bitmap_);
cursor_bitmaps_[0]);
// Reset location & buffer.
if (controller) {
......
......@@ -54,9 +54,10 @@ class DriSurfaceFactory : public SurfaceFactoryOzone,
SetGLGetProcAddressProcCallback set_gl_get_proc_address) OVERRIDE;
// HardwareCursorDelegate:
virtual void SetHardwareCursor(gfx::AcceleratedWidget window,
const SkBitmap& image,
const gfx::Point& location) OVERRIDE;
virtual void SetHardwareCursor(gfx::AcceleratedWidget widget,
const std::vector<SkBitmap>& bitmaps,
const gfx::Point& location,
int frame_delay_ms) OVERRIDE;
virtual void MoveHardwareCursor(gfx::AcceleratedWidget window,
const gfx::Point& location) OVERRIDE;
......@@ -72,8 +73,9 @@ class DriSurfaceFactory : public SurfaceFactoryOzone,
scoped_refptr<DriBuffer> cursor_buffers_[2];
int cursor_frontbuffer_;
SkBitmap cursor_bitmap_;
std::vector<SkBitmap> cursor_bitmaps_;
gfx::Point cursor_location_;
int cursor_frame_delay_ms_;
DISALLOW_COPY_AND_ASSIGN(DriSurfaceFactory);
};
......
......@@ -130,8 +130,12 @@ TEST_F(DriSurfaceFactoryTest, SetCursorImage) {
image.allocPixels(info);
image.eraseColor(SK_ColorWHITE);
factory_->SetHardwareCursor(
ui::DriSurfaceFactory::kDefaultWidgetHandle, image, gfx::Point(4, 2));
std::vector<SkBitmap> cursor_bitmaps;
cursor_bitmaps.push_back(image);
factory_->SetHardwareCursor(ui::DriSurfaceFactory::kDefaultWidgetHandle,
cursor_bitmaps,
gfx::Point(4, 2),
0);
SkBitmap cursor;
// Buffers 0 and 1 are the cursor buffers.
......
......@@ -83,9 +83,10 @@ void GpuPlatformSupportGbm::OnWindowBoundsChanged(gfx::AcceleratedWidget widget,
}
void GpuPlatformSupportGbm::OnCursorSet(gfx::AcceleratedWidget widget,
const SkBitmap& bitmap,
const gfx::Point& location) {
dri_->SetHardwareCursor(widget, bitmap, location);
const std::vector<SkBitmap>& bitmaps,
const gfx::Point& location,
int frame_delay_ms) {
dri_->SetHardwareCursor(widget, bitmaps, location, frame_delay_ms);
}
void GpuPlatformSupportGbm::OnCursorMove(gfx::AcceleratedWidget widget,
......
......@@ -46,8 +46,9 @@ class GpuPlatformSupportGbm : public GpuPlatformSupport {
void OnWindowBoundsChanged(gfx::AcceleratedWidget widget,
const gfx::Rect& bounds);
void OnCursorSet(gfx::AcceleratedWidget widget,
const SkBitmap& bitmap,
const gfx::Point& location);
const std::vector<SkBitmap>& bitmaps,
const gfx::Point& location,
int frame_delay_ms);
void OnCursorMove(gfx::AcceleratedWidget widget, const gfx::Point& location);
IPC::Sender* sender_;
......
......@@ -100,10 +100,12 @@ bool GpuPlatformSupportHostGbm::Send(IPC::Message* message) {
return true;
}
void GpuPlatformSupportHostGbm::SetHardwareCursor(gfx::AcceleratedWidget widget,
const SkBitmap& bitmap,
const gfx::Point& location) {
Send(new OzoneGpuMsg_CursorSet(widget, bitmap, location));
void GpuPlatformSupportHostGbm::SetHardwareCursor(
gfx::AcceleratedWidget widget,
const std::vector<SkBitmap>& bitmaps,
const gfx::Point& location,
int frame_delay_ms) {
Send(new OzoneGpuMsg_CursorSet(widget, bitmaps, location, frame_delay_ms));
}
void GpuPlatformSupportHostGbm::MoveHardwareCursor(
......
......@@ -50,8 +50,9 @@ class GpuPlatformSupportHostGbm : public GpuPlatformSupportHost,
// HardwareCursorDelegate:
virtual void SetHardwareCursor(gfx::AcceleratedWidget widget,
const SkBitmap& bitmap,
const gfx::Point& location) OVERRIDE;
const std::vector<SkBitmap>& bitmaps,
const gfx::Point& location,
int frame_delay_ms) OVERRIDE;
virtual void MoveHardwareCursor(gfx::AcceleratedWidget widget,
const gfx::Point& location) OVERRIDE;
......
......@@ -20,8 +20,9 @@ class HardwareCursorDelegate {
// Update the HW cursor bitmap & move to specified location. If
// the bitmap is empty, the cursor is hidden.
virtual void SetHardwareCursor(gfx::AcceleratedWidget widget,
const SkBitmap& bitmap,
const gfx::Point& location) = 0;
const std::vector<SkBitmap>& bitmaps,
const gfx::Point& location,
int frame_delay_ms) = 0;
// Move the HW cursor to the specified location.
virtual void MoveHardwareCursor(gfx::AcceleratedWidget widget,
......
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