OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef PPAPI_PROXY_COMPOSITOR_RESOURCE_H_ | 5 #ifndef PPAPI_PROXY_COMPOSITOR_RESOURCE_H_ |
6 #define PPAPI_PROXY_COMPOSITOR_RESOURCE_H_ | 6 #define PPAPI_PROXY_COMPOSITOR_RESOURCE_H_ |
7 | 7 |
| 8 #include <map> |
| 9 |
| 10 #include "base/callback.h" |
| 11 #include "base/memory/scoped_vector.h" |
| 12 #include "base/memory/weak_ptr.h" |
| 13 #include "ppapi/c/ppb_compositor_layer.h" |
8 #include "ppapi/proxy/plugin_resource.h" | 14 #include "ppapi/proxy/plugin_resource.h" |
9 #include "ppapi/proxy/ppapi_proxy_export.h" | 15 #include "ppapi/proxy/ppapi_proxy_export.h" |
| 16 #include "ppapi/shared_impl/compositor_layer_data.h" |
| 17 #include "ppapi/shared_impl/scoped_pp_resource.h" |
10 #include "ppapi/thunk/ppb_compositor_api.h" | 18 #include "ppapi/thunk/ppb_compositor_api.h" |
11 | 19 |
12 namespace ppapi { | 20 namespace ppapi { |
13 namespace proxy { | 21 namespace proxy { |
14 | 22 |
15 class PPAPI_PROXY_EXPORT CompositorResource | 23 class PPAPI_PROXY_EXPORT CompositorResource |
16 : public PluginResource, | 24 : public PluginResource, |
17 public thunk::PPB_Compositor_API { | 25 public thunk::PPB_Compositor_API { |
18 public: | 26 public: |
| 27 // Release callback for texture or image. |
| 28 typedef base::Callback<void(uint32_t, bool)> ReleaseCallback; |
| 29 |
| 30 class LayerImpl : public base::SupportsWeakPtr<LayerImpl> { |
| 31 public: |
| 32 LayerImpl(CompositorResource* compositor); |
| 33 ~LayerImpl(); |
| 34 |
| 35 // Methods for CompositorLayerResource: |
| 36 int32_t SetColor(uint8_t red, |
| 37 uint8_t green, |
| 38 uint8_t blue, |
| 39 uint8_t alpha, |
| 40 const struct PP_Size* size); |
| 41 int32_t SetTexture(PP_Resource context, |
| 42 uint32_t texture, |
| 43 const struct PP_Size* size, |
| 44 const scoped_refptr<TrackedCallback>& release_callback); |
| 45 int32_t SetImage(PP_Resource image_data, |
| 46 const struct PP_Size* size, |
| 47 const scoped_refptr<TrackedCallback>& release_callback); |
| 48 int32_t SetClipRect(const struct PP_Rect* rect); |
| 49 int32_t SetTransform(const float matrix[16]); |
| 50 int32_t SetOpacity(uint8_t opacity); |
| 51 int32_t SetBlendMode(PP_BlendMode mode); |
| 52 int32_t SetSourceRect(const struct PP_FloatRect* rect); |
| 53 int32_t SetPremultipliedAlpha(PP_Bool premult); |
| 54 |
| 55 const CompositorLayerData& data() const { return data_; } |
| 56 const ReleaseCallback& release_callback() const { |
| 57 return release_callback_; |
| 58 } |
| 59 void ResetReleaseCallback() { release_callback_.Reset(); } |
| 60 |
| 61 private: |
| 62 bool SetType(CompositorLayerData::Type type); |
| 63 |
| 64 void OnTextureReleased( |
| 65 const ScopedPPResource& context, |
| 66 uint32_t texture, |
| 67 const scoped_refptr<TrackedCallback>& release_callback, |
| 68 uint32_t sync_point, |
| 69 bool is_lost); |
| 70 |
| 71 void OnImageReleased( |
| 72 const ScopedPPResource& image, |
| 73 const scoped_refptr<TrackedCallback>& release_callback, |
| 74 uint32_t sync_point, |
| 75 bool is_lost); |
| 76 |
| 77 CompositorResource* compositor_; |
| 78 |
| 79 // Release callback for texture or image layer. |
| 80 ReleaseCallback release_callback_; |
| 81 |
| 82 PP_FloatSize source_size_; |
| 83 |
| 84 CompositorLayerData data_; |
| 85 |
| 86 DISALLOW_COPY_AND_ASSIGN(LayerImpl); |
| 87 }; |
| 88 |
19 CompositorResource(Connection connection, | 89 CompositorResource(Connection connection, |
20 PP_Instance instance); | 90 PP_Instance instance); |
21 | 91 |
22 private: | 92 private: |
23 virtual ~CompositorResource(); | 93 virtual ~CompositorResource(); |
24 | 94 |
| 95 bool IsInProgress() const { |
| 96 return TrackedCallback::IsPending(commit_callback_); |
| 97 } |
| 98 |
| 99 int32_t GenerateResourceId() { |
| 100 return ++last_resource_id_; |
| 101 } |
| 102 |
25 // Resource overrides: | 103 // Resource overrides: |
26 virtual thunk::PPB_Compositor_API* AsPPB_Compositor_API() OVERRIDE; | 104 virtual thunk::PPB_Compositor_API* AsPPB_Compositor_API() OVERRIDE; |
27 | 105 |
| 106 // PluginResource overrides: |
| 107 virtual void OnReplyReceived(const ResourceMessageReplyParams& params, |
| 108 const IPC::Message& msg) OVERRIDE; |
| 109 |
28 // thunk::PPB_Compositor_API overrides: | 110 // thunk::PPB_Compositor_API overrides: |
29 virtual PP_Resource AddLayer() OVERRIDE; | 111 virtual PP_Resource AddLayer() OVERRIDE; |
30 virtual int32_t CommitLayers( | 112 virtual int32_t CommitLayers( |
31 const scoped_refptr<ppapi::TrackedCallback>& callback) OVERRIDE; | 113 const scoped_refptr<TrackedCallback>& callback) OVERRIDE; |
32 virtual int32_t ResetLayers() OVERRIDE; | 114 virtual int32_t ResetLayers() OVERRIDE; |
33 | 115 |
| 116 // IPC msg handlers: |
| 117 void OnPluginMsgCommitLayersReply(const ResourceMessageReplyParams& params); |
| 118 void OnPluginMsgReleaseResource( |
| 119 const ResourceMessageReplyParams& params, |
| 120 int32_t id, |
| 121 uint32_t sync_point, |
| 122 bool is_lost); |
| 123 |
| 124 scoped_refptr<TrackedCallback> commit_callback_; |
| 125 |
| 126 bool layer_reset_; |
| 127 |
| 128 ScopedVector<LayerImpl> layers_; |
| 129 |
| 130 int32_t last_resource_id_; |
| 131 typedef std::map<int32_t, ReleaseCallback > ReleaseCallbackMap; |
| 132 ReleaseCallbackMap release_callback_map_; |
| 133 |
34 DISALLOW_COPY_AND_ASSIGN(CompositorResource); | 134 DISALLOW_COPY_AND_ASSIGN(CompositorResource); |
35 }; | 135 }; |
36 | 136 |
37 } // namespace proxy | 137 } // namespace proxy |
38 } // namespace ppapi | 138 } // namespace ppapi |
39 | 139 |
40 #endif // PPAPI_PROXY_COMPOSITOR_RESOURCE_H_ | 140 #endif // PPAPI_PROXY_COMPOSITOR_RESOURCE_H_ |
OLD | NEW |