| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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.auto | 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_rect.h" | 8 #include "ppapi/c/pp_rect.h" |
| 9 #include "ppapi/c/pp_resource.h" | 9 #include "ppapi/c/pp_resource.h" |
| 10 #include "ppapi/c/pp_size.h" | 10 #include "ppapi/c/pp_size.h" |
| 11 #include "ppapi/c/ppb_core.h" | 11 #include "ppapi/c/ppb_core.h" |
| 12 #include "ppapi/c/ppb_graphics_2d.h" | 12 #include "ppapi/c/ppb_graphics_2d.h" |
| 13 #include "ppapi/c/ppb_image_data.h" | 13 #include "ppapi/c/ppb_image_data.h" |
| 14 #include "ppapi/c/ppb_instance.h" | 14 #include "ppapi/c/ppb_instance.h" |
| 15 #include "ppapi/c/ppb_view.h" | 15 #include "ppapi/c/ppb_view.h" |
| 16 #include "ppapi/cpp/image_data.h" | 16 #include "ppapi/cpp/image_data.h" |
| 17 | 17 |
| 18 #include "ppapi_simple/ps.h" | 18 #include "ppapi_simple/ps.h" |
| 19 #include "ppapi_simple/ps_context_2d.h" | 19 #include "ppapi_simple/ps_context_2d.h" |
| 20 #include "ppapi_simple/ps_event.h" | 20 #include "ppapi_simple/ps_event.h" |
| 21 #include "ppapi_simple/ps_instance.h" | 21 #include "ppapi_simple/ps_instance.h" |
| 22 #include "ppapi_simple/ps_interface.h" | 22 #include "ppapi_simple/ps_interface.h" |
| 23 | 23 |
| 24 PSContext2D_t* PSContext2DAllocate() { | 24 PSContext2D_t* PSContext2DAllocate(PP_ImageDataFormat format) { |
| 25 PSContext2D_t* ctx = (PSContext2D_t*) malloc(sizeof(PSContext2D_t)); | 25 PSContext2D_t* ctx = (PSContext2D_t*) malloc(sizeof(PSContext2D_t)); |
| 26 memset(ctx, 0, sizeof(PSContext2D_t)); | 26 memset(ctx, 0, sizeof(PSContext2D_t)); |
| 27 | 27 |
| 28 ctx->format = PSInterfaceImageData()->GetNativeImageDataFormat(); | 28 ctx->format = format; |
| 29 return ctx; | 29 return ctx; |
| 30 } | 30 } |
| 31 | 31 |
| 32 void PSContext2DFree(PSContext2D_t* ctx) { | 32 void PSContext2DFree(PSContext2D_t* ctx) { |
| 33 if (ctx->graphic_2d) { | 33 if (ctx->graphic_2d) { |
| 34 PSInterfaceCore()->ReleaseResource(ctx->graphic_2d); | 34 PSInterfaceCore()->ReleaseResource(ctx->graphic_2d); |
| 35 ctx->graphic_2d = 0; | 35 ctx->graphic_2d = 0; |
| 36 } | 36 } |
| 37 if (ctx->image) { | 37 if (ctx->image) { |
| 38 PSInterfaceCore()->ReleaseResource(ctx->image); | 38 PSInterfaceCore()->ReleaseResource(ctx->image); |
| 39 ctx->image = 0; | 39 ctx->image = 0; |
| 40 } | 40 } |
| 41 free(ctx); | 41 free(ctx); |
| 42 } | 42 } |
| 43 | 43 |
| 44 PP_ImageDataFormat PSContext2DGetNativeImageDataFormat() { |
| 45 return PSInterfaceImageData()->GetNativeImageDataFormat(); |
| 46 } |
| 47 |
| 44 // Update the 2D context if the message is appropriate, returning non-zero | 48 // Update the 2D context if the message is appropriate, returning non-zero |
| 45 // if the event was consumed. | 49 // if the event was consumed. |
| 46 int PSContext2DHandleEvent(PSContext2D_t* ctx, PSEvent* event) { | 50 int PSContext2DHandleEvent(PSContext2D_t* ctx, PSEvent* event) { |
| 47 switch(event->type) { | 51 switch(event->type) { |
| 48 case PSE_INSTANCE_DIDCHANGEVIEW: { | 52 case PSE_INSTANCE_DIDCHANGEVIEW: { |
| 49 struct PP_Rect rect; | 53 struct PP_Rect rect; |
| 50 | 54 |
| 51 PSInterfaceView()->GetRect(event->as_resource, &rect); | 55 PSInterfaceView()->GetRect(event->as_resource, &rect); |
| 52 PSInterfaceCore()->ReleaseResource(ctx->graphic_2d); | 56 PSInterfaceCore()->ReleaseResource(ctx->graphic_2d); |
| 53 ctx->bound = 0; | 57 ctx->bound = 0; |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 PSInterfaceCore()->ReleaseResource(ctx->image); | 129 PSInterfaceCore()->ReleaseResource(ctx->image); |
| 126 | 130 |
| 127 ctx->image = 0; | 131 ctx->image = 0; |
| 128 ctx->stride = 0; | 132 ctx->stride = 0; |
| 129 ctx->data = NULL; | 133 ctx->data = NULL; |
| 130 return 1; | 134 return 1; |
| 131 } | 135 } |
| 132 return 0; | 136 return 0; |
| 133 } | 137 } |
| 134 | 138 |
| OLD | NEW |