summaryrefslogtreecommitdiffstats
path: root/ppapi/examples
diff options
context:
space:
mode:
authortommycli <tommycli@chromium.org>2015-04-07 09:58:51 -0700
committerCommit bot <commit-bot@chromium.org>2015-04-07 17:01:00 +0000
commita1b9fb3524473610a204e2c39ecd681f67d3db20 (patch)
tree7cd220c3946ff994a8f3b6a78a8fa0c641850f26 /ppapi/examples
parent709579eedbd4c8a5d116398bd8b76e7c13366c22 (diff)
downloadchromium_src-a1b9fb3524473610a204e2c39ecd681f67d3db20.zip
chromium_src-a1b9fb3524473610a204e2c39ecd681f67d3db20.tar.gz
chromium_src-a1b9fb3524473610a204e2c39ecd681f67d3db20.tar.bz2
PPAPI Examples: Fix painting in Graphics 2D example.
Releasing the Graphics2D at the end of the Repaint method causes the blue image to never be visible to anyone who runs the 2d.html example. (At least on Linux) This saves the created Graphics 2D, saves it, and releases it when the plugin instance is destroyed. BUG= Review URL: https://codereview.chromium.org/1065733003 Cr-Commit-Position: refs/heads/master@{#324059}
Diffstat (limited to 'ppapi/examples')
-rw-r--r--ppapi/examples/2d/graphics_2d_example.c25
1 files changed, 14 insertions, 11 deletions
diff --git a/ppapi/examples/2d/graphics_2d_example.c b/ppapi/examples/2d/graphics_2d_example.c
index 085f0cf..0f32617 100644
--- a/ppapi/examples/2d/graphics_2d_example.c
+++ b/ppapi/examples/2d/graphics_2d_example.c
@@ -33,6 +33,7 @@ const PPB_View* g_view_interface;
struct InstanceInfo {
PP_Instance pp_instance;
struct PP_Size last_size;
+ PP_Resource graphics;
struct InstanceInfo* next;
};
@@ -61,11 +62,18 @@ void FlushCompletionCallback(void* user_data, int32_t result) {
}
void Repaint(struct InstanceInfo* instance, const struct PP_Size* size) {
- PP_Resource image, graphics;
+ PP_Resource image;
struct PP_ImageDataDesc image_desc;
uint32_t* image_data;
int num_words, i;
+ /* Ensure the graphics 2d is ready. */
+ if (!instance->graphics) {
+ instance->graphics = MakeAndBindGraphics2D(instance->pp_instance, size);
+ if (!instance->graphics)
+ return;
+ }
+
/* Create image data to paint into. */
image = g_image_data_interface->Create(
instance->pp_instance, PP_IMAGEDATAFORMAT_BGRA_PREMUL, size, PP_TRUE);
@@ -83,18 +91,11 @@ void Repaint(struct InstanceInfo* instance, const struct PP_Size* size) {
for (i = 0; i < num_words; i++)
image_data[i] = 0xFF0000FF;
- /* Create the graphics 2d and paint the image to it. */
- graphics = MakeAndBindGraphics2D(instance->pp_instance, size);
- if (!graphics) {
- g_core_interface->ReleaseResource(image);
- return;
- }
-
- g_graphics_2d_interface->ReplaceContents(graphics, image);
- g_graphics_2d_interface->Flush(graphics,
+ /* Paint image to graphics 2d. */
+ g_graphics_2d_interface->ReplaceContents(instance->graphics, image);
+ g_graphics_2d_interface->Flush(instance->graphics,
PP_MakeCompletionCallback(&FlushCompletionCallback, NULL));
- g_core_interface->ReleaseResource(graphics);
g_core_interface->ReleaseResource(image);
}
@@ -118,6 +119,7 @@ PP_Bool Instance_DidCreate(PP_Instance instance,
info->pp_instance = instance;
info->last_size.width = 0;
info->last_size.height = 0;
+ info->graphics = 0;
/* Insert into linked list of live instances. */
info->next = all_instances;
@@ -134,6 +136,7 @@ void Instance_DidDestroy(PP_Instance instance) {
while (cur) {
if (instance == cur->pp_instance) {
*prev_ptr = cur->next;
+ g_core_interface->ReleaseResource(cur->graphics);
free(cur);
return;
}