| 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" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 | 24 |
| 25 const struct PPB_Core* g_core_interface; | 25 const struct PPB_Core* g_core_interface; |
| 26 const struct PPB_Graphics2D* g_graphics_2d_interface; | 26 const struct PPB_Graphics2D* g_graphics_2d_interface; |
| 27 const struct PPB_ImageData* g_image_data_interface; | 27 const struct PPB_ImageData* g_image_data_interface; |
| 28 const struct PPB_Instance* g_instance_interface; | 28 const struct PPB_Instance* g_instance_interface; |
| 29 | 29 |
| 30 // PPP_Instance implementation ------------------------------------------------- | 30 // PPP_Instance implementation ------------------------------------------------- |
| 31 | 31 |
| 32 struct InstanceInfo { | 32 struct InstanceInfo { |
| 33 PP_Instance pp_instance; | 33 PP_Instance pp_instance; |
| 34 PP_Size last_size; | 34 struct PP_Size last_size; |
| 35 | 35 |
| 36 InstanceInfo* next; | 36 struct InstanceInfo* next; |
| 37 }; | 37 }; |
| 38 | 38 |
| 39 // Linked list of all live instances. | 39 // Linked list of all live instances. |
| 40 InstanceInfo* all_instances = NULL; | 40 struct InstanceInfo* all_instances = NULL; |
| 41 | 41 |
| 42 // Returns a refed resource corresponding to the created device context. | 42 // Returns a refed resource corresponding to the created device context. |
| 43 PP_Resource MakeAndBindDeviceContext(PP_Instance instance, | 43 PP_Resource MakeAndBindDeviceContext(PP_Instance instance, |
| 44 const struct PP_Size* size) { | 44 const struct PP_Size* size) { |
| 45 PP_Resource device_context; | 45 PP_Resource device_context; |
| 46 | 46 |
| 47 device_context = g_graphics_2d_interface->Create(g_module_id, size, false); | 47 device_context = g_graphics_2d_interface->Create(g_module_id, size, PP_FALSE); |
| 48 if (!device_context) | 48 if (!device_context) |
| 49 return 0; | 49 return 0; |
| 50 | 50 |
| 51 if (!g_instance_interface->BindGraphics(instance, device_context)) { | 51 if (!g_instance_interface->BindGraphics(instance, device_context)) { |
| 52 g_core_interface->ReleaseResource(device_context); | 52 g_core_interface->ReleaseResource(device_context); |
| 53 return 0; | 53 return 0; |
| 54 } | 54 } |
| 55 return device_context; | 55 return device_context; |
| 56 } | 56 } |
| 57 | 57 |
| 58 void FlushCompletionCallback(void* user_data, int32_t result) { | 58 void FlushCompletionCallback(void* user_data, int32_t result) { |
| 59 // Don't need to do anything here. | 59 // Don't need to do anything here. |
| 60 } | 60 } |
| 61 | 61 |
| 62 void Repaint(InstanceInfo* instance, const struct PP_Size* size) { | 62 void Repaint(struct InstanceInfo* instance, const struct PP_Size* size) { |
| 63 PP_Resource image, device_context; | 63 PP_Resource image, device_context; |
| 64 PP_ImageDataDesc image_desc; | 64 struct PP_ImageDataDesc image_desc; |
| 65 uint32_t* image_data; | 65 uint32_t* image_data; |
| 66 int num_words, i; | 66 int num_words, i; |
| 67 | 67 |
| 68 // Create image data to paint into. | 68 // Create image data to paint into. |
| 69 image = g_image_data_interface->Create( | 69 image = g_image_data_interface->Create( |
| 70 g_module_id, PP_IMAGEDATAFORMAT_BGRA_PREMUL, size, true); | 70 g_module_id, PP_IMAGEDATAFORMAT_BGRA_PREMUL, size, PP_TRUE); |
| 71 if (!image) | 71 if (!image) |
| 72 return; | 72 return; |
| 73 g_image_data_interface->Describe(image, &image_desc); | 73 g_image_data_interface->Describe(image, &image_desc); |
| 74 | 74 |
| 75 // Fill the image with blue. | 75 // Fill the image with blue. |
| 76 image_data = (uint32_t*)g_image_data_interface->Map(image); | 76 image_data = (uint32_t*)g_image_data_interface->Map(image); |
| 77 if (!image_data) { | 77 if (!image_data) { |
| 78 g_core_interface->ReleaseResource(image); | 78 g_core_interface->ReleaseResource(image); |
| 79 return; | 79 return; |
| 80 } | 80 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 91 | 91 |
| 92 g_graphics_2d_interface->ReplaceContents(device_context, image); | 92 g_graphics_2d_interface->ReplaceContents(device_context, image); |
| 93 g_graphics_2d_interface->Flush(device_context, | 93 g_graphics_2d_interface->Flush(device_context, |
| 94 PP_MakeCompletionCallback(&FlushCompletionCallback, NULL)); | 94 PP_MakeCompletionCallback(&FlushCompletionCallback, NULL)); |
| 95 | 95 |
| 96 g_core_interface->ReleaseResource(device_context); | 96 g_core_interface->ReleaseResource(device_context); |
| 97 g_core_interface->ReleaseResource(image); | 97 g_core_interface->ReleaseResource(image); |
| 98 } | 98 } |
| 99 | 99 |
| 100 // Returns the info for the given instance, or NULL if it's not found. | 100 // Returns the info for the given instance, or NULL if it's not found. |
| 101 InstanceInfo* FindInstance(PP_Instance instance) { | 101 struct InstanceInfo* FindInstance(PP_Instance instance) { |
| 102 InstanceInfo* cur = all_instances; | 102 struct InstanceInfo* cur = all_instances; |
| 103 while (cur) { | 103 while (cur) { |
| 104 if (cur->pp_instance == instance) | 104 if (cur->pp_instance == instance) |
| 105 return cur; | 105 return cur; |
| 106 } | 106 } |
| 107 return NULL; | 107 return NULL; |
| 108 } | 108 } |
| 109 | 109 |
| 110 bool Instance_New(PP_Instance instance) { | 110 PP_Bool Instance_DidCreate(PP_Instance instance, |
| 111 InstanceInfo* info = (InstanceInfo*)malloc(sizeof(InstanceInfo)); | 111 uint32_t argc, |
| 112 const char* argn[], |
| 113 const char* argv[]) { |
| 114 struct InstanceInfo* info = |
| 115 (struct InstanceInfo*)malloc(sizeof(struct InstanceInfo)); |
| 112 info->pp_instance = instance; | 116 info->pp_instance = instance; |
| 113 info->last_size.width = 0; | 117 info->last_size.width = 0; |
| 114 info->last_size.height = 0; | 118 info->last_size.height = 0; |
| 115 | 119 |
| 116 // Insert into linked list of live instances. | 120 // Insert into linked list of live instances. |
| 117 info->next = all_instances; | 121 info->next = all_instances; |
| 118 all_instances = info; | 122 all_instances = info; |
| 119 return true; | 123 return PP_TRUE; |
| 120 } | 124 } |
| 121 | 125 |
| 122 void Instance_Delete(PP_Instance instance) { | 126 void Instance_DidDestroy(PP_Instance instance) { |
| 123 // Find the matching item in the linked list, delete it, and patch the links. | 127 // Find the matching item in the linked list, delete it, and patch the links. |
| 124 InstanceInfo** prev_ptr = &all_instances; | 128 struct InstanceInfo** prev_ptr = &all_instances; |
| 125 InstanceInfo* cur = all_instances; | 129 struct InstanceInfo* cur = all_instances; |
| 126 while (cur) { | 130 while (cur) { |
| 127 if (instance == cur->pp_instance) { | 131 if (instance == cur->pp_instance) { |
| 128 *prev_ptr = cur->next; | 132 *prev_ptr = cur->next; |
| 129 free(cur); | 133 free(cur); |
| 130 return; | 134 return; |
| 131 } | 135 } |
| 132 prev_ptr = &cur->next; | 136 prev_ptr = &cur->next; |
| 133 } | 137 } |
| 134 } | 138 } |
| 135 | 139 |
| 136 bool Instance_Initialize(PP_Instance pp_instance, | 140 void Instance_DidChangeView(PP_Instance pp_instance, |
| 137 uint32_t argc, | 141 const struct PP_Rect* position, |
| 138 const char* argn[], | 142 const struct PP_Rect* clip) { |
| 139 const char* argv[]) { | 143 struct InstanceInfo* info = FindInstance(pp_instance); |
| 140 return true; | |
| 141 } | |
| 142 | |
| 143 bool Instance_HandleDocumentLoad(PP_Instance pp_instance, | |
| 144 PP_Resource pp_url_loader) { | |
| 145 return false; | |
| 146 } | |
| 147 | |
| 148 bool Instance_HandleInputEvent(PP_Instance pp_instance, | |
| 149 const struct PP_InputEvent* event) { | |
| 150 // We don't handle any events. | |
| 151 return false; | |
| 152 } | |
| 153 | |
| 154 void Instance_HandleFocusChanged(bool /*has_focus*/) { | |
| 155 } | |
| 156 | |
| 157 PP_Var Instance_GetInstanceObject(PP_Instance pp_instance) { | |
| 158 return PP_MakeNull(); | |
| 159 } | |
| 160 | |
| 161 void Instance_ViewChanged(PP_Instance pp_instance, | |
| 162 const struct PP_Rect* position, | |
| 163 const struct PP_Rect* clip) { | |
| 164 InstanceInfo* info = FindInstance(pp_instance); | |
| 165 if (!info) | 144 if (!info) |
| 166 return; | 145 return; |
| 167 | 146 |
| 168 if (info->last_size.width != position->size.width || | 147 if (info->last_size.width != position->size.width || |
| 169 info->last_size.height != position->size.height) { | 148 info->last_size.height != position->size.height) { |
| 170 // Got a resize, repaint the plugin. | 149 // Got a resize, repaint the plugin. |
| 171 Repaint(info, &position->size); | 150 Repaint(info, &position->size); |
| 172 info->last_size.width = position->size.width; | 151 info->last_size.width = position->size.width; |
| 173 info->last_size.height = position->size.height; | 152 info->last_size.height = position->size.height; |
| 174 } | 153 } |
| 175 } | 154 } |
| 176 | 155 |
| 177 PP_Var Instance_GetSelectedText(PP_Instance pp_instance, | 156 void Instance_DidChangeFocus(PP_Instance pp_instance, PP_Bool has_focus) { |
| 178 bool html) { | 157 } |
| 158 |
| 159 PP_Bool Instance_HandleInputEvent(PP_Instance pp_instance, |
| 160 const struct PP_InputEvent* event) { |
| 161 // We don't handle any events. |
| 162 return PP_FALSE; |
| 163 } |
| 164 |
| 165 PP_Bool Instance_HandleDocumentLoad(PP_Instance pp_instance, |
| 166 PP_Resource pp_url_loader) { |
| 167 return PP_FALSE; |
| 168 } |
| 169 |
| 170 struct PP_Var Instance_GetInstanceObject(PP_Instance pp_instance) { |
| 179 return PP_MakeNull(); | 171 return PP_MakeNull(); |
| 180 } | 172 } |
| 181 | 173 |
| 182 static PPP_Instance instance_interface = { | 174 static struct PPP_Instance instance_interface = { |
| 183 &Instance_New, | 175 &Instance_DidCreate, |
| 184 &Instance_Delete, | 176 &Instance_DidDestroy, |
| 185 &Instance_Initialize, | 177 &Instance_DidChangeView, |
| 178 &Instance_DidChangeFocus, |
| 179 &Instance_HandleInputEvent, |
| 186 &Instance_HandleDocumentLoad, | 180 &Instance_HandleDocumentLoad, |
| 187 &Instance_HandleInputEvent, | |
| 188 &Instance_HandleFocusChanged, | |
| 189 &Instance_GetInstanceObject, | 181 &Instance_GetInstanceObject, |
| 190 &Instance_ViewChanged, | |
| 191 &Instance_GetSelectedText, | |
| 192 }; | 182 }; |
| 193 | 183 |
| 194 | 184 |
| 195 // Global entrypoints ---------------------------------------------------------- | 185 // Global entrypoints ---------------------------------------------------------- |
| 196 | 186 |
| 197 PP_EXPORT int32_t PPP_InitializeModule(PP_Module module, | 187 PP_EXPORT int32_t PPP_InitializeModule(PP_Module module, |
| 198 PPB_GetInterface get_browser_interface) { | 188 PPB_GetInterface get_browser_interface) { |
| 199 // Save the global module information for later. | 189 // Save the global module information for later. |
| 200 g_module_id = module; | 190 g_module_id = module; |
| 201 g_get_browser_interface = get_browser_interface; | 191 g_get_browser_interface = get_browser_interface; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 216 } | 206 } |
| 217 | 207 |
| 218 PP_EXPORT void PPP_ShutdownModule() { | 208 PP_EXPORT void PPP_ShutdownModule() { |
| 219 } | 209 } |
| 220 | 210 |
| 221 PP_EXPORT const void* PPP_GetInterface(const char* interface_name) { | 211 PP_EXPORT const void* PPP_GetInterface(const char* interface_name) { |
| 222 if (strcmp(interface_name, PPP_INSTANCE_INTERFACE) == 0) | 212 if (strcmp(interface_name, PPP_INSTANCE_INTERFACE) == 0) |
| 223 return &instance_interface; | 213 return &instance_interface; |
| 224 return NULL; | 214 return NULL; |
| 225 } | 215 } |
| OLD | NEW |