Revert 168224 - Update V8 to version 3.15.4.
[chromium-blink-merge.git] / ppapi / proxy / ppb_image_data_proxy.h
blob6ddbafa33921190b88076026dd90ed327f458399
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
3 // found in the LICENSE file.
5 #ifndef PPAPI_PPB_IMAGE_DATA_PROXY_H_
6 #define PPAPI_PPB_IMAGE_DATA_PROXY_H_
8 #include "base/memory/scoped_ptr.h"
9 #include "base/shared_memory.h"
10 #include "build/build_config.h"
11 #include "ppapi/c/pp_bool.h"
12 #include "ppapi/c/pp_completion_callback.h"
13 #include "ppapi/c/pp_instance.h"
14 #include "ppapi/c/pp_module.h"
15 #include "ppapi/c/pp_resource.h"
16 #include "ppapi/c/pp_size.h"
17 #include "ppapi/c/pp_var.h"
18 #include "ppapi/c/ppb_image_data.h"
19 #include "ppapi/proxy/interface_proxy.h"
20 #include "ppapi/proxy/serialized_structs.h"
21 #include "ppapi/shared_impl/ppb_image_data_shared.h"
22 #include "ppapi/shared_impl/resource.h"
23 #include "ppapi/thunk/ppb_image_data_api.h"
25 class TransportDIB;
27 namespace ppapi {
28 namespace proxy {
30 // The proxied image data resource. Unlike most resources, this needs to be
31 // public in the header since a number of other resources need to access it.
32 class ImageData : public ppapi::Resource,
33 public ppapi::thunk::PPB_ImageData_API,
34 public ppapi::PPB_ImageData_Shared {
35 public:
36 #if !defined(OS_NACL)
37 ImageData(const ppapi::HostResource& resource,
38 const PP_ImageDataDesc& desc,
39 ImageHandle handle);
40 #else
41 // In NaCl, we only allow creating an ImageData using a SharedMemoryHandle.
42 // ImageHandle can differ by host platform. We need something that is
43 // more consistent across platforms for NaCl, so that we can communicate to
44 // the host OS in a consistent way.
45 ImageData(const ppapi::HostResource& resource,
46 const PP_ImageDataDesc& desc,
47 const base::SharedMemoryHandle& handle);
48 #endif
49 virtual ~ImageData();
51 // Resource overrides.
52 virtual ppapi::thunk::PPB_ImageData_API* AsPPB_ImageData_API() OVERRIDE;
53 virtual void LastPluginRefWasDeleted() OVERRIDE;
55 // PPB_ImageData API.
56 virtual PP_Bool Describe(PP_ImageDataDesc* desc) OVERRIDE;
57 virtual void* Map() OVERRIDE;
58 virtual void Unmap() OVERRIDE;
59 virtual int32_t GetSharedMemory(int* handle, uint32_t* byte_count) OVERRIDE;
60 virtual SkCanvas* GetPlatformCanvas() OVERRIDE;
61 virtual SkCanvas* GetCanvas() OVERRIDE;
63 const PP_ImageDataDesc& desc() const { return desc_; }
65 void set_used_in_replace_contents() { used_in_replace_contents_ = true; }
67 // Prepares this image data to be recycled to the plugin. The contents will be
68 // cleared if zero_contents is set.
69 void RecycleToPlugin(bool zero_contents);
71 #if !defined(OS_NACL)
72 static ImageHandle NullHandle();
73 static ImageHandle HandleFromInt(int32_t i);
74 #endif
76 private:
77 PP_ImageDataDesc desc_;
79 #if defined(OS_NACL)
80 base::SharedMemory shm_;
81 uint32 size_;
82 int map_count_;
83 #else
84 scoped_ptr<TransportDIB> transport_dib_;
86 // Null when the image isn't mapped.
87 scoped_ptr<SkCanvas> mapped_canvas_;
88 #endif
90 // Set to true when this ImageData has been used in a call to
91 // Graphics2D.ReplaceContents. This is used to signal that it can be cached.
92 bool used_in_replace_contents_;
94 DISALLOW_COPY_AND_ASSIGN(ImageData);
97 class PPB_ImageData_Proxy : public InterfaceProxy {
98 public:
99 PPB_ImageData_Proxy(Dispatcher* dispatcher);
100 virtual ~PPB_ImageData_Proxy();
102 static PP_Resource CreateProxyResource(PP_Instance instance,
103 PP_ImageDataFormat format,
104 const PP_Size& size,
105 PP_Bool init_to_zero);
107 // InterfaceProxy implementation.
108 virtual bool OnMessageReceived(const IPC::Message& msg);
110 static const ApiID kApiID = API_ID_PPB_IMAGE_DATA;
112 private:
113 // Plugin->Host message handlers.
114 void OnHostMsgCreate(PP_Instance instance,
115 int32_t format,
116 const PP_Size& size,
117 PP_Bool init_to_zero,
118 HostResource* result,
119 std::string* image_data_desc,
120 ImageHandle* result_image_handle);
121 void OnHostMsgCreateNaCl(PP_Instance instance,
122 int32_t format,
123 const PP_Size& size,
124 PP_Bool init_to_zero,
125 HostResource* result,
126 std::string* image_data_desc,
127 ppapi::proxy::SerializedHandle* result_image_handle);
129 // Host->Plugin message handlers.
130 void OnPluginMsgNotifyUnusedImageData(const HostResource& old_image_data);
132 DISALLOW_COPY_AND_ASSIGN(PPB_ImageData_Proxy);
135 } // namespace proxy
136 } // namespace ppapi
138 #endif // PPAPI_PPB_IMAGE_DATA_PROXY_H_