OLD | NEW |
1 /* Copyright (c) 2010 The Chromium Authors. All rights reserved. | 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 | 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 #include <stdlib.h> | 5 #include <stdlib.h> |
6 #include <string.h> | 6 #include <string.h> |
7 | 7 |
8 #include "ppapi/c/pp_completion_callback.h" | 8 #include "ppapi/c/pp_completion_callback.h" |
9 #include "ppapi/c/pp_errors.h" | 9 #include "ppapi/c/pp_errors.h" |
10 #include "ppapi/c/pp_instance.h" | 10 #include "ppapi/c/pp_instance.h" |
11 #include "ppapi/c/pp_module.h" | 11 #include "ppapi/c/pp_module.h" |
12 #include "ppapi/c/pp_size.h" | 12 #include "ppapi/c/pp_size.h" |
13 #include "ppapi/c/pp_var.h" | 13 #include "ppapi/c/pp_var.h" |
14 #include "ppapi/c/ppb.h" | 14 #include "ppapi/c/ppb.h" |
15 #include "ppapi/c/ppb_core.h" | 15 #include "ppapi/c/ppb_core.h" |
16 #include "ppapi/c/ppb_graphics_2d.h" | 16 #include "ppapi/c/ppb_graphics_2d.h" |
17 #include "ppapi/c/ppb_image_data.h" | 17 #include "ppapi/c/ppb_image_data.h" |
18 #include "ppapi/c/ppb_instance.h" | 18 #include "ppapi/c/ppb_instance.h" |
19 #include "ppapi/c/ppp.h" | 19 #include "ppapi/c/ppp.h" |
20 #include "ppapi/c/ppp_instance.h" | 20 #include "ppapi/c/ppp_instance.h" |
21 | 21 |
22 PP_Module g_module_id; | |
23 PPB_GetInterface g_get_browser_interface = NULL; | 22 PPB_GetInterface g_get_browser_interface = NULL; |
24 | 23 |
25 const struct PPB_Core* g_core_interface; | 24 const struct PPB_Core* g_core_interface; |
26 const struct PPB_Graphics2D* g_graphics_2d_interface; | 25 const struct PPB_Graphics2D* g_graphics_2d_interface; |
27 const struct PPB_ImageData* g_image_data_interface; | 26 const struct PPB_ImageData* g_image_data_interface; |
28 const struct PPB_Instance* g_instance_interface; | 27 const struct PPB_Instance* g_instance_interface; |
29 | 28 |
30 /* PPP_Instance implementation -----------------------------------------------*/ | 29 /* PPP_Instance implementation -----------------------------------------------*/ |
31 | 30 |
32 struct InstanceInfo { | 31 struct InstanceInfo { |
33 PP_Instance pp_instance; | 32 PP_Instance pp_instance; |
34 struct PP_Size last_size; | 33 struct PP_Size last_size; |
35 | 34 |
36 struct InstanceInfo* next; | 35 struct InstanceInfo* next; |
37 }; | 36 }; |
38 | 37 |
39 /** Linked list of all live instances. */ | 38 /** Linked list of all live instances. */ |
40 struct InstanceInfo* all_instances = NULL; | 39 struct InstanceInfo* all_instances = NULL; |
41 | 40 |
42 /** Returns a refed resource corresponding to the created device context. */ | 41 /** Returns a refed resource corresponding to the created device context. */ |
43 PP_Resource MakeAndBindDeviceContext(PP_Instance instance, | 42 PP_Resource MakeAndBindDeviceContext(PP_Instance instance, |
44 const struct PP_Size* size) { | 43 const struct PP_Size* size) { |
45 PP_Resource device_context; | 44 PP_Resource device_context; |
46 | 45 |
47 device_context = g_graphics_2d_interface->Create(g_module_id, size, PP_FALSE); | 46 device_context = g_graphics_2d_interface->Create(instance, size, PP_FALSE); |
48 if (!device_context) | 47 if (!device_context) |
49 return 0; | 48 return 0; |
50 | 49 |
51 if (!g_instance_interface->BindGraphics(instance, device_context)) { | 50 if (!g_instance_interface->BindGraphics(instance, device_context)) { |
52 g_core_interface->ReleaseResource(device_context); | 51 g_core_interface->ReleaseResource(device_context); |
53 return 0; | 52 return 0; |
54 } | 53 } |
55 return device_context; | 54 return device_context; |
56 } | 55 } |
57 | 56 |
58 void FlushCompletionCallback(void* user_data, int32_t result) { | 57 void FlushCompletionCallback(void* user_data, int32_t result) { |
59 /* Don't need to do anything here. */ | 58 /* Don't need to do anything here. */ |
60 } | 59 } |
61 | 60 |
62 void Repaint(struct InstanceInfo* instance, const struct PP_Size* size) { | 61 void Repaint(struct InstanceInfo* instance, const struct PP_Size* size) { |
63 PP_Resource image, device_context; | 62 PP_Resource image, device_context; |
64 struct PP_ImageDataDesc image_desc; | 63 struct PP_ImageDataDesc image_desc; |
65 uint32_t* image_data; | 64 uint32_t* image_data; |
66 int num_words, i; | 65 int num_words, i; |
67 | 66 |
68 /* Create image data to paint into. */ | 67 /* Create image data to paint into. */ |
69 image = g_image_data_interface->Create( | 68 image = g_image_data_interface->Create( |
70 g_module_id, PP_IMAGEDATAFORMAT_BGRA_PREMUL, size, PP_TRUE); | 69 instance->pp_instance, PP_IMAGEDATAFORMAT_BGRA_PREMUL, size, PP_TRUE); |
71 if (!image) | 70 if (!image) |
72 return; | 71 return; |
73 g_image_data_interface->Describe(image, &image_desc); | 72 g_image_data_interface->Describe(image, &image_desc); |
74 | 73 |
75 /* Fill the image with blue. */ | 74 /* Fill the image with blue. */ |
76 image_data = (uint32_t*)g_image_data_interface->Map(image); | 75 image_data = (uint32_t*)g_image_data_interface->Map(image); |
77 if (!image_data) { | 76 if (!image_data) { |
78 g_core_interface->ReleaseResource(image); | 77 g_core_interface->ReleaseResource(image); |
79 return; | 78 return; |
80 } | 79 } |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 &Instance_HandleInputEvent, | 180 &Instance_HandleInputEvent, |
182 &Instance_HandleDocumentLoad, | 181 &Instance_HandleDocumentLoad, |
183 &Instance_GetInstanceObject, | 182 &Instance_GetInstanceObject, |
184 }; | 183 }; |
185 | 184 |
186 | 185 |
187 /* Global entrypoints --------------------------------------------------------*/ | 186 /* Global entrypoints --------------------------------------------------------*/ |
188 | 187 |
189 PP_EXPORT int32_t PPP_InitializeModule(PP_Module module, | 188 PP_EXPORT int32_t PPP_InitializeModule(PP_Module module, |
190 PPB_GetInterface get_browser_interface) { | 189 PPB_GetInterface get_browser_interface) { |
191 /* Save the global module information for later. */ | |
192 g_module_id = module; | |
193 g_get_browser_interface = get_browser_interface; | 190 g_get_browser_interface = get_browser_interface; |
194 | 191 |
195 g_core_interface = (const struct PPB_Core*) | 192 g_core_interface = (const struct PPB_Core*) |
196 get_browser_interface(PPB_CORE_INTERFACE); | 193 get_browser_interface(PPB_CORE_INTERFACE); |
197 g_instance_interface = (const struct PPB_Instance*) | 194 g_instance_interface = (const struct PPB_Instance*) |
198 get_browser_interface(PPB_INSTANCE_INTERFACE); | 195 get_browser_interface(PPB_INSTANCE_INTERFACE); |
199 g_image_data_interface = (const struct PPB_ImageData*) | 196 g_image_data_interface = (const struct PPB_ImageData*) |
200 get_browser_interface(PPB_IMAGEDATA_INTERFACE); | 197 get_browser_interface(PPB_IMAGEDATA_INTERFACE); |
201 g_graphics_2d_interface = (const struct PPB_Graphics2D*) | 198 g_graphics_2d_interface = (const struct PPB_Graphics2D*) |
202 get_browser_interface(PPB_GRAPHICS_2D_INTERFACE); | 199 get_browser_interface(PPB_GRAPHICS_2D_INTERFACE); |
203 if (!g_core_interface || !g_instance_interface || !g_image_data_interface || | 200 if (!g_core_interface || !g_instance_interface || !g_image_data_interface || |
204 !g_graphics_2d_interface) | 201 !g_graphics_2d_interface) |
205 return -1; | 202 return -1; |
206 | 203 |
207 return PP_OK; | 204 return PP_OK; |
208 } | 205 } |
209 | 206 |
210 PP_EXPORT void PPP_ShutdownModule() { | 207 PP_EXPORT void PPP_ShutdownModule() { |
211 } | 208 } |
212 | 209 |
213 PP_EXPORT const void* PPP_GetInterface(const char* interface_name) { | 210 PP_EXPORT const void* PPP_GetInterface(const char* interface_name) { |
214 if (strcmp(interface_name, PPP_INSTANCE_INTERFACE) == 0) | 211 if (strcmp(interface_name, PPP_INSTANCE_INTERFACE) == 0) |
215 return &instance_interface; | 212 return &instance_interface; |
216 return NULL; | 213 return NULL; |
217 } | 214 } |
218 | 215 |
OLD | NEW |