Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "ui/wayland/wayland_cursor.h" | |
| 6 | |
| 7 #include <cairo.h> | |
| 8 | |
| 9 #include "base/logging.h" | |
| 10 #include "ui/wayland/wayland_display.h" | |
| 11 #include "ui/wayland/wayland_shm_buffer.h" | |
| 12 | |
| 13 namespace { | |
| 14 | |
| 15 struct PointerImage { | |
| 16 const char* filename; | |
| 17 int hotspot_x, hotspot_y; | |
| 18 }; | |
| 19 | |
| 20 // TODO(dnicoara) Add more pointer images and fix the path | |
|
tfarina
2011/07/25 16:27:13
end with period.
| |
| 21 static const struct PointerImage kPointerImages[] = { | |
|
tfarina
2011/07/25 16:27:13
please, remove this static, since this is already
tfarina
2011/07/25 16:27:13
You can write this as:
struct PointerImage {
...
| |
| 22 {"left_ptr.png", 10, 5}, | |
| 23 {"hand.png", 10, 5}, | |
| 24 }; | |
| 25 | |
| 26 } // namespace | |
| 27 | |
| 28 namespace ui { | |
| 29 | |
| 30 WaylandCursor::WaylandCursor(WaylandDisplay* display) | |
| 31 : display_(display), | |
| 32 buffer_(NULL) { | |
| 33 } | |
| 34 | |
| 35 WaylandCursor::~WaylandCursor() { | |
| 36 if (buffer_) { | |
| 37 delete buffer_; | |
| 38 buffer_ = NULL; | |
| 39 } | |
| 40 } | |
| 41 | |
| 42 void WaylandCursor::ChangeCursor(Type type) { | |
| 43 const struct PointerImage *ptr = &kPointerImages[type]; | |
|
tfarina
2011/07/25 16:27:13
const PointerImage& image = kPointerImages[type] ?
| |
| 44 | |
| 45 cairo_surface_t* ptr_surface = cairo_image_surface_create_from_png( | |
| 46 ptr->filename); | |
| 47 | |
| 48 if (!ptr_surface) { | |
| 49 LOG(ERROR) << "Failed to create cursor surface"; | |
| 50 return; | |
| 51 } | |
| 52 | |
| 53 int width = cairo_image_surface_get_width(ptr_surface); | |
| 54 int height = cairo_image_surface_get_height(ptr_surface); | |
| 55 | |
| 56 if (buffer_) { | |
| 57 delete buffer_; | |
| 58 buffer_ = NULL; | |
| 59 } | |
| 60 | |
| 61 // TODO(dnicoara) There should be a simpler way to create a wl_buffer for | |
| 62 // a cairo surface. Meantime we just copy the contents of the cairo surface | |
| 63 // created from file to the cairo surface created using a shm file. | |
| 64 buffer_ = new WaylandShmBuffer(display_, width, height); | |
| 65 cairo_surface_t* shared_surface = buffer_->GetDataSurface(); | |
| 66 | |
| 67 cairo_t* cr = cairo_create(shared_surface); | |
| 68 cairo_set_source_surface(cr, ptr_surface, 0, 0); | |
| 69 cairo_rectangle(cr, 0, 0, width, height); | |
| 70 cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); | |
| 71 cairo_fill(cr); | |
| 72 | |
| 73 display_->SetCursor(buffer_, ptr->hotspot_x, ptr->hotspot_y); | |
| 74 } | |
| 75 | |
| 76 } // namespace ui | |
| OLD | NEW |