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" | 7 #include "base/logging.h" |
8 #include "ppapi/proxy/ppapi_messages.h" | 8 #include "ppapi/proxy/ppapi_messages.h" |
9 #include "ppapi/thunk/enter.h" | |
10 | 9 |
11 namespace ppapi { | 10 namespace ppapi { |
12 namespace proxy { | 11 namespace proxy { |
13 | 12 |
14 CompositorResource::CompositorResource(Connection connection, | 13 CompositorResource::CompositorResource(Connection connection, |
15 PP_Instance instance) | 14 PP_Instance instance) |
16 : PluginResource(connection, instance), | 15 : PluginResource(connection, instance), |
17 layer_reset_(true), | 16 layer_reset_(true), |
18 last_resource_id_(0) { | 17 last_resource_id_(0) { |
19 SendCreate(RENDERER, PpapiHostMsg_Compositor_Create()); | 18 SendCreate(RENDERER, PpapiHostMsg_Compositor_Create()); |
20 } | 19 } |
21 | 20 |
22 bool CompositorResource::IsInProgress() const { | |
23 ProxyLock::AssertAcquiredDebugOnly(); | |
24 return TrackedCallback::IsPending(commit_callback_); | |
25 } | |
26 | |
27 int32_t CompositorResource::GenerateResourceId() const { | |
28 ProxyLock::AssertAcquiredDebugOnly(); | |
29 return ++last_resource_id_; | |
30 } | |
31 | |
32 CompositorResource::~CompositorResource() { | 21 CompositorResource::~CompositorResource() { |
33 ResetLayersInternal(true); | 22 ResetLayersInternal(); |
34 | |
35 // Abort all release callbacks. | |
36 for (ReleaseCallbackMap::iterator it = release_callback_map_.begin(); | |
37 it != release_callback_map_.end(); ++it) { | |
38 if (!it->second.is_null()) | |
39 it->second.Run(PP_ERROR_ABORTED, 0, false); | |
40 } | |
41 } | 23 } |
42 | 24 |
43 thunk::PPB_Compositor_API* CompositorResource::AsPPB_Compositor_API() { | 25 thunk::PPB_Compositor_API* CompositorResource::AsPPB_Compositor_API() { |
44 return this; | 26 return this; |
45 } | 27 } |
46 | 28 |
47 void CompositorResource::OnReplyReceived( | 29 void CompositorResource::OnReplyReceived( |
48 const ResourceMessageReplyParams& params, | 30 const ResourceMessageReplyParams& params, |
49 const IPC::Message& msg) { | 31 const IPC::Message& msg) { |
50 PPAPI_BEGIN_MESSAGE_MAP(CompositorResource, msg) | 32 PPAPI_BEGIN_MESSAGE_MAP(CompositorResource, msg) |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 base::Bind(&CompositorResource::OnPluginMsgCommitLayersReply, | 67 base::Bind(&CompositorResource::OnPluginMsgCommitLayersReply, |
86 base::Unretained(this)), | 68 base::Unretained(this)), |
87 callback); | 69 callback); |
88 | 70 |
89 return PP_OK_COMPLETIONPENDING; | 71 return PP_OK_COMPLETIONPENDING; |
90 } | 72 } |
91 | 73 |
92 int32_t CompositorResource::ResetLayers() { | 74 int32_t CompositorResource::ResetLayers() { |
93 if (IsInProgress()) | 75 if (IsInProgress()) |
94 return PP_ERROR_INPROGRESS; | 76 return PP_ERROR_INPROGRESS; |
95 | 77 ResetLayersInternal(); |
96 ResetLayersInternal(false); | |
97 return PP_OK; | 78 return PP_OK; |
98 } | 79 } |
99 | 80 |
100 void CompositorResource::OnPluginMsgCommitLayersReply( | 81 void CompositorResource::OnPluginMsgCommitLayersReply( |
101 const ResourceMessageReplyParams& params) { | 82 const ResourceMessageReplyParams& params) { |
102 if (!TrackedCallback::IsPending(commit_callback_)) | 83 if (!TrackedCallback::IsPending(commit_callback_)) |
103 return; | 84 return; |
104 | 85 |
105 // On success, we put layers' release_callbacks into a map, | 86 // On success, we put layers' release_callbacks into a map, |
106 // otherwise we will do nothing. So plugin may change layers and | 87 // otherwise we will do nothing. So plugin may change layers and |
(...skipping 17 matching lines...) Expand all Loading... |
124 } | 105 } |
125 | 106 |
126 void CompositorResource::OnPluginMsgReleaseResource( | 107 void CompositorResource::OnPluginMsgReleaseResource( |
127 const ResourceMessageReplyParams& params, | 108 const ResourceMessageReplyParams& params, |
128 int32_t id, | 109 int32_t id, |
129 uint32_t sync_point, | 110 uint32_t sync_point, |
130 bool is_lost) { | 111 bool is_lost) { |
131 ReleaseCallbackMap::iterator it = release_callback_map_.find(id); | 112 ReleaseCallbackMap::iterator it = release_callback_map_.find(id); |
132 DCHECK(it != release_callback_map_.end()) << | 113 DCHECK(it != release_callback_map_.end()) << |
133 "Can not found release_callback_ by id(" << id << ")!"; | 114 "Can not found release_callback_ by id(" << id << ")!"; |
134 it->second.Run(PP_OK, sync_point, is_lost); | 115 it->second.Run(sync_point, is_lost); |
135 release_callback_map_.erase(it); | 116 release_callback_map_.erase(it); |
136 } | 117 } |
137 | 118 |
138 void CompositorResource::ResetLayersInternal(bool is_aborted) { | 119 void CompositorResource::ResetLayersInternal() { |
139 for (LayerList::iterator it = layers_.begin(); | 120 for (LayerList::iterator it = layers_.begin(); |
140 it != layers_.end(); ++it) { | 121 it != layers_.end(); ++it) { |
141 ReleaseCallback release_callback = (*it)->release_callback(); | 122 ReleaseCallback release_callback = (*it)->release_callback(); |
142 if (!release_callback.is_null()) { | 123 if (!release_callback.is_null()) { |
143 release_callback.Run(is_aborted ? PP_ERROR_ABORTED : PP_OK, 0, false); | 124 release_callback.Run(0, false); |
144 (*it)->ResetReleaseCallback(); | 125 (*it)->ResetReleaseCallback(); |
145 } | 126 } |
146 (*it)->Invalidate(); | 127 (*it)->Invalidate(); |
147 } | 128 } |
148 | 129 |
149 layers_.clear(); | 130 layers_.clear(); |
150 layer_reset_ = true; | 131 layer_reset_ = true; |
151 } | 132 } |
152 | 133 |
153 } // namespace proxy | 134 } // namespace proxy |
154 } // namespace ppapi | 135 } // namespace ppapi |
OLD | NEW |