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

Side by Side Diff: src/utils/android/ashmem.cpp

Issue 319533004: remove ashmem from skia (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: AnotherPatchSet Created 6 years, 6 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
« no previous file with comments | « src/utils/android/ashmem.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright 2008 The Android Open Source Project
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 /*
9 * Implementation of the user-space ashmem API for devices, which have our
10 * ashmem-enabled kernel. See ashmem-sim.c for the "fake" tmp-based version,
11 * used by the simulator.
12 */
13
14 #include <android/ashmem.h>
15
16 #include <unistd.h>
17 #include <string.h>
18 #include <sys/types.h>
19 #include <sys/stat.h>
20 #include <sys/ioctl.h>
21 #include <fcntl.h>
22
23 #include <linux/ashmem.h>
24
25 #include <SkTypes.h> // SkASSERT
26
27 #define ASHMEM_DEVICE "/dev/ashmem"
28
29 /*
30 * ashmem_create_region - creates a new ashmem region and returns the file
31 * descriptor, or <0 on error
32 *
33 * `name' is an optional label to give the region (visible in /proc/pid/maps)
34 * `size' is the size of the region, in page-aligned bytes
35 */
36 int ashmem_create_region(const char *name, size_t size)
37 {
38 int fd, ret;
39
40 fd = open(ASHMEM_DEVICE, O_RDWR);
41 if (fd < 0)
42 return fd;
43
44 if (name) {
45 char buf[ASHMEM_NAME_LEN];
46
47 strlcpy(buf, name, sizeof(buf));
48 ret = ioctl(fd, ASHMEM_SET_NAME, buf);
49 if (ret < 0)
50 goto error;
51 }
52
53 ret = ioctl(fd, ASHMEM_SET_SIZE, size);
54 if (ret < 0)
55 goto error;
56
57 return fd;
58
59 error:
60 close(fd);
61 return ret;
62 }
63
64 int ashmem_set_prot_region(int fd, int prot)
65 {
66 return ioctl(fd, ASHMEM_SET_PROT_MASK, prot);
67 }
68
69 int ashmem_pin_region(int fd, size_t offset, size_t len)
70 {
71 // Skia only calls this when offset=len=0.
72 struct ashmem_pin pin = { static_cast<__u32>(offset),
73 static_cast<__u32>(len) };
74 SkASSERT(pin.offset == offset && pin.len == len);
75 return ioctl(fd, ASHMEM_PIN, &pin);
76 }
77
78 int ashmem_unpin_region(int fd, size_t offset, size_t len)
79 {
80 // Skia only calls this when offset=len=0.
81 struct ashmem_pin pin = { static_cast<__u32>(offset),
82 static_cast<__u32>(len) };
83 SkASSERT(pin.offset == offset && pin.len == len);
84 return ioctl(fd, ASHMEM_UNPIN, &pin);
85 }
86
87 int ashmem_get_size_region(int fd)
88 {
89 return ioctl(fd, ASHMEM_GET_SIZE, NULL);
90 }
91
92 int ashmem_purge_all_caches(int fd)
93 {
94 return ioctl(fd, ASHMEM_PURGE_ALL_CACHES, NULL);
95 }
OLDNEW
« no previous file with comments | « src/utils/android/ashmem.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698