| 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 <memory> | 5 #include <memory> |
| 6 #include <string> | 6 #include <string> |
| 7 | 7 |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 | 162 |
| 163 callback.Run(false); | 163 callback.Run(false); |
| 164 } | 164 } |
| 165 | 165 |
| 166 // |ChoreographerDelegate|: | 166 // |ChoreographerDelegate|: |
| 167 void OnDraw(const mojo::gfx::composition::FrameInfo& frame_info, | 167 void OnDraw(const mojo::gfx::composition::FrameInfo& frame_info, |
| 168 const base::TimeDelta& time_delta) override { | 168 const base::TimeDelta& time_delta) override { |
| 169 if (!properties()) | 169 if (!properties()) |
| 170 return; | 170 return; |
| 171 | 171 |
| 172 auto update = mojo::gfx::composition::SceneUpdate::New(); |
| 173 |
| 172 const mojo::Size& size = *properties()->view_layout->size; | 174 const mojo::Size& size = *properties()->view_layout->size; |
| 173 mojo::RectF bounds; | 175 if (size.width > 0 && size.height > 0) { |
| 174 bounds.width = size.width; | 176 mojo::RectF bounds; |
| 175 bounds.height = size.height; | 177 bounds.width = size.width; |
| 178 bounds.height = size.height; |
| 176 | 179 |
| 177 auto update = mojo::gfx::composition::SceneUpdate::New(); | 180 mojo::gfx::composition::ResourcePtr content_resource = |
| 178 mojo::gfx::composition::ResourcePtr content_resource = | 181 ganesh_renderer()->DrawCanvas( |
| 179 ganesh_renderer()->DrawCanvas(size, | 182 size, base::Bind(&PDFDocumentView::DrawContent, |
| 180 base::Bind(&PDFDocumentView::DrawContent, | 183 base::Unretained(this), size)); |
| 181 base::Unretained(this), size)); | 184 DCHECK(content_resource); |
| 182 DCHECK(content_resource); | 185 update->resources.insert(kContentImageResourceId, |
| 183 update->resources.insert(kContentImageResourceId, content_resource.Pass()); | 186 content_resource.Pass()); |
| 184 | 187 |
| 185 auto root_node = mojo::gfx::composition::Node::New(); | 188 auto root_node = mojo::gfx::composition::Node::New(); |
| 186 root_node->hit_test_behavior = | 189 root_node->hit_test_behavior = |
| 187 mojo::gfx::composition::HitTestBehavior::New(); | 190 mojo::gfx::composition::HitTestBehavior::New(); |
| 188 root_node->op = mojo::gfx::composition::NodeOp::New(); | 191 root_node->op = mojo::gfx::composition::NodeOp::New(); |
| 189 root_node->op->set_image(mojo::gfx::composition::ImageNodeOp::New()); | 192 root_node->op->set_image(mojo::gfx::composition::ImageNodeOp::New()); |
| 190 root_node->op->get_image()->content_rect = bounds.Clone(); | 193 root_node->op->get_image()->content_rect = bounds.Clone(); |
| 191 root_node->op->get_image()->image_resource_id = kContentImageResourceId; | 194 root_node->op->get_image()->image_resource_id = kContentImageResourceId; |
| 192 update->nodes.insert(kRootNodeId, root_node.Pass()); | 195 update->nodes.insert(kRootNodeId, root_node.Pass()); |
| 196 } else { |
| 197 auto root_node = mojo::gfx::composition::Node::New(); |
| 198 update->nodes.insert(kRootNodeId, root_node.Pass()); |
| 199 } |
| 193 | 200 |
| 194 scene()->Update(update.Pass()); | 201 scene()->Update(update.Pass()); |
| 195 | 202 |
| 196 auto metadata = mojo::gfx::composition::SceneMetadata::New(); | 203 auto metadata = mojo::gfx::composition::SceneMetadata::New(); |
| 197 metadata->version = scene_version(); | 204 metadata->version = scene_version(); |
| 198 scene()->Publish(metadata.Pass()); | 205 scene()->Publish(metadata.Pass()); |
| 199 } | 206 } |
| 200 | 207 |
| 201 void DrawContent(const mojo::Size& size, SkCanvas* canvas) { | 208 void DrawContent(const mojo::Size& size, SkCanvas* canvas) { |
| 202 if (!cached_image_) { | 209 if (!cached_image_) { |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 296 | 303 |
| 297 DISALLOW_COPY_AND_ASSIGN(PDFContentViewerApp); | 304 DISALLOW_COPY_AND_ASSIGN(PDFContentViewerApp); |
| 298 }; | 305 }; |
| 299 | 306 |
| 300 } // namespace examples | 307 } // namespace examples |
| 301 | 308 |
| 302 MojoResult MojoMain(MojoHandle application_request) { | 309 MojoResult MojoMain(MojoHandle application_request) { |
| 303 mojo::ApplicationRunnerChromium runner(new examples::PDFContentViewerApp()); | 310 mojo::ApplicationRunnerChromium runner(new examples::PDFContentViewerApp()); |
| 304 return runner.Run(application_request); | 311 return runner.Run(application_request); |
| 305 } | 312 } |
| OLD | NEW |