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 #include "ppapi/proxy/compositor_resource.h" | 5 #include "ppapi/proxy/compositor_resource.h" |
6 | 6 |
7 #include "base/logging.h" | |
8 #include "ppapi/proxy/ppapi_messages.h" | |
9 | |
7 namespace ppapi { | 10 namespace ppapi { |
8 namespace proxy { | 11 namespace proxy { |
9 | 12 |
10 CompositorResource::CompositorResource(Connection connection, | 13 CompositorResource::CompositorResource(Connection connection, |
11 PP_Instance instance) | 14 PP_Instance instance) |
12 : PluginResource(connection, instance) { | 15 : PluginResource(connection, instance), |
16 layer_reset_(true), | |
17 last_resource_id_(0) { | |
18 SendCreate(RENDERER, PpapiHostMsg_Compositor_Create()); | |
13 } | 19 } |
14 | 20 |
15 CompositorResource::~CompositorResource() { | 21 CompositorResource::~CompositorResource() { |
22 ResetLayersInternal(); | |
16 } | 23 } |
17 | 24 |
18 thunk::PPB_Compositor_API* CompositorResource::AsPPB_Compositor_API() { | 25 thunk::PPB_Compositor_API* CompositorResource::AsPPB_Compositor_API() { |
19 return this; | 26 return this; |
20 } | 27 } |
21 | 28 |
29 void CompositorResource::OnReplyReceived( | |
30 const ResourceMessageReplyParams& params, | |
31 const IPC::Message& msg) { | |
32 PPAPI_BEGIN_MESSAGE_MAP(CompositorResource, msg) | |
33 PPAPI_DISPATCH_PLUGIN_RESOURCE_CALL( | |
34 PpapiPluginMsg_Compositor_ReleaseResource, | |
35 OnPluginMsgReleaseResource) | |
36 PPAPI_DISPATCH_PLUGIN_RESOURCE_CALL_UNHANDLED( | |
37 PluginResource::OnReplyReceived(params, msg)) | |
38 PPAPI_END_MESSAGE_MAP() | |
39 } | |
40 | |
22 PP_Resource CompositorResource::AddLayer() { | 41 PP_Resource CompositorResource::AddLayer() { |
23 return 0; | 42 scoped_refptr<CompositorLayerResource> resource(new CompositorLayerResource( |
43 connection(), pp_instance(), this)); | |
44 layers_.push_back(resource); | |
45 return resource->GetReference(); | |
24 } | 46 } |
25 | 47 |
26 int32_t CompositorResource::CommitLayers( | 48 int32_t CompositorResource::CommitLayers( |
27 const scoped_refptr<ppapi::TrackedCallback>& callback) { | 49 const scoped_refptr<ppapi::TrackedCallback>& callback) { |
28 return PP_ERROR_NOTSUPPORTED; | 50 if (IsInProgress()) |
51 return PP_ERROR_INPROGRESS; | |
52 | |
53 std::vector<CompositorLayerData> layers; | |
54 layers.reserve(layers_.size()); | |
55 | |
56 for (LayerList::const_iterator it = layers_.begin(); | |
57 it != layers_.end(); ++it) { | |
58 if ((*it)->data().is_null()) | |
59 return PP_ERROR_FAILED; | |
60 layers.push_back((*it)->data()); | |
61 } | |
62 | |
63 commit_callback_ = callback; | |
64 Call<PpapiPluginMsg_Compositor_CommitLayersReply>( | |
65 RENDERER, | |
66 PpapiHostMsg_Compositor_CommitLayers(layers, layer_reset_), | |
67 base::Bind(&CompositorResource::OnPluginMsgCommitLayersReply, | |
68 base::Unretained(this)), | |
69 callback); | |
70 | |
71 return PP_OK_COMPLETIONPENDING; | |
29 } | 72 } |
30 | 73 |
31 int32_t CompositorResource::ResetLayers() { | 74 int32_t CompositorResource::ResetLayers() { |
32 return PP_ERROR_NOTSUPPORTED; | 75 if (IsInProgress()) |
76 return PP_ERROR_INPROGRESS; | |
77 ResetLayersInternal(); | |
78 return PP_OK; | |
79 } | |
80 | |
81 void CompositorResource::OnPluginMsgCommitLayersReply( | |
82 const ResourceMessageReplyParams& params) { | |
83 if (!TrackedCallback::IsPending(commit_callback_)) | |
84 return; | |
85 | |
86 // On success, we put layers' release_callbacks into a map, | |
87 // otherwise we will do nothing. So plugin may change layers and | |
88 // call CommitLayers() again. | |
89 if (params.result() == PP_OK) { | |
90 layer_reset_ = false; | |
91 for (LayerList::iterator it = layers_.begin(); | |
92 it != layers_.end(); ++it) { | |
93 ReleaseCallback release_callback = (*it)->release_callback(); | |
94 if (!release_callback.is_null()) { | |
95 release_callback_map_.insert(ReleaseCallbackMap::value_type( | |
96 (*it)->data().common.resource_id, release_callback)); | |
97 (*it)->ResetReleaseCallback(); | |
98 } | |
99 } | |
100 } | |
101 | |
102 scoped_refptr<TrackedCallback> callback; | |
103 callback.swap(commit_callback_); | |
104 callback->Run(params.result()); | |
105 } | |
106 | |
107 void CompositorResource::OnPluginMsgReleaseResource( | |
108 const ResourceMessageReplyParams& params, | |
109 int32_t id, | |
110 uint32_t sync_point, | |
111 bool is_lost) { | |
112 ReleaseCallbackMap::iterator it = release_callback_map_.find(id); | |
113 DCHECK(it != release_callback_map_.end()) << | |
nasko
2014/06/13 17:23:01
Why is this just a DCHECK? If there is no callback
piman
2014/06/13 17:30:05
Preemptive comment: no CHECK please. If this needs
nasko
2014/06/13 17:38:49
Sure, I don't have strong preference on which way.
Peng
2014/06/13 18:04:05
I think this DCHECK() should be true always (unles
| |
114 "Can not found release_callback_ by id(" << id << ")!"; | |
115 it->second.Run(sync_point, is_lost); | |
116 release_callback_map_.erase(it); | |
117 } | |
118 | |
119 void CompositorResource::ResetLayersInternal() { | |
120 for (LayerList::iterator it = layers_.begin(); | |
121 it != layers_.end(); ++it) { | |
122 ReleaseCallback release_callback = (*it)->release_callback(); | |
123 if (!release_callback.is_null()) { | |
124 release_callback.Run(0, false); | |
125 (*it)->ResetReleaseCallback(); | |
126 } | |
127 (*it)->Invalidate(); | |
128 } | |
129 | |
130 layers_.clear(); | |
131 layer_reset_ = true; | |
33 } | 132 } |
34 | 133 |
35 } // namespace proxy | 134 } // namespace proxy |
36 } // namespace ppapi | 135 } // namespace ppapi |
OLD | NEW |