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

Side by Side Diff: ppapi/native_client/tests/earth/pepper_c.c

Issue 8951014: Change the DidChangeView update to take a new ViewChanged resource. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: More nacl fixes Created 8 years, 11 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 /* 1 /*
2 * Copyright (c) 2011 The Chromium Authors. All rights reserved. 2 * Copyright (c) 2011 The Chromium Authors. All rights reserved.
3 * Use of this source code is governed by a BSD-style license that can be 3 * Use of this source code is governed by a BSD-style license that can be
4 * found in the LICENSE file. 4 * found in the LICENSE file.
5 */ 5 */
6 6
7 /* NaCl Earth demo */ 7 /* NaCl Earth demo */
8 /* Pepper code in C */ 8 /* Pepper code in C */
9 9
10 #include "native_client/tests/earth/earth.h" 10 #include "native_client/tests/earth/earth.h"
11 11
12 #include <assert.h> 12 #include <assert.h>
13 #include <stdbool.h> 13 #include <stdbool.h>
14 #include <stdio.h> 14 #include <stdio.h>
15 15
16 /* Pepper includes */ 16 /* Pepper includes */
17 #include "ppapi/c/pp_completion_callback.h" 17 #include "ppapi/c/pp_completion_callback.h"
18 #include "ppapi/c/pp_errors.h" 18 #include "ppapi/c/pp_errors.h"
19 #include "ppapi/c/pp_instance.h" 19 #include "ppapi/c/pp_instance.h"
20 #include "ppapi/c/pp_module.h" 20 #include "ppapi/c/pp_module.h"
21 #include "ppapi/c/pp_point.h" 21 #include "ppapi/c/pp_point.h"
22 #include "ppapi/c/pp_rect.h" 22 #include "ppapi/c/pp_rect.h"
23 #include "ppapi/c/pp_size.h" 23 #include "ppapi/c/pp_size.h"
24 #include "ppapi/c/ppb_core.h" 24 #include "ppapi/c/ppb_core.h"
25 #include "ppapi/c/ppb_graphics_2d.h" 25 #include "ppapi/c/ppb_graphics_2d.h"
26 #include "ppapi/c/ppb_image_data.h" 26 #include "ppapi/c/ppb_image_data.h"
27 #include "ppapi/c/ppb_instance.h" 27 #include "ppapi/c/ppb_instance.h"
28 #include "ppapi/c/ppb_view.h"
28 #include "ppapi/c/ppp.h" 29 #include "ppapi/c/ppp.h"
29 #include "ppapi/c/ppp_instance.h" 30 #include "ppapi/c/ppp_instance.h"
30 31
31 #define NUMBER_OF_IMAGES 2 32 #define NUMBER_OF_IMAGES 2
32 33
33 PPB_GetInterface g_get_browser_interface = NULL; 34 PPB_GetInterface g_get_browser_interface = NULL;
34 35
35 /* NOTE on PP_Instance: In general Pepper is designed such that a 36 /* NOTE on PP_Instance: In general Pepper is designed such that a
36 * single plugin process can implement multiple plugin instances. 37 * single plugin process can implement multiple plugin instances.
37 * This might occur, for example, if a plugin were instantiated by 38 * This might occur, for example, if a plugin were instantiated by
38 * multiple <embed ...> tags in a single page. 39 * multiple <embed ...> tags in a single page.
39 * 40 *
40 * This implementation assumes at most one instance per plugin, 41 * This implementation assumes at most one instance per plugin,
41 * consistent with limitations of the current implementation of 42 * consistent with limitations of the current implementation of
42 * Native Client. 43 * Native Client.
43 */ 44 */
44 struct PepperState { 45 struct PepperState {
45 const struct PPB_Core* core_interface; 46 const struct PPB_Core* core_interface;
46 const struct PPB_Graphics2D* graphics_2d_interface; 47 const struct PPB_Graphics2D* graphics_2d_interface;
47 const struct PPB_ImageData* image_data_interface; 48 const struct PPB_ImageData* image_data_interface;
48 const struct PPB_Instance* instance_interface; 49 const struct PPB_Instance* instance_interface;
50 const struct PPB_View* view_interface;
49 PP_Resource device_context; 51 PP_Resource device_context;
50 int32_t which_image; 52 int32_t which_image;
51 PP_Resource image[NUMBER_OF_IMAGES]; 53 PP_Resource image[NUMBER_OF_IMAGES];
52 uint32_t* image_data[NUMBER_OF_IMAGES]; 54 uint32_t* image_data[NUMBER_OF_IMAGES];
53 PP_Instance instance; 55 PP_Instance instance;
54 struct PP_Rect position; 56 struct PP_Rect position;
55 bool ready; 57 bool ready;
56 }; 58 };
57 struct PepperState g_MyState; 59 struct PepperState g_MyState;
58 bool g_MyStateIsValid = false; 60 bool g_MyStateIsValid = false;
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 if (!device_context) return 0; 124 if (!device_context) return 0;
123 125
124 if (!g_MyState.instance_interface->BindGraphics(instance, device_context)) { 126 if (!g_MyState.instance_interface->BindGraphics(instance, device_context)) {
125 g_MyState.core_interface->ReleaseResource(device_context); 127 g_MyState.core_interface->ReleaseResource(device_context);
126 return 0; 128 return 0;
127 } 129 }
128 return device_context; 130 return device_context;
129 } 131 }
130 132
131 static void Instance_DidChangeView(PP_Instance pp_instance, 133 static void Instance_DidChangeView(PP_Instance pp_instance,
132 const struct PP_Rect* position, 134 PP_Resource pp_view) {
133 const struct PP_Rect* clip) {
134 DebugPrintf("DidChangeView(%x)\n", pp_instance); 135 DebugPrintf("DidChangeView(%x)\n", pp_instance);
135 assert(g_MyStateIsValid == true); 136 assert(g_MyStateIsValid == true);
136 assert(g_MyState.instance == pp_instance); 137 assert(g_MyState.instance == pp_instance);
137 138
138 g_MyState.position = *position; 139 g_MyState.view_interface->GetRect(pp_view, &g_MyState.position);
139 if (g_MyState.ready == false) { 140 if (g_MyState.ready == false) {
140 g_MyState.device_context = 141 g_MyState.device_context =
141 MakeAndBindDeviceContext(pp_instance, &position->size); 142 MakeAndBindDeviceContext(pp_instance, &g_MyState.position.size);
142 /* create device context */ 143 /* create device context */
143 if (!g_MyState.device_context) { 144 if (!g_MyState.device_context) {
144 DebugPrintf("device_context is null!\n"); 145 DebugPrintf("device_context is null!\n");
145 return; 146 return;
146 } 147 }
147 /* 148 /*
148 * Create double-buffered image data. 149 * Create double-buffered image data.
149 * Note: This example does not use transparent pixels. All pixels are 150 * Note: This example does not use transparent pixels. All pixels are
150 * written into the framebuffer with alpha set to 255 (opaque) 151 * written into the framebuffer with alpha set to 255 (opaque)
151 * Note: Pepper uses premultiplied alpha. 152 * Note: Pepper uses premultiplied alpha.
152 */ 153 */
153 g_MyState.which_image = 0; 154 g_MyState.which_image = 0;
154 for (int i = 0; i < NUMBER_OF_IMAGES; ++i) { 155 for (int i = 0; i < NUMBER_OF_IMAGES; ++i) {
155 g_MyState.image[i] = 156 g_MyState.image[i] =
156 g_MyState.image_data_interface->Create(pp_instance, 157 g_MyState.image_data_interface->Create(pp_instance,
157 PP_IMAGEDATAFORMAT_BGRA_PREMUL, &position->size, PP_TRUE); 158 PP_IMAGEDATAFORMAT_BGRA_PREMUL, &g_MyState.position.size, PP_TRUE);
158 if (!g_MyState.image[i]) { 159 if (!g_MyState.image[i]) {
159 DebugPrintf("image resource is invalid!\n"); 160 DebugPrintf("image resource is invalid!\n");
160 return; 161 return;
161 } 162 }
162 g_MyState.image_data[i] = 163 g_MyState.image_data[i] =
163 (uint32_t*)g_MyState.image_data_interface->Map(g_MyState.image[i]); 164 (uint32_t*)g_MyState.image_data_interface->Map(g_MyState.image[i]);
164 if (!g_MyState.image_data[i]) { 165 if (!g_MyState.image_data[i]) {
165 DebugPrintf("could not allocate image_data\n"); 166 DebugPrintf("could not allocate image_data\n");
166 return; 167 return;
167 } 168 }
168 size_t size_in_bytes = position->size.width * position->size.height * 169 size_t size_in_bytes = g_MyState.position.size.width *
169 sizeof(uint32_t); 170 g_MyState.position.size.height * sizeof(uint32_t);
170 memset(g_MyState.image_data[i], 0, size_in_bytes); 171 memset(g_MyState.image_data[i], 0, size_in_bytes);
171 } 172 }
172 g_MyState.ready = true; 173 g_MyState.ready = true;
173 Repaint(&g_MyState); 174 Repaint(&g_MyState);
174 } 175 }
175 } 176 }
176 177
177 static void Instance_DidChangeFocus(PP_Instance pp_instance, 178 static void Instance_DidChangeFocus(PP_Instance pp_instance,
178 PP_Bool has_focus) { 179 PP_Bool has_focus) {
179 } 180 }
(...skipping 19 matching lines...) Expand all
199 g_get_browser_interface = get_browser_interface; 200 g_get_browser_interface = get_browser_interface;
200 201
201 g_MyState.core_interface = (const struct PPB_Core*) 202 g_MyState.core_interface = (const struct PPB_Core*)
202 get_browser_interface(PPB_CORE_INTERFACE); 203 get_browser_interface(PPB_CORE_INTERFACE);
203 g_MyState.instance_interface = (const struct PPB_Instance*) 204 g_MyState.instance_interface = (const struct PPB_Instance*)
204 get_browser_interface(PPB_INSTANCE_INTERFACE); 205 get_browser_interface(PPB_INSTANCE_INTERFACE);
205 g_MyState.image_data_interface = (const struct PPB_ImageData*) 206 g_MyState.image_data_interface = (const struct PPB_ImageData*)
206 get_browser_interface(PPB_IMAGEDATA_INTERFACE); 207 get_browser_interface(PPB_IMAGEDATA_INTERFACE);
207 g_MyState.graphics_2d_interface = (const struct PPB_Graphics2D*) 208 g_MyState.graphics_2d_interface = (const struct PPB_Graphics2D*)
208 get_browser_interface(PPB_GRAPHICS_2D_INTERFACE); 209 get_browser_interface(PPB_GRAPHICS_2D_INTERFACE);
210 g_MyState.view_interface = (const struct PPB_View*)
211 get_browser_interface(PPB_VIEW_INTERFACE);
209 if (!g_MyState.core_interface || 212 if (!g_MyState.core_interface ||
210 !g_MyState.instance_interface || 213 !g_MyState.instance_interface ||
211 !g_MyState.image_data_interface || 214 !g_MyState.image_data_interface ||
212 !g_MyState.graphics_2d_interface) 215 !g_MyState.graphics_2d_interface ||
216 !g_MyState.view_interface)
213 return -1; 217 return -1;
214 218
215 return PP_OK; 219 return PP_OK;
216 } 220 }
217 221
218 PP_EXPORT void PPP_ShutdownModule() { 222 PP_EXPORT void PPP_ShutdownModule() {
219 } 223 }
220 224
221 PP_EXPORT const void* PPP_GetInterface(const char* interface_name) { 225 PP_EXPORT const void* PPP_GetInterface(const char* interface_name) {
222 if (strcmp(interface_name, PPP_INSTANCE_INTERFACE) == 0) 226 if (strcmp(interface_name, PPP_INSTANCE_INTERFACE) == 0)
223 return &instance_interface; 227 return &instance_interface;
224 return NULL; 228 return NULL;
225 } 229 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698