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

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: 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 #include "wayland_display.h"
7 #include "wayland_shm_buffer.h"
8
9 #include <cairo.h>
10 #include <stdio.h>
11
12 struct PointerImage {
13 const char* filename;
14 int hotspot_x, hotspot_y;
15 };
16
17 // TODO Add more pointer images and fix the path
18 static const struct PointerImage pointer_images[] = {
19 {"left_ptr.png", 10, 5},
20 {"hand.png", 10, 5},
21 };
22
23 WaylandCursor::WaylandCursor(WaylandDisplay* display)
24 : display_(display),
25 buffer_(NULL) {
26 }
27
28 void WaylandCursor::ChangeCursor(WaylandCursorType type) {
29 const struct PointerImage *ptr = &pointer_images[type];
30
31 cairo_surface_t* ptr_surface = cairo_image_surface_create_from_png(
32 ptr->filename);
33
34 if (!ptr_surface) {
35 fprintf(stderr, "Failed to create cursor surface\n");
36 return;
37 }
38
39 int width = cairo_image_surface_get_width(ptr_surface);
40 int height = cairo_image_surface_get_height(ptr_surface);
41
42 if (buffer_) {
43 delete buffer_;
44 }
45
46 // TODO There should be a simpler way to create a wl_buffer for
47 // a cairo surface
48 buffer_ = new WaylandShmBuffer(display_, width, height);
49 cairo_surface_t* shared_surface = buffer_->GetDataSurface();
50
51 cairo_t* cr = cairo_create(shared_surface);
52 cairo_set_source_surface(cr, ptr_surface, 0, 0);
53 cairo_rectangle(cr, 0, 0, width, height);
54 cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
55 cairo_fill(cr);
56
57 display_->SetCursor(buffer_, ptr->hotspot_x, ptr->hotspot_y);
58 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698