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

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: 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
54 PPB_ImageData_Shared::ImageDataType type() const { return type_; }
70 const PP_ImageDataDesc& desc() const { return desc_; } 55 const PP_ImageDataDesc& desc() const { return desc_; }
71 56
72 // Prepares this image data to be recycled to the plugin. The contents will be 57 // Prepares this image data to be recycled to the plugin. Clears the contents
73 // cleared if zero_contents is set. 58 // if zero_contents is true.
74 void RecycleToPlugin(bool zero_contents); 59 void RecycleToPlugin(bool zero_contents);
75 60
76 #if !defined(OS_NACL) 61 protected:
77 static ImageHandle NullHandle(); 62 ImageData(const ppapi::HostResource& resource,
78 static ImageHandle HandleFromInt(int32_t i); 63 PPB_ImageData_Shared::ImageDataType type,
79 #endif 64 const PP_ImageDataDesc& desc);
80 65
81 private: 66 PPB_ImageData_Shared::ImageDataType type_;
82 PP_ImageDataDesc desc_; 67 PP_ImageDataDesc desc_;
83 68
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. 69 // Set to true when this ImageData is a good candidate for reuse.
96 bool is_candidate_for_reuse_; 70 bool is_candidate_for_reuse_;
97 71
98 DISALLOW_COPY_AND_ASSIGN(ImageData); 72 DISALLOW_COPY_AND_ASSIGN(ImageData);
99 }; 73 };
100 74
75 // PlatformImageData is a full featured image data resource which can access
76 // the underlying platform-specific canvas and ImageHandle. This can't be used
77 // by NaCl apps.
78 #if !defined(OS_NACL)
79 class PPAPI_PROXY_EXPORT PlatformImageData : public ImageData {
80 public:
81 PlatformImageData(const ppapi::HostResource& resource,
82 const PP_ImageDataDesc& desc,
83 ImageHandle handle);
84 virtual ~PlatformImageData();
85
86 // PPB_ImageData API.
87 virtual void* Map() OVERRIDE;
88 virtual void Unmap() OVERRIDE;
89 virtual SkCanvas* GetPlatformCanvas() OVERRIDE;
90 virtual SkCanvas* GetCanvas() OVERRIDE;
91
92 static ImageHandle NullHandle();
93 static ImageHandle HandleFromInt(int32_t i);
94
95 private:
96 scoped_ptr<TransportDIB> transport_dib_;
97
98 // Null when the image isn't mapped.
99 scoped_ptr<SkCanvas> mapped_canvas_;
100
101 DISALLOW_COPY_AND_ASSIGN(PlatformImageData);
102 };
103 #endif // !defined(OS_NACL)
104
105 // SimpleImageData is a simple, platform-independent image data resource which
106 // can be used by NaCl. It can also be used by trusted apps when access to the
107 // platform canvas isn't needed.
108 class PPAPI_PROXY_EXPORT SimpleImageData : public ImageData {
109 public:
110 SimpleImageData(const ppapi::HostResource& resource,
111 const PP_ImageDataDesc& desc,
112 const base::SharedMemoryHandle& handle);
113 virtual ~SimpleImageData();
114
115 // PPB_ImageData API.
116 virtual void* Map() OVERRIDE;
117 virtual void Unmap() OVERRIDE;
118 virtual SkCanvas* GetPlatformCanvas() OVERRIDE;
119 virtual SkCanvas* GetCanvas() OVERRIDE;
120
121 private:
122 base::SharedMemory shm_;
123 uint32 size_;
124 int map_count_;
125
126 DISALLOW_COPY_AND_ASSIGN(SimpleImageData);
127 };
128
101 class PPB_ImageData_Proxy : public InterfaceProxy { 129 class PPB_ImageData_Proxy : public InterfaceProxy {
102 public: 130 public:
103 PPB_ImageData_Proxy(Dispatcher* dispatcher); 131 PPB_ImageData_Proxy(Dispatcher* dispatcher);
104 virtual ~PPB_ImageData_Proxy(); 132 virtual ~PPB_ImageData_Proxy();
105 133
106 static PP_Resource CreateProxyResource(PP_Instance instance, 134 static PP_Resource CreateProxyResource(
107 PP_ImageDataFormat format, 135 PP_Instance instance,
108 const PP_Size& size, 136 PPB_ImageData_Shared::ImageDataType type,
109 PP_Bool init_to_zero); 137 PP_ImageDataFormat format,
138 const PP_Size& size,
139 PP_Bool init_to_zero);
110 140
111 // InterfaceProxy implementation. 141 // InterfaceProxy implementation.
112 virtual bool OnMessageReceived(const IPC::Message& msg); 142 virtual bool OnMessageReceived(const IPC::Message& msg);
113 143
114 // Utility for creating ImageData resources. 144 // Utility for creating ImageData resources.
115 // This can only be called on the host side of the proxy. 145 // 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 146 // On failure, will return invalid resource (0). On success it will return a
117 // valid resource and the out params will be written. 147 // valid resource and the out params will be written.
118 // |desc| contains the result of Describe. 148 // |desc| contains the result of Describe.
119 // |image_handle| and |byte_count| contain the result of GetSharedMemory. 149 // |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 150 // 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. 151 // to avoid leaking sensitive data to a less privileged process.
122 PPAPI_PROXY_EXPORT static PP_Resource CreateImageData( 152 PPAPI_PROXY_EXPORT static PP_Resource CreateImageData(
123 PP_Instance instance, 153 PP_Instance instance,
154 PPB_ImageData_Shared::ImageDataType type,
124 PP_ImageDataFormat format, 155 PP_ImageDataFormat format,
125 const PP_Size& size, 156 const PP_Size& size,
126 bool init_to_zero, 157 bool init_to_zero,
127 bool is_nacl_plugin,
128 PP_ImageDataDesc* desc, 158 PP_ImageDataDesc* desc,
129 IPC::PlatformFileForTransit* image_handle, 159 IPC::PlatformFileForTransit* image_handle,
130 uint32_t* byte_count); 160 uint32_t* byte_count);
131 161
132 static const ApiID kApiID = API_ID_PPB_IMAGE_DATA; 162 static const ApiID kApiID = API_ID_PPB_IMAGE_DATA;
133 163
134 private: 164 private:
135 // Plugin->Host message handlers. 165 // Plugin->Host message handlers.
136 void OnHostMsgCreate(PP_Instance instance, 166 void OnHostMsgCreatePlatform(
137 int32_t format, 167 PP_Instance instance,
138 const PP_Size& size, 168 int32_t format,
139 PP_Bool init_to_zero, 169 const PP_Size& size,
140 HostResource* result, 170 PP_Bool init_to_zero,
141 std::string* image_data_desc, 171 HostResource* result,
142 ImageHandle* result_image_handle); 172 PP_ImageDataDesc* desc,
143 void OnHostMsgCreateNaCl(PP_Instance instance, 173 ImageHandle* result_image_handle);
144 int32_t format, 174 void OnHostMsgCreateSimple(
145 const PP_Size& size, 175 PP_Instance instance,
146 PP_Bool init_to_zero, 176 int32_t format,
147 HostResource* result, 177 const PP_Size& size,
148 std::string* image_data_desc, 178 PP_Bool init_to_zero,
149 ppapi::proxy::SerializedHandle* result_image_handle); 179 HostResource* result,
180 PP_ImageDataDesc* desc,
181 ppapi::proxy::SerializedHandle* result_image_handle);
150 182
151 // Host->Plugin message handlers. 183 // Host->Plugin message handlers.
152 void OnPluginMsgNotifyUnusedImageData(const HostResource& old_image_data); 184 void OnPluginMsgNotifyUnusedImageData(const HostResource& old_image_data);
153 185
154 DISALLOW_COPY_AND_ASSIGN(PPB_ImageData_Proxy); 186 DISALLOW_COPY_AND_ASSIGN(PPB_ImageData_Proxy);
155 }; 187 };
156 188
157 } // namespace proxy 189 } // namespace proxy
158 } // namespace ppapi 190 } // namespace ppapi
159 191
160 #endif // PPAPI_PPB_IMAGE_DATA_PROXY_H_ 192 #endif // PPAPI_PPB_IMAGE_DATA_PROXY_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698