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

Side by Side Diff: ppapi/proxy/image_data.cc

Issue 6334016: Refactor PPAPI proxy resource handling to maintain which host they came from,... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 11 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
« no previous file with comments | « ppapi/proxy/image_data.h ('k') | ppapi/proxy/mock_resource.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2010 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 "ppapi/proxy/image_data.h"
6
7 #if defined(OS_LINUX)
8 #include <sys/shm.h>
9 #endif
10
11 #if defined(OS_MACOSX)
12 #include <sys/stat.h>
13 #include <sys/mman.h>
14 #endif
15
16 namespace pp {
17 namespace proxy {
18
19 ImageData::ImageData(PP_Instance instance,
20 const PP_ImageDataDesc& desc,
21 ImageHandle handle)
22 : PluginResource(instance),
23 desc_(desc),
24 handle_(handle),
25 mapped_data_(NULL) {
26 }
27
28 ImageData::~ImageData() {
29 Unmap();
30 }
31
32 ImageData* ImageData::AsImageData() {
33 return this;
34 }
35
36 void* ImageData::Map() {
37 #if defined(OS_WIN)
38 NOTIMPLEMENTED();
39 return NULL;
40 #elif defined(OS_MACOSX)
41 struct stat st;
42 if (fstat(handle_.fd, &st) != 0)
43 return NULL;
44 void* memory = mmap(NULL, st.st_size, PROT_READ | PROT_WRITE,
45 MAP_SHARED, handle_.fd, 0);
46 if (memory == MAP_FAILED)
47 return NULL;
48 mapped_data_ = memory;
49 return mapped_data_;
50 #else
51 int shmkey = handle_;
52 void* address = shmat(shmkey, NULL, 0);
53 // Mark for deletion in case we crash so the kernel will clean it up.
54 shmctl(shmkey, IPC_RMID, 0);
55 if (address == (void*)-1)
56 return NULL;
57 mapped_data_ = address;
58 return address;
59 #endif
60 }
61
62 void ImageData::Unmap() {
63 #if defined(OS_WIN)
64 NOTIMPLEMENTED();
65 #elif defined(OS_MACOSX)
66 if (mapped_data_) {
67 struct stat st;
68 if (fstat(handle_.fd, &st) == 0)
69 munmap(mapped_data_, st.st_size);
70 }
71 #else
72 if (mapped_data_)
73 shmdt(mapped_data_);
74 #endif
75 mapped_data_ = NULL;
76 }
77
78 #if defined(OS_WIN)
79 const ImageHandle ImageData::NullHandle = NULL;
80 #elif defined(OS_MACOSX)
81 const ImageHandle ImageData::NullHandle = ImageHandle();
82 #else
83 const ImageHandle ImageData::NullHandle = 0;
84 #endif
85
86 ImageHandle ImageData::HandleFromInt(int32_t i) {
87 #if defined(OS_WIN)
88 return reinterpret_cast<ImageHandle>(i);
89 #elif defined(OS_MACOSX)
90 return ImageHandle(i, false);
91 #else
92 return static_cast<ImageHandle>(i);
93 #endif
94 }
95
96 } // namespace proxy
97 } // namespace pp
OLDNEW
« no previous file with comments | « ppapi/proxy/image_data.h ('k') | ppapi/proxy/mock_resource.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698