| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "services/gfx/compositor/graph/scene_def.h" | 5 #include "services/gfx/compositor/graph/scene_def.h" |
| 6 | 6 |
| 7 #include <ostream> | 7 #include <ostream> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
| 12 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
| 13 #include "mojo/services/gfx/composition/cpp/formatting.h" | 13 #include "mojo/services/gfx/composition/cpp/formatting.h" |
| 14 #include "mojo/skia/type_converters.h" | 14 #include "mojo/skia/type_converters.h" |
| 15 #include "services/gfx/compositor/graph/scene_content.h" | 15 #include "services/gfx/compositor/graph/scene_content.h" |
| 16 #include "services/gfx/compositor/graph/transform_pair.h" | 16 #include "services/gfx/compositor/graph/transform_pair.h" |
| 17 #include "services/gfx/compositor/graph/universe.h" |
| 17 #include "services/gfx/compositor/render/render_image.h" | 18 #include "services/gfx/compositor/render/render_image.h" |
| 18 | 19 |
| 19 namespace compositor { | 20 namespace compositor { |
| 20 | 21 |
| 21 namespace { | 22 namespace { |
| 22 // TODO(jeffbrown): Determine and document a more appropriate size limit | 23 // TODO(jeffbrown): Determine and document a more appropriate size limit |
| 23 // for transferred images as part of the image pipe abstraction instead. | 24 // for transferred images as part of the image pipe abstraction instead. |
| 24 const int32_t kMaxTextureWidth = 65536; | 25 const int32_t kMaxTextureWidth = 65536; |
| 25 const int32_t kMaxTextureHeight = 65536; | 26 const int32_t kMaxTextureHeight = 65536; |
| 26 | 27 |
| 27 void ReleaseMailboxTexture( | 28 void ReleaseMailboxTexture( |
| 28 mojo::gfx::composition::MailboxTextureCallbackPtr callback) { | 29 mojo::gfx::composition::MailboxTextureCallbackPtr callback) { |
| 29 if (callback) | 30 if (callback) |
| 30 callback->OnMailboxTextureReleased(); | 31 callback->OnMailboxTextureReleased(); |
| 31 } | 32 } |
| 32 } // namespace | 33 } // namespace |
| 33 | 34 |
| 34 SceneDef::SceneDef(const SceneLabel& label) | 35 SceneDef::SceneDef(const SceneLabel& label) : label_(label) {} |
| 35 : label_(label), weak_factory_(this) {} | |
| 36 | 36 |
| 37 SceneDef::~SceneDef() {} | 37 SceneDef::~SceneDef() {} |
| 38 | 38 |
| 39 void SceneDef::EnqueueUpdate(mojo::gfx::composition::SceneUpdatePtr update) { | 39 void SceneDef::EnqueueUpdate(mojo::gfx::composition::SceneUpdatePtr update) { |
| 40 DCHECK(update); | 40 DCHECK(update); |
| 41 pending_updates_.push_back(update.Pass()); | 41 pending_updates_.push_back(update.Pass()); |
| 42 } | 42 } |
| 43 | 43 |
| 44 void SceneDef::EnqueuePublish( | 44 void SceneDef::EnqueuePublish( |
| 45 mojo::gfx::composition::SceneMetadataPtr metadata) { | 45 mojo::gfx::composition::SceneMetadataPtr metadata) { |
| 46 DCHECK(metadata); | 46 DCHECK(metadata); |
| 47 pending_publications_.emplace_back(new Publication(metadata.Pass())); | 47 pending_publications_.emplace_back(new Publication(metadata.Pass())); |
| 48 pending_updates_.swap(pending_publications_.back()->updates); | 48 pending_updates_.swap(pending_publications_.back()->updates); |
| 49 } | 49 } |
| 50 | 50 |
| 51 SceneDef::Disposition SceneDef::Present( | 51 SceneDef::Disposition SceneDef::Present( |
| 52 int64_t presentation_time, | 52 int64_t presentation_time, |
| 53 Universe* universe, |
| 53 const SceneResolver& resolver, | 54 const SceneResolver& resolver, |
| 54 const SceneUnavailableSender& unavailable_sender, | 55 const SceneUnavailableSender& unavailable_sender, |
| 55 std::ostream& err) { | 56 std::ostream& err) { |
| 56 // Walk backwards through the pending publications to find the index | 57 // Walk backwards through the pending publications to find the index |
| 57 // just beyond the last one which is due to be presented at or before the | 58 // just beyond the last one which is due to be presented at or before the |
| 58 // presentation time. | 59 // presentation time. |
| 59 size_t end = pending_publications_.size(); | 60 size_t end = pending_publications_.size(); |
| 60 for (;;) { | 61 for (;;) { |
| 61 if (!end) | 62 if (!end) |
| 62 return Disposition::kUnchanged; | 63 return Disposition::kUnchanged; |
| 63 if (pending_publications_[end - 1]->is_due(presentation_time)) | 64 if (pending_publications_[end - 1]->is_due(presentation_time)) |
| 64 break; // found last presentable publication | 65 break; // found last presentable publication |
| 65 end--; | 66 end--; |
| 66 } | 67 } |
| 67 | 68 |
| 69 // TODO(jeffbrown): Should we publish every individual update to the |
| 70 // universe or is it good enough to only capture the most recent |
| 71 // accumulated updates at presentation time as we do here? |
| 72 |
| 68 // Apply all updates sequentially up to this point. | 73 // Apply all updates sequentially up to this point. |
| 69 version_ = pending_publications_[end - 1]->metadata->version; | 74 uint32_t version = pending_publications_[end - 1]->metadata->version; |
| 70 for (size_t index = 0; index < end; ++index) { | 75 for (size_t index = 0; index < end; ++index) { |
| 71 for (auto& update : pending_publications_[index]->updates) { | 76 for (auto& update : pending_publications_[index]->updates) { |
| 72 if (!ApplyUpdate(update.Pass(), resolver, unavailable_sender, err)) | 77 if (!ApplyUpdate(update.Pass(), resolver, unavailable_sender, err)) |
| 73 return Disposition::kFailed; | 78 return Disposition::kFailed; |
| 74 } | 79 } |
| 75 } | 80 } |
| 76 | 81 |
| 77 // Dequeue the publications we processed. | 82 // Dequeue the publications we processed. |
| 78 pending_publications_.erase(pending_publications_.begin(), | 83 pending_publications_.erase(pending_publications_.begin(), |
| 79 pending_publications_.begin() + end); | 84 pending_publications_.begin() + end); |
| 80 | 85 |
| 81 // Rebuild the scene content, gathering all reachable nodes and resources | 86 // Rebuild the scene content, collecting all reachable nodes and resources |
| 82 // and verifying that everything is correctly linked. | 87 // and verifying that everything is correctly linked. |
| 83 SceneContentBuilder builder(this, version_, err, resources_.size(), | 88 Collector collector(this, version, presentation_time, err); |
| 84 nodes_.size()); | 89 scoped_refptr<const SceneContent> content = collector.Build(); |
| 85 content_ = builder.Build(); | 90 if (!content) |
| 86 return content_ ? Disposition::kSucceeded : Disposition::kFailed; | 91 return Disposition::kFailed; |
| 92 |
| 93 universe->PresentScene(content); |
| 94 return Disposition::kSucceeded; |
| 87 } | 95 } |
| 88 | 96 |
| 89 bool SceneDef::ApplyUpdate(mojo::gfx::composition::SceneUpdatePtr update, | 97 bool SceneDef::ApplyUpdate(mojo::gfx::composition::SceneUpdatePtr update, |
| 90 const SceneResolver& resolver, | 98 const SceneResolver& resolver, |
| 91 const SceneUnavailableSender& unavailable_sender, | 99 const SceneUnavailableSender& unavailable_sender, |
| 92 std::ostream& err) { | 100 std::ostream& err) { |
| 93 DCHECK(update); | 101 DCHECK(update); |
| 94 | 102 |
| 95 // TODO(jeffbrown): We may be able to reuse some content from previous | 103 // TODO(jeffbrown): We may be able to reuse some content from previous |
| 96 // versions even when the client removes and recreates resources or nodes. | 104 // versions even when the client removes and recreates resources or nodes. |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 if (!node) | 138 if (!node) |
| 131 return false; | 139 return false; |
| 132 nodes_[node_id] = std::move(node); | 140 nodes_[node_id] = std::move(node); |
| 133 } else { | 141 } else { |
| 134 nodes_.erase(node_id); | 142 nodes_.erase(node_id); |
| 135 } | 143 } |
| 136 } | 144 } |
| 137 return true; | 145 return true; |
| 138 } | 146 } |
| 139 | 147 |
| 140 bool SceneDef::UnlinkReferencedScene( | 148 void SceneDef::NotifySceneUnavailable( |
| 141 SceneDef* scene, | 149 const mojo::gfx::composition::SceneToken& scene_token, |
| 142 const SceneUnavailableSender& unavailable_sender) { | 150 const SceneUnavailableSender& unavailable_sender) { |
| 143 DCHECK(scene); | |
| 144 | |
| 145 bool changed = false; | |
| 146 for (auto& pair : resources_) { | 151 for (auto& pair : resources_) { |
| 147 if (pair.second->type() == Resource::Type::kScene) { | 152 if (pair.second->type() == Resource::Type::kScene) { |
| 148 auto scene_resource = | 153 auto scene_resource = |
| 149 static_cast<const SceneResource*>(pair.second.get()); | 154 static_cast<const SceneResource*>(pair.second.get()); |
| 150 if (scene_resource->referenced_scene().get() == scene) { | 155 if (scene_resource->scene_token().value == scene_token.value) |
| 151 changed = true; | |
| 152 pair.second = scene_resource->Unlink(); | |
| 153 unavailable_sender.Run(pair.first); | 156 unavailable_sender.Run(pair.first); |
| 154 } | |
| 155 } | 157 } |
| 156 } | 158 } |
| 157 return changed; | |
| 158 } | 159 } |
| 159 | 160 |
| 160 scoped_refptr<const Resource> SceneDef::CreateResource( | 161 scoped_refptr<const Resource> SceneDef::CreateResource( |
| 161 uint32_t resource_id, | 162 uint32_t resource_id, |
| 162 mojo::gfx::composition::ResourcePtr resource_decl, | 163 mojo::gfx::composition::ResourcePtr resource_decl, |
| 163 const SceneResolver& resolver, | 164 const SceneResolver& resolver, |
| 164 const SceneUnavailableSender& unavailable_sender, | 165 const SceneUnavailableSender& unavailable_sender, |
| 165 std::ostream& err) { | 166 std::ostream& err) { |
| 166 DCHECK(resource_decl); | 167 DCHECK(resource_decl); |
| 167 | 168 |
| 168 if (resource_decl->is_scene()) { | 169 if (resource_decl->is_scene()) { |
| 169 auto& scene_resource_decl = resource_decl->get_scene(); | 170 auto& scene_resource_decl = resource_decl->get_scene(); |
| 170 DCHECK(scene_resource_decl->scene_token); | 171 DCHECK(scene_resource_decl->scene_token); |
| 171 | 172 |
| 172 const mojo::gfx::composition::SceneToken& scene_token = | 173 const mojo::gfx::composition::SceneToken& scene_token = |
| 173 *scene_resource_decl->scene_token; | 174 *scene_resource_decl->scene_token; |
| 174 base::WeakPtr<SceneDef> referenced_scene = resolver.Run(scene_token); | 175 if (!resolver.Run(scene_token)) |
| 175 if (!referenced_scene) | |
| 176 unavailable_sender.Run(resource_id); | 176 unavailable_sender.Run(resource_id); |
| 177 return new SceneResource(scene_token, referenced_scene); | 177 return new SceneResource(scene_token); |
| 178 } | 178 } |
| 179 | 179 |
| 180 if (resource_decl->is_mailbox_texture()) { | 180 if (resource_decl->is_mailbox_texture()) { |
| 181 auto& mailbox_texture_resource_decl = resource_decl->get_mailbox_texture(); | 181 auto& mailbox_texture_resource_decl = resource_decl->get_mailbox_texture(); |
| 182 DCHECK(mailbox_texture_resource_decl->mailbox_name.size() == | 182 DCHECK(mailbox_texture_resource_decl->mailbox_name.size() == |
| 183 GL_MAILBOX_SIZE_CHROMIUM); | 183 GL_MAILBOX_SIZE_CHROMIUM); |
| 184 DCHECK(mailbox_texture_resource_decl->size); | 184 DCHECK(mailbox_texture_resource_decl->size); |
| 185 | 185 |
| 186 const int32_t width = mailbox_texture_resource_decl->size->width; | 186 const int32_t width = mailbox_texture_resource_decl->size->width; |
| 187 const int32_t height = mailbox_texture_resource_decl->size->height; | 187 const int32_t height = mailbox_texture_resource_decl->size->height; |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 287 return new LayerNode(node_id, std::move(content_transform), | 287 return new LayerNode(node_id, std::move(content_transform), |
| 288 content_clip.Pass(), hit_test_behavior.Pass(), | 288 content_clip.Pass(), hit_test_behavior.Pass(), |
| 289 combinator, child_node_ids, layer_rect, blend.Pass()); | 289 combinator, child_node_ids, layer_rect, blend.Pass()); |
| 290 } | 290 } |
| 291 | 291 |
| 292 err << "Unsupported node op type: node_id=" << node_id | 292 err << "Unsupported node op type: node_id=" << node_id |
| 293 << ", node_op=" << node_decl->op; | 293 << ", node_op=" << node_decl->op; |
| 294 return nullptr; | 294 return nullptr; |
| 295 } | 295 } |
| 296 | 296 |
| 297 const Node* SceneDef::FindNode(uint32_t node_id) const { | 297 SceneDef::Collector::Collector(const SceneDef* scene, |
| 298 auto it = nodes_.find(node_id); | 298 uint32_t version, |
| 299 return it != nodes_.end() ? it->second.get() : nullptr; | 299 int64_t presentation_time, |
| 300 std::ostream& err) |
| 301 : SceneContentBuilder(scene->label_, |
| 302 version, |
| 303 presentation_time, |
| 304 scene->resources_.size(), |
| 305 scene->nodes_.size(), |
| 306 err), |
| 307 scene_(scene) { |
| 308 DCHECK(scene_); |
| 300 } | 309 } |
| 301 | 310 |
| 302 const Resource* SceneDef::FindResource(uint32_t resource_id) const { | 311 SceneDef::Collector::~Collector() {} |
| 303 auto it = resources_.find(resource_id); | 312 |
| 304 return it != resources_.end() ? it->second.get() : nullptr; | 313 const Node* SceneDef::Collector::FindNode(uint32_t node_id) const { |
| 314 auto it = scene_->nodes_.find(node_id); |
| 315 return it != scene_->nodes_.end() ? it->second.get() : nullptr; |
| 305 } | 316 } |
| 306 | 317 |
| 307 const SceneContent* SceneDef::FindContent(uint32_t version) const { | 318 const Resource* SceneDef::Collector::FindResource(uint32_t resource_id) const { |
| 308 if (!content_) | 319 auto it = scene_->resources_.find(resource_id); |
| 309 return nullptr; | 320 return it != scene_->resources_.end() ? it->second.get() : nullptr; |
| 310 | |
| 311 // TODO(jeffbrown): Consider briefly caching older versions to allow them | |
| 312 // to be used to provide alternate content for node combinators. | |
| 313 if (version != mojo::gfx::composition::kSceneVersionNone && | |
| 314 version != content_->version() && | |
| 315 content_->version() != mojo::gfx::composition::kSceneVersionNone) | |
| 316 return nullptr; | |
| 317 return content_.get(); | |
| 318 } | 321 } |
| 319 | 322 |
| 320 SceneDef::Publication::Publication( | 323 SceneDef::Publication::Publication( |
| 321 mojo::gfx::composition::SceneMetadataPtr metadata) | 324 mojo::gfx::composition::SceneMetadataPtr metadata) |
| 322 : metadata(metadata.Pass()) { | 325 : metadata(metadata.Pass()) { |
| 323 DCHECK(this->metadata); | 326 DCHECK(this->metadata); |
| 324 } | 327 } |
| 325 | 328 |
| 326 SceneDef::Publication::~Publication() {} | 329 SceneDef::Publication::~Publication() {} |
| 327 | 330 |
| 328 } // namespace compositor | 331 } // namespace compositor |
| OLD | NEW |