Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(458)

Side by Side Diff: ui/wayland/wayland_cursor.cc

Issue 7457023: Adding a Wayland basic toolkit (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: More comments and Chrome style formatting Created 9 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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 "wayland_cursor.h"
6
7 #include <cairo.h>
8
9 #include "base/logging.h"
10 #include "wayland_display.h"
11 #include "wayland_shm_buffer.h"
12
13 struct PointerImage {
Evan Martin 2011/07/22 18:21:22 Use an anon namespace around all the file-local de
14 const char* filename;
15 int hotspot_x, hotspot_y;
16 };
17
18 /* TODO(dnicoara) Add more pointer images and fix the path */
19 static const struct PointerImage pointer_images[] = {
Evan Martin 2011/07/22 18:21:22 kPointerImages
20 {"left_ptr.png", 10, 5},
21 {"hand.png", 10, 5},
22 };
23
24 WaylandCursor::WaylandCursor(WaylandDisplay* display)
25 : display_(display),
26 buffer_(NULL) {
27 }
28
29 WaylandCursor::~WaylandCursor() {
30 if (buffer_) {
31 delete buffer_;
32 buffer_ = NULL;
33 }
34 }
35
36 void WaylandCursor::ChangeCursor(WaylandCursorType type) {
37 const struct PointerImage *ptr = &pointer_images[type];
38
39 cairo_surface_t* ptr_surface = cairo_image_surface_create_from_png(
40 ptr->filename);
41
42 if (!ptr_surface) {
43 LOG(ERROR) << "Failed to create cursor surface";
44 return;
45 }
46
47 int width = cairo_image_surface_get_width(ptr_surface);
48 int height = cairo_image_surface_get_height(ptr_surface);
49
50 if (buffer_) {
51 delete buffer_;
52 buffer_ = NULL;
53 }
54
55 /* TODO(dnicoara) There should be a simpler way to create a wl_buffer for
56 a cairo surface. Meantime we just copy the contents of the cairo surface
57 created from file to the cairo surface created using a shm file.
58 */
59 buffer_ = new WaylandShmBuffer(display_, width, height);
60 cairo_surface_t* shared_surface = buffer_->GetDataSurface();
61
62 cairo_t* cr = cairo_create(shared_surface);
63 cairo_set_source_surface(cr, ptr_surface, 0, 0);
64 cairo_rectangle(cr, 0, 0, width, height);
65 cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
66 cairo_fill(cr);
67
68 display_->SetCursor(buffer_, ptr->hotspot_x, ptr->hotspot_y);
69 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698