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

Side by Side Diff: ppapi/proxy/ppb_image_data_proxy.h

Issue 16605006: Clean up Pepper ImageData resource class. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix Linux, allow both kinds of ImageData on host side. Created 7 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef PPAPI_PPB_IMAGE_DATA_PROXY_H_ 5 #ifndef PPAPI_PPB_IMAGE_DATA_PROXY_H_
6 #define PPAPI_PPB_IMAGE_DATA_PROXY_H_ 6 #define PPAPI_PPB_IMAGE_DATA_PROXY_H_
7 7
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/shared_memory.h" 9 #include "base/shared_memory.h"
10 #include "build/build_config.h" 10 #include "build/build_config.h"
(...skipping 13 matching lines...) Expand all
24 #include "ppapi/shared_impl/resource.h" 24 #include "ppapi/shared_impl/resource.h"
25 #include "ppapi/thunk/ppb_image_data_api.h" 25 #include "ppapi/thunk/ppb_image_data_api.h"
26 26
27 class TransportDIB; 27 class TransportDIB;
28 28
29 namespace ppapi { 29 namespace ppapi {
30 namespace proxy { 30 namespace proxy {
31 31
32 class SerializedHandle; 32 class SerializedHandle;
33 33
34 // The proxied image data resource. Unlike most resources, this needs to be 34 // ImageData is an abstract base class for image data resources. Unlike most
35 // public in the header since a number of other resources need to access it. 35 // resources, ImageData must be public in the header since a number of other
36 // resources need to access it.
36 class PPAPI_PROXY_EXPORT ImageData 37 class PPAPI_PROXY_EXPORT ImageData
37 : public ppapi::Resource, 38 : public ppapi::Resource,
38 public NON_EXPORTED_BASE(ppapi::thunk::PPB_ImageData_API), 39 public NON_EXPORTED_BASE(ppapi::thunk::PPB_ImageData_API),
39 public ppapi::PPB_ImageData_Shared { 40 public ppapi::PPB_ImageData_Shared {
40 public: 41 public:
41 #if !defined(OS_NACL)
42 ImageData(const ppapi::HostResource& resource,
43 const PP_ImageDataDesc& desc,
44 ImageHandle handle);
45 #else
46 // In NaCl, we only allow creating an ImageData using a SharedMemoryHandle.
47 // ImageHandle can differ by host platform. We need something that is
48 // more consistent across platforms for NaCl, so that we can communicate to
49 // the host OS in a consistent way.
50 ImageData(const ppapi::HostResource& resource,
51 const PP_ImageDataDesc& desc,
52 const base::SharedMemoryHandle& handle);
53 #endif
54 virtual ~ImageData(); 42 virtual ~ImageData();
55 43
56 // Resource overrides. 44 // Resource overrides.
57 virtual ppapi::thunk::PPB_ImageData_API* AsPPB_ImageData_API() OVERRIDE; 45 virtual ppapi::thunk::PPB_ImageData_API* AsPPB_ImageData_API() OVERRIDE;
58 virtual void LastPluginRefWasDeleted() OVERRIDE; 46 virtual void LastPluginRefWasDeleted() OVERRIDE;
59 virtual void InstanceWasDeleted() OVERRIDE; 47 virtual void InstanceWasDeleted() OVERRIDE;
60 48
61 // PPB_ImageData API. 49 // PPB_ImageData API.
62 virtual PP_Bool Describe(PP_ImageDataDesc* desc) OVERRIDE; 50 virtual PP_Bool Describe(PP_ImageDataDesc* desc) OVERRIDE;
63 virtual void* Map() OVERRIDE;
64 virtual void Unmap() OVERRIDE;
65 virtual int32_t GetSharedMemory(int* handle, uint32_t* byte_count) OVERRIDE; 51 virtual int32_t GetSharedMemory(int* handle, uint32_t* byte_count) OVERRIDE;
66 virtual SkCanvas* GetPlatformCanvas() OVERRIDE;
67 virtual SkCanvas* GetCanvas() OVERRIDE;
68 virtual void SetIsCandidateForReuse() OVERRIDE; 52 virtual void SetIsCandidateForReuse() OVERRIDE;
69 53
70 const PP_ImageDataDesc& desc() const { return desc_; } 54 const PP_ImageDataDesc& desc() const { return desc_; }
71 55
72 // Prepares this image data to be recycled to the plugin. The contents will be 56 // Prepares this image data to be recycled to the plugin. Clears the contents
73 // cleared if zero_contents is set. 57 // if zero_contents is true.
74 void RecycleToPlugin(bool zero_contents); 58 void RecycleToPlugin(bool zero_contents);
75 59
76 #if !defined(OS_NACL) 60 protected:
77 static ImageHandle NullHandle(); 61 ImageData(const ppapi::HostResource& resource,
78 static ImageHandle HandleFromInt(int32_t i); 62 const PP_ImageDataDesc& desc);
79 #endif
80 63
81 private:
82 PP_ImageDataDesc desc_; 64 PP_ImageDataDesc desc_;
83 65
84 #if defined(OS_NACL)
85 base::SharedMemory shm_;
86 uint32 size_;
87 int map_count_;
88 #else
89 scoped_ptr<TransportDIB> transport_dib_;
90
91 // Null when the image isn't mapped.
92 scoped_ptr<SkCanvas> mapped_canvas_;
93 #endif
94
95 // Set to true when this ImageData is a good candidate for reuse. 66 // Set to true when this ImageData is a good candidate for reuse.
96 bool is_candidate_for_reuse_; 67 bool is_candidate_for_reuse_;
97 68
98 DISALLOW_COPY_AND_ASSIGN(ImageData); 69 DISALLOW_COPY_AND_ASSIGN(ImageData);
99 }; 70 };
100 71
72 // PlatformImageData is a full featured image data resource which can access
73 // the underlying platform-specific canvas and ImageHandle. This can't be used
74 // by NaCl apps.
75 #if !defined(OS_NACL)
76 class PPAPI_PROXY_EXPORT PlatformImageData : public ImageData {
77 public:
78 PlatformImageData(const ppapi::HostResource& resource,
79 const PP_ImageDataDesc& desc,
80 ImageHandle handle);
81 virtual ~PlatformImageData();
82
83 // PPB_ImageData API.
84 virtual void* Map() OVERRIDE;
85 virtual void Unmap() OVERRIDE;
86 virtual SkCanvas* GetPlatformCanvas() OVERRIDE;
87 virtual SkCanvas* GetCanvas() OVERRIDE;
88
89 static ImageHandle NullHandle();
90 static ImageHandle HandleFromInt(int32_t i);
91
92 private:
93 scoped_ptr<TransportDIB> transport_dib_;
94
95 // Null when the image isn't mapped.
96 scoped_ptr<SkCanvas> mapped_canvas_;
97
98 DISALLOW_COPY_AND_ASSIGN(PlatformImageData);
99 };
100 #endif // !defined(OS_NACL)
101
102 // SimpleImageData is a simple, platform independent image data resource which
dmichael (off chromium) 2013/06/10 18:07:29 teeny nit: I would hyphenate platform-independent.
bbudge 2013/06/10 23:28:37 Done.
103 // can be used by NaCl. It can also be used by trusted apps when access to the
104 // platform canvas isn't needed.
105 class PPAPI_PROXY_EXPORT SimpleImageData : public ImageData {
106 public:
107 SimpleImageData(const ppapi::HostResource& resource,
108 const PP_ImageDataDesc& desc,
109 const base::SharedMemoryHandle& handle);
110 virtual ~SimpleImageData();
111
112 // PPB_ImageData API.
113 virtual void* Map() OVERRIDE;
114 virtual void Unmap() OVERRIDE;
115 virtual SkCanvas* GetPlatformCanvas() OVERRIDE;
116 virtual SkCanvas* GetCanvas() OVERRIDE;
117
118 private:
119 base::SharedMemory shm_;
120 uint32 size_;
121 int map_count_;
122
123 DISALLOW_COPY_AND_ASSIGN(SimpleImageData);
124 };
125
101 class PPB_ImageData_Proxy : public InterfaceProxy { 126 class PPB_ImageData_Proxy : public InterfaceProxy {
102 public: 127 public:
103 PPB_ImageData_Proxy(Dispatcher* dispatcher); 128 PPB_ImageData_Proxy(Dispatcher* dispatcher);
104 virtual ~PPB_ImageData_Proxy(); 129 virtual ~PPB_ImageData_Proxy();
105 130
106 static PP_Resource CreateProxyResource(PP_Instance instance, 131 static PP_Resource CreateProxyResource(PP_Instance instance,
107 PP_ImageDataFormat format, 132 PP_ImageDataFormat format,
108 const PP_Size& size, 133 const PP_Size& size,
109 PP_Bool init_to_zero); 134 PP_Bool init_to_zero,
135 PP_Bool platform);
110 136
111 // InterfaceProxy implementation. 137 // InterfaceProxy implementation.
112 virtual bool OnMessageReceived(const IPC::Message& msg); 138 virtual bool OnMessageReceived(const IPC::Message& msg);
113 139
114 // Utility for creating ImageData resources. 140 // Utility for creating ImageData resources.
115 // This can only be called on the host side of the proxy. 141 // This can only be called on the host side of the proxy.
116 // On failure, will return invalid resource (0). On success it will return a 142 // On failure, will return invalid resource (0). On success it will return a
117 // valid resource and the out params will be written. 143 // valid resource and the out params will be written.
144 // |platform| determines whether a PlatformImageData or SimpleImageData is
145 // created.
118 // |desc| contains the result of Describe. 146 // |desc| contains the result of Describe.
119 // |image_handle| and |byte_count| contain the result of GetSharedMemory. 147 // |image_handle| and |byte_count| contain the result of GetSharedMemory.
120 // NOTE: if |init_to_zero| is false, you should write over the entire image 148 // NOTE: if |init_to_zero| is false, you should write over the entire image
121 // to avoid leaking sensitive data to a less privileged process. 149 // to avoid leaking sensitive data to a less privileged process.
122 PPAPI_PROXY_EXPORT static PP_Resource CreateImageData( 150 PPAPI_PROXY_EXPORT static PP_Resource CreateImageData(
123 PP_Instance instance, 151 PP_Instance instance,
124 PP_ImageDataFormat format, 152 PP_ImageDataFormat format,
125 const PP_Size& size, 153 const PP_Size& size,
126 bool init_to_zero, 154 bool init_to_zero,
127 bool is_nacl_plugin, 155 bool platform,
dmichael (off chromium) 2013/06/10 18:07:29 suggestion: you could use an enum for this, to mak
bbudge 2013/06/10 23:28:37 Done. Moved the one in PPB_ImageData_Impl to PPB_I
128 PP_ImageDataDesc* desc, 156 PP_ImageDataDesc* desc,
129 IPC::PlatformFileForTransit* image_handle, 157 IPC::PlatformFileForTransit* image_handle,
130 uint32_t* byte_count); 158 uint32_t* byte_count);
131 159
132 static const ApiID kApiID = API_ID_PPB_IMAGE_DATA; 160 static const ApiID kApiID = API_ID_PPB_IMAGE_DATA;
133 161
134 private: 162 private:
135 // Plugin->Host message handlers. 163 // Plugin->Host message handlers.
136 void OnHostMsgCreate(PP_Instance instance, 164 void OnHostMsgCreatePlatform(
137 int32_t format, 165 PP_Instance instance,
138 const PP_Size& size, 166 int32_t format,
139 PP_Bool init_to_zero, 167 const PP_Size& size,
140 HostResource* result, 168 PP_Bool init_to_zero,
141 std::string* image_data_desc, 169 HostResource* result,
142 ImageHandle* result_image_handle); 170 PP_ImageDataDesc* desc,
143 void OnHostMsgCreateNaCl(PP_Instance instance, 171 ImageHandle* result_image_handle);
144 int32_t format, 172 void OnHostMsgCreateSimple(
145 const PP_Size& size, 173 PP_Instance instance,
146 PP_Bool init_to_zero, 174 int32_t format,
147 HostResource* result, 175 const PP_Size& size,
148 std::string* image_data_desc, 176 PP_Bool init_to_zero,
149 ppapi::proxy::SerializedHandle* result_image_handle); 177 HostResource* result,
178 PP_ImageDataDesc* desc,
179 ppapi::proxy::SerializedHandle* result_image_handle);
150 180
151 // Host->Plugin message handlers. 181 // Host->Plugin message handlers.
152 void OnPluginMsgNotifyUnusedImageData(const HostResource& old_image_data); 182 void OnPluginMsgNotifyUnusedImageData(const HostResource& old_image_data);
153 183
154 DISALLOW_COPY_AND_ASSIGN(PPB_ImageData_Proxy); 184 DISALLOW_COPY_AND_ASSIGN(PPB_ImageData_Proxy);
155 }; 185 };
156 186
157 } // namespace proxy 187 } // namespace proxy
158 } // namespace ppapi 188 } // namespace ppapi
159 189
160 #endif // PPAPI_PPB_IMAGE_DATA_PROXY_H_ 190 #endif // PPAPI_PPB_IMAGE_DATA_PROXY_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698