1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CONTENT_RENDERER_PEPPER_PEPPER_GRAPHICS_2D_HOST_H_
6 #define CONTENT_RENDERER_PEPPER_PEPPER_GRAPHICS_2D_HOST_H_
8 #include "base/compiler_specific.h"
9 #include "base/memory/weak_ptr.h"
10 #include "content/common/content_export.h"
11 #include "ppapi/c/ppb_graphics_2d.h"
12 #include "ppapi/host/host_message_context.h"
13 #include "ppapi/host/resource_host.h"
14 #include "webkit/plugins/ppapi/plugin_delegate.h"
15 #include "webkit/plugins/ppapi/ppb_graphics_2d_impl.h"
19 class PPB_ImageData_Impl
;
26 class RendererPpapiHost
;
28 class CONTENT_EXPORT PepperGraphics2DHost
29 : public ppapi::host::ResourceHost
,
30 public webkit::ppapi::PluginDelegate::PlatformGraphics2D
,
31 public base::SupportsWeakPtr
<PepperGraphics2DHost
> {
33 static PepperGraphics2DHost
* Create(RendererPpapiHost
* host
,
37 PP_Bool is_always_opaque
);
39 virtual ~PepperGraphics2DHost();
41 virtual int32_t OnResourceMessageReceived(
42 const IPC::Message
& msg
,
43 ppapi::host::HostMessageContext
* context
) OVERRIDE
;
45 // PlatformGraphics2D overrides.
46 virtual bool ReadImageData(PP_Resource image
,
47 const PP_Point
* top_left
) OVERRIDE
;
48 virtual bool BindToInstance(
49 webkit::ppapi::PluginInstance
* new_instance
) OVERRIDE
;
50 virtual void Paint(WebKit::WebCanvas
* canvas
,
51 const gfx::Rect
& plugin_rect
,
52 const gfx::Rect
& paint_rect
) OVERRIDE
;
53 virtual void ViewWillInitiatePaint() OVERRIDE
;
54 virtual void ViewInitiatedPaint() OVERRIDE
;
55 virtual void ViewFlushedPaint() OVERRIDE
;
56 virtual void SetScale(float scale
) OVERRIDE
;
57 virtual float GetScale() const OVERRIDE
;
58 virtual bool IsAlwaysOpaque() const OVERRIDE
;
59 virtual webkit::ppapi::PPB_ImageData_Impl
* ImageData() OVERRIDE
;
60 virtual bool IsGraphics2DHost() const OVERRIDE
;
63 PepperGraphics2DHost(RendererPpapiHost
* host
,
65 PP_Resource resource
);
67 int32_t OnHostMsgPaintImageData(ppapi::host::HostMessageContext
* context
,
68 const ppapi::HostResource
& image_data
,
69 const PP_Point
& top_left
,
70 bool src_rect_specified
,
71 const PP_Rect
& src_rect
);
72 int32_t OnHostMsgScroll(ppapi::host::HostMessageContext
* context
,
75 const PP_Point
& amount
);
76 int32_t OnHostMsgReplaceContents(ppapi::host::HostMessageContext
* context
,
77 const ppapi::HostResource
& image_data
);
78 int32_t OnHostMsgFlush(ppapi::host::HostMessageContext
* context
);
79 int32_t OnHostMsgSetScale(ppapi::host::HostMessageContext
* context
,
81 int32_t OnHostMsgReadImageData(ppapi::host::HostMessageContext
* context
,
83 const PP_Point
& top_left
);
85 static void SendFlushACKToPlugin(void* data
, int32_t pp_error
);
87 // TODO: merge this delegation into this host class.
88 scoped_refptr
<webkit::ppapi::PPB_Graphics2D_Impl
> graphics_2d_
;
90 ppapi::host::ReplyMessageContext flush_reply_context_
;
92 bool is_running_in_process_
;
94 DISALLOW_COPY_AND_ASSIGN(PepperGraphics2DHost
);
97 } // namespace content
99 #endif // CONTENT_RENDERER_PEPPER_PEPPER_GRAPHICS_2D_HOST_H_