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.
4 
5 #ifndef PPAPI_PROXY_GRAPHICS_2D_RESOURCE_H_
6 #define PPAPI_PROXY_GRAPHICS_2D_RESOURCE_H_
7 
8 #include <stdint.h>
9 
10 #include "base/compiler_specific.h"
11 #include "base/macros.h"
12 #include "ppapi/proxy/plugin_resource.h"
13 #include "ppapi/proxy/ppapi_proxy_export.h"
14 #include "ppapi/thunk/ppb_graphics_2d_api.h"
15 
16 namespace ppapi {
17 
18 class TrackedCallback;
19 
20 namespace proxy {
21 
22 class PPAPI_PROXY_EXPORT Graphics2DResource : public PluginResource,
23                                               public thunk::PPB_Graphics2D_API {
24  public:
25   Graphics2DResource(Connection connection,
26                      PP_Instance instance,
27                      const PP_Size& size,
28                      PP_Bool is_always_opaque);
29 
30   ~Graphics2DResource() override;
31 
32   // Resource overrides.
33   thunk::PPB_Graphics2D_API* AsPPB_Graphics2D_API() override;
34 
35   // PPB_Graphics2D_API overrides.
36   PP_Bool Describe(PP_Size* size, PP_Bool* is_always_opaque) override;
37   void PaintImageData(PP_Resource image_data,
38                       const PP_Point* top_left,
39                       const PP_Rect* src_rect) override;
40   void Scroll(const PP_Rect* clip_rect, const PP_Point* amount) override;
41   void ReplaceContents(PP_Resource image_data) override;
42   PP_Bool SetScale(float scale) override;
43   float GetScale() override;
44   PP_Bool SetLayerTransform(float scale,
45                             const PP_Point* origin,
46                             const PP_Point* translate) override;
47   int32_t Flush(scoped_refptr<TrackedCallback> callback) override;
48   bool ReadImageData(PP_Resource image, const PP_Point* top_left) override;
49 
50  private:
51   void OnPluginMsgFlushACK(const ResourceMessageReplyParams& params);
52 
53   const PP_Size size_;
54   const PP_Bool is_always_opaque_;
55   float scale_;
56 
57   scoped_refptr<TrackedCallback> current_flush_callback_;
58 
59   DISALLOW_COPY_AND_ASSIGN(Graphics2DResource);
60 };
61 
62 }  // namespace proxy
63 }  // namespace ppapi
64 
65 #endif  // PPAPI_PROXY_GRAPHICS_2D_RESOURCE_H_
66