Chromium Code Reviews| 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), |
| 18 bound_to_instance_(false), | |
| 17 last_resource_id_(0) { | 19 last_resource_id_(0) { |
| 18 SendCreate(RENDERER, PpapiHostMsg_Compositor_Create()); | 20 SendCreate(RENDERER, PpapiHostMsg_Compositor_Create()); |
| 19 } | 21 } |
| 20 | 22 |
| 21 CompositorResource::~CompositorResource() { | 23 CompositorResource::~CompositorResource() { |
| 22 ResetLayersInternal(); | 24 ResetLayersInternal(); |
| 23 } | 25 } |
| 24 | 26 |
| 25 thunk::PPB_Compositor_API* CompositorResource::AsPPB_Compositor_API() { | 27 thunk::PPB_Compositor_API* CompositorResource::AsPPB_Compositor_API() { |
| 26 return this; | 28 return this; |
| 27 } | 29 } |
| 28 | 30 |
| 29 void CompositorResource::OnReplyReceived( | 31 void CompositorResource::OnReplyReceived( |
| 30 const ResourceMessageReplyParams& params, | 32 const ResourceMessageReplyParams& params, |
| 31 const IPC::Message& msg) { | 33 const IPC::Message& msg) { |
| 32 PPAPI_BEGIN_MESSAGE_MAP(CompositorResource, msg) | 34 PPAPI_BEGIN_MESSAGE_MAP(CompositorResource, msg) |
| 33 PPAPI_DISPATCH_PLUGIN_RESOURCE_CALL( | 35 PPAPI_DISPATCH_PLUGIN_RESOURCE_CALL( |
| 34 PpapiPluginMsg_Compositor_ReleaseResource, | 36 PpapiPluginMsg_Compositor_ReleaseResource, |
| 35 OnPluginMsgReleaseResource) | 37 OnPluginMsgReleaseResource) |
| 36 PPAPI_DISPATCH_PLUGIN_RESOURCE_CALL_UNHANDLED( | 38 PPAPI_DISPATCH_PLUGIN_RESOURCE_CALL_UNHANDLED( |
| 37 PluginResource::OnReplyReceived(params, msg)) | 39 PluginResource::OnReplyReceived(params, msg)) |
| 38 PPAPI_END_MESSAGE_MAP() | 40 PPAPI_END_MESSAGE_MAP() |
| 39 } | 41 } |
| 40 | 42 |
| 41 PP_Resource CompositorResource::AddLayer() { | 43 PP_Resource CompositorResource::AddLayer() { |
| 44 if (!bound_to_instance_) | |
| 45 return 0; | |
| 46 | |
| 42 scoped_refptr<CompositorLayerResource> resource(new CompositorLayerResource( | 47 scoped_refptr<CompositorLayerResource> resource(new CompositorLayerResource( |
| 43 connection(), pp_instance(), this)); | 48 connection(), pp_instance(), this)); |
| 44 layers_.push_back(resource); | 49 layers_.push_back(resource); |
| 45 return resource->GetReference(); | 50 return resource->GetReference(); |
| 46 } | 51 } |
| 47 | 52 |
| 48 int32_t CompositorResource::CommitLayers( | 53 int32_t CompositorResource::CommitLayers( |
| 49 const scoped_refptr<ppapi::TrackedCallback>& callback) { | 54 const scoped_refptr<ppapi::TrackedCallback>& callback) { |
| 55 if (!bound_to_instance_) | |
| 56 return PP_ERROR_FAILED; | |
| 57 | |
| 50 if (IsInProgress()) | 58 if (IsInProgress()) |
| 51 return PP_ERROR_INPROGRESS; | 59 return PP_ERROR_INPROGRESS; |
| 52 | 60 |
| 53 std::vector<CompositorLayerData> layers; | 61 std::vector<CompositorLayerData> layers; |
| 54 layers.reserve(layers_.size()); | 62 layers.reserve(layers_.size()); |
| 55 | 63 |
| 56 for (LayerList::const_iterator it = layers_.begin(); | 64 for (LayerList::const_iterator it = layers_.begin(); |
| 57 it != layers_.end(); ++it) { | 65 it != layers_.end(); ++it) { |
| 58 if ((*it)->data().is_null()) | 66 if ((*it)->data().is_null()) |
| 59 return PP_ERROR_FAILED; | 67 return PP_ERROR_FAILED; |
| 60 layers.push_back((*it)->data()); | 68 layers.push_back((*it)->data()); |
| 61 } | 69 } |
| 62 | 70 |
| 63 commit_callback_ = callback; | 71 commit_callback_ = callback; |
| 64 Call<PpapiPluginMsg_Compositor_CommitLayersReply>( | 72 Call<PpapiPluginMsg_Compositor_CommitLayersReply>( |
| 65 RENDERER, | 73 RENDERER, |
| 66 PpapiHostMsg_Compositor_CommitLayers(layers, layer_reset_), | 74 PpapiHostMsg_Compositor_CommitLayers(layers, layer_reset_), |
| 67 base::Bind(&CompositorResource::OnPluginMsgCommitLayersReply, | 75 base::Bind(&CompositorResource::OnPluginMsgCommitLayersReply, |
| 68 base::Unretained(this)), | 76 base::Unretained(this)), |
| 69 callback); | 77 callback); |
| 70 | 78 |
| 71 return PP_OK_COMPLETIONPENDING; | 79 return PP_OK_COMPLETIONPENDING; |
| 72 } | 80 } |
| 73 | 81 |
| 74 int32_t CompositorResource::ResetLayers() { | 82 int32_t CompositorResource::ResetLayers() { |
| 83 if (!bound_to_instance_) | |
| 84 return PP_ERROR_FAILED; | |
| 85 | |
| 75 if (IsInProgress()) | 86 if (IsInProgress()) |
| 76 return PP_ERROR_INPROGRESS; | 87 return PP_ERROR_INPROGRESS; |
| 88 | |
| 77 ResetLayersInternal(); | 89 ResetLayersInternal(); |
| 78 return PP_OK; | 90 return PP_OK; |
| 79 } | 91 } |
| 80 | 92 |
| 93 void CompositorResource::BindToInstance(bool bound) { | |
| 94 ProxyLock::AssertAcquiredDebugOnly(); | |
| 95 | |
| 96 if (bound == bound_to_instance_) | |
| 97 return; | |
| 98 bound_to_instance_ = bound; | |
| 99 | |
| 100 // Reset layers when the compositor is un bound from the instance. | |
| 101 if (!bound_to_instance_) | |
| 102 ResetLayersInternal(); | |
| 103 } | |
| 104 | |
| 105 void CompositorResource::NotifyLastPluginRefWasDeleted() { | |
| 106 ProxyLock::AssertAcquiredDebugOnly(); | |
| 107 | |
| 108 PluginResource::NotifyLastPluginRefWasDeleted(); | |
| 109 if (bound_to_instance_) { | |
| 110 ppapi::thunk::EnterInstanceNoLock enter(pp_instance()); | |
| 111 DCHECK(enter.succeeded()); | |
| 112 enter.functions()->BindGraphics(pp_instance(), 0); | |
| 113 // BindToInstance(0) should be called by PPB_Instance_Proxy::BindGraphics(). | |
| 114 DCHECK(!bound_to_instance_); | |
| 115 } | |
|
raymes
2014/06/18 05:58:44
Why do we need to do this?
Peng
2014/06/18 11:14:37
Because the plugin instance holds a scoped_refptr
raymes
2014/06/19 00:39:13
I think this would be much simpler if we didn't ma
Peng
2014/06/19 17:35:11
In the recent patchset, we do not manage the bind
| |
| 116 } | |
| 117 | |
| 81 void CompositorResource::OnPluginMsgCommitLayersReply( | 118 void CompositorResource::OnPluginMsgCommitLayersReply( |
| 82 const ResourceMessageReplyParams& params) { | 119 const ResourceMessageReplyParams& params) { |
| 83 if (!TrackedCallback::IsPending(commit_callback_)) | 120 if (!TrackedCallback::IsPending(commit_callback_)) |
| 84 return; | 121 return; |
| 85 | 122 |
| 86 // On success, we put layers' release_callbacks into a map, | 123 // On success, we put layers' release_callbacks into a map, |
| 87 // otherwise we will do nothing. So plugin may change layers and | 124 // otherwise we will do nothing. So plugin may change layers and |
| 88 // call CommitLayers() again. | 125 // call CommitLayers() again. |
| 89 if (params.result() == PP_OK) { | 126 if (params.result() == PP_OK) { |
| 90 layer_reset_ = false; | 127 layer_reset_ = false; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 126 } | 163 } |
| 127 (*it)->Invalidate(); | 164 (*it)->Invalidate(); |
| 128 } | 165 } |
| 129 | 166 |
| 130 layers_.clear(); | 167 layers_.clear(); |
| 131 layer_reset_ = true; | 168 layer_reset_ = true; |
| 132 } | 169 } |
| 133 | 170 |
| 134 } // namespace proxy | 171 } // namespace proxy |
| 135 } // namespace ppapi | 172 } // namespace ppapi |
| OLD | NEW |