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" | |
| 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 ResetLayers(); | |
| 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 switch ((*it)->data().type) { | |
| 59 case CompositorLayerData::TYPE_UNKNOWN: | |
| 60 return PP_ERROR_FAILED; | |
| 61 case CompositorLayerData::TYPE_COLOR: | |
| 62 case CompositorLayerData::TYPE_TEXTURE: | |
| 63 case CompositorLayerData::TYPE_IMAGE: | |
| 64 layers.push_back((*it)->data()); | |
| 65 continue; | |
| 66 default: | |
| 67 NOTREACHED(); | |
|
piman
2014/06/04 13:19:43
No default case, just omit it to get compiler warn
Peng
2014/06/05 00:50:38
Done.
| |
| 68 } | |
| 69 } | |
| 70 | |
| 71 commit_callback_ = callback; | |
| 72 Call<PpapiPluginMsg_Compositor_CommitLayersReply>( | |
| 73 RENDERER, | |
| 74 PpapiHostMsg_Compositor_CommitLayers(layers, layer_reset_), | |
| 75 base::Bind(&CompositorResource::OnPluginMsgCommitLayersReply, | |
| 76 base::Unretained(this)), | |
| 77 callback); | |
| 78 | |
| 79 return PP_OK_COMPLETIONPENDING; | |
| 29 } | 80 } |
| 30 | 81 |
| 31 int32_t CompositorResource::ResetLayers() { | 82 int32_t CompositorResource::ResetLayers() { |
| 32 return PP_ERROR_NOTSUPPORTED; | 83 if (IsInProgress()) |
| 84 return PP_ERROR_INPROGRESS; | |
| 85 | |
| 86 for (LayerList::iterator it = layers_.begin(); | |
| 87 it != layers_.end(); ++it) { | |
| 88 ReleaseCallback release_callback = (*it)->release_callback(); | |
| 89 if (!release_callback.is_null()) | |
| 90 release_callback.Run(0, false); | |
| 91 (*it)->Invalidate(); | |
|
raymes
2014/06/04 01:11:38
One problem here is that if IsInProgress() returns
Peng
2014/06/05 00:50:38
Good catch. Done
| |
| 92 } | |
| 93 | |
| 94 layers_.clear(); | |
| 95 layer_reset_ = true; | |
| 96 return PP_OK; | |
| 97 } | |
| 98 | |
| 99 void CompositorResource::OnPluginMsgCommitLayersReply( | |
| 100 const ResourceMessageReplyParams& params) { | |
| 101 if (!TrackedCallback::IsPending(commit_callback_)) | |
| 102 return; | |
| 103 | |
| 104 // On success, we put layers' release_callbacks into a map, | |
| 105 // otherwise we will do nothing. So plugin may change layers and | |
| 106 // call CommitLayers() again. | |
| 107 if (params.result() == PP_OK) { | |
| 108 layer_reset_ = false; | |
| 109 for (LayerList::iterator it = layers_.begin(); | |
| 110 it != layers_.end(); ++it) { | |
| 111 switch ((*it)->data().type) { | |
| 112 case CompositorLayerData::TYPE_TEXTURE: | |
| 113 case CompositorLayerData::TYPE_IMAGE: { | |
| 114 ReleaseCallback release_callback = (*it)->release_callback(); | |
| 115 (*it)->ResetReleaseCallback(); | |
| 116 if (!release_callback.is_null()) { | |
| 117 release_callback_map_.insert(ReleaseCallbackMap::value_type( | |
| 118 (*it)->data().resource_id, release_callback)); | |
|
raymes
2014/06/04 01:11:38
Note that the ReleaseCallback holds a reference to
Peng
2014/06/05 00:50:38
Actually, the ReleaseCallback does not need hold a
| |
| 119 } | |
| 120 break; | |
| 121 } | |
| 122 default: | |
| 123 break; | |
| 124 } | |
| 125 } | |
| 126 } | |
| 127 | |
| 128 scoped_refptr<TrackedCallback> callback; | |
| 129 callback.swap(commit_callback_); | |
| 130 callback->Run(params.result()); | |
| 131 } | |
| 132 | |
| 133 void CompositorResource::OnPluginMsgReleaseResource( | |
| 134 const ResourceMessageReplyParams& params, | |
| 135 int32_t id, | |
| 136 uint32_t sync_point, | |
| 137 bool is_lost) { | |
| 138 ReleaseCallbackMap::iterator it = release_callback_map_.find(id); | |
| 139 DCHECK(it != release_callback_map_.end()) << | |
| 140 "Can not found release_callback_ by id(" << id << ")!"; | |
| 141 it->second.Run(sync_point, is_lost); | |
| 142 release_callback_map_.erase(it); | |
| 33 } | 143 } |
| 34 | 144 |
| 35 } // namespace proxy | 145 } // namespace proxy |
| 36 } // namespace ppapi | 146 } // namespace ppapi |
| OLD | NEW |