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