Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(244)

Side by Side Diff: examples/ui/png_viewer/png_viewer.cc

Issue 1679023006: Reify view ownership as a message pipe. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « examples/ui/pdf_viewer/pdf_viewer.cc ('k') | examples/ui/shapes/shapes_app.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <string> 5 #include <string>
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/macros.h" 8 #include "base/macros.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "mojo/application/application_runner_chromium.h" 10 #include "mojo/application/application_runner_chromium.h"
11 #include "mojo/data_pipe_utils/data_pipe_utils.h" 11 #include "mojo/data_pipe_utils/data_pipe_utils.h"
12 #include "mojo/public/c/system/main.h" 12 #include "mojo/public/c/system/main.h"
13 #include "mojo/ui/content_viewer_app.h" 13 #include "mojo/ui/content_viewer_app.h"
14 #include "mojo/ui/ganesh_view.h" 14 #include "mojo/ui/ganesh_view.h"
15 #include "third_party/skia/include/core/SkBitmap.h" 15 #include "third_party/skia/include/core/SkBitmap.h"
16 #include "third_party/skia/include/core/SkCanvas.h" 16 #include "third_party/skia/include/core/SkCanvas.h"
17 #include "third_party/skia/include/core/SkImage.h" 17 #include "third_party/skia/include/core/SkImage.h"
18 #include "third_party/skia/include/core/SkSurface.h" 18 #include "third_party/skia/include/core/SkSurface.h"
19 #include "ui/gfx/codec/png_codec.h" 19 #include "ui/gfx/codec/png_codec.h"
20 20
21 namespace examples { 21 namespace examples {
22 22
23 namespace { 23 namespace {
24 constexpr uint32_t kContentImageResourceId = 1; 24 constexpr uint32_t kContentImageResourceId = 1;
25 constexpr uint32_t kRootNodeId = mojo::gfx::composition::kSceneRootNodeId; 25 constexpr uint32_t kRootNodeId = mojo::gfx::composition::kSceneRootNodeId;
26 } // namespace 26 } // namespace
27 27
28 class PNGView : public mojo::ui::GaneshView { 28 class PNGView : public mojo::ui::GaneshView {
29 public: 29 public:
30 PNGView( 30 PNGView(mojo::ApplicationImpl* app_impl,
31 mojo::ApplicationImpl* app_impl, 31 mojo::InterfaceRequest<mojo::ui::ViewOwner> view_owner_request,
32 const skia::RefPtr<SkImage>& image, 32 const skia::RefPtr<SkImage>& image)
33 const mojo::ui::ViewProvider::CreateViewCallback& create_view_callback) 33 : GaneshView(app_impl, view_owner_request.Pass(), "PNGViewer"),
34 : GaneshView(app_impl, "PNGViewer", create_view_callback), image_(image) { 34 image_(image) {
35 DCHECK(image_); 35 DCHECK(image_);
36 } 36 }
37 37
38 ~PNGView() override {} 38 ~PNGView() override {}
39 39
40 private: 40 private:
41 // |GaneshView|: 41 // |GaneshView|:
42 void OnLayout(mojo::ui::ViewLayoutParamsPtr layout_params, 42 void OnLayout(mojo::ui::ViewLayoutParamsPtr layout_params,
43 mojo::Array<uint32_t> children_needing_layout, 43 mojo::Array<uint32_t> children_needing_layout,
44 const OnLayoutCallback& callback) override { 44 const OnLayoutCallback& callback) override {
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 }; 99 };
100 100
101 class PNGContentViewProviderApp : public mojo::ui::ViewProviderApp { 101 class PNGContentViewProviderApp : public mojo::ui::ViewProviderApp {
102 public: 102 public:
103 PNGContentViewProviderApp(skia::RefPtr<SkImage> image) : image_(image) { 103 PNGContentViewProviderApp(skia::RefPtr<SkImage> image) : image_(image) {
104 DCHECK(image_); 104 DCHECK(image_);
105 } 105 }
106 106
107 ~PNGContentViewProviderApp() override {} 107 ~PNGContentViewProviderApp() override {}
108 108
109 bool CreateView( 109 void CreateView(
110 const std::string& connection_url, 110 const std::string& connection_url,
111 mojo::InterfaceRequest<mojo::ui::ViewOwner> view_owner_request,
111 mojo::InterfaceRequest<mojo::ServiceProvider> services, 112 mojo::InterfaceRequest<mojo::ServiceProvider> services,
112 mojo::ServiceProviderPtr exposed_services, 113 mojo::ServiceProviderPtr exposed_services) override {
113 const mojo::ui::ViewProvider::CreateViewCallback& callback) override { 114 new PNGView(app_impl(), view_owner_request.Pass(), image_);
114 new PNGView(app_impl(), image_, callback);
115 return true;
116 } 115 }
117 116
118 private: 117 private:
119 skia::RefPtr<SkImage> image_; 118 skia::RefPtr<SkImage> image_;
120 119
121 DISALLOW_COPY_AND_ASSIGN(PNGContentViewProviderApp); 120 DISALLOW_COPY_AND_ASSIGN(PNGContentViewProviderApp);
122 }; 121 };
123 122
124 class PNGContentViewerApp : public mojo::ui::ContentViewerApp { 123 class PNGContentViewerApp : public mojo::ui::ContentViewerApp {
125 public: 124 public:
(...skipping 22 matching lines...) Expand all
148 private: 147 private:
149 DISALLOW_COPY_AND_ASSIGN(PNGContentViewerApp); 148 DISALLOW_COPY_AND_ASSIGN(PNGContentViewerApp);
150 }; 149 };
151 150
152 } // namespace examples 151 } // namespace examples
153 152
154 MojoResult MojoMain(MojoHandle application_request) { 153 MojoResult MojoMain(MojoHandle application_request) {
155 mojo::ApplicationRunnerChromium runner(new examples::PNGContentViewerApp()); 154 mojo::ApplicationRunnerChromium runner(new examples::PNGContentViewerApp());
156 return runner.Run(application_request); 155 return runner.Run(application_request);
157 } 156 }
OLDNEW
« no previous file with comments | « examples/ui/pdf_viewer/pdf_viewer.cc ('k') | examples/ui/shapes/shapes_app.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698