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
3 // found in the LICENSE file.
5 #include "base/at_exit.h"
7 #include "base/command_line.h"
8 #include "base/message_loop/message_loop.h"
9 #include "mojo/public/cpp/application/application.h"
10 #include "mojo/public/cpp/environment/environment.h"
11 #include "mojo/public/cpp/system/core.h"
12 #include "mojo/public/cpp/system/macros.h"
13 #include "mojo/public/cpp/utility/run_loop.h"
14 #include "mojo/services/public/cpp/view_manager/view.h"
15 #include "mojo/services/public/cpp/view_manager/view_manager.h"
16 #include "mojo/services/public/cpp/view_manager/view_tree_node.h"
17 #include "ui/gfx/canvas.h"
23 #define SAMPLE_APP_EXPORT __declspec(dllexport)
26 #define SAMPLE_APP_EXPORT __attribute__((visibility("default")))
32 class SampleApp
: public Application
{
34 explicit SampleApp(MojoHandle service_provider_handle
)
35 : Application(service_provider_handle
) {
36 view_manager_
.reset(new view_manager::ViewManager(service_provider()));
37 view_manager_
->Init();
38 view_manager::ViewTreeNode
* node1
=
39 view_manager::ViewTreeNode::Create(view_manager_
.get());
40 view_manager::ViewTreeNode
* node11
=
41 view_manager::ViewTreeNode::Create(view_manager_
.get());
42 node11
->SetBounds(gfx::Rect(800, 600));
44 view_manager::View
* view11
=
45 view_manager::View::Create(view_manager_
.get());
46 node11
->SetActiveView(view11
);
47 view_manager_
->tree()->AddChild(node1
);
48 node1
->AddChild(node11
);
50 gfx::Canvas
canvas(gfx::Size(800, 600), 1.0f
, true);
51 canvas
.DrawColor(SK_ColorRED
);
53 skia::GetTopDevice(*canvas
.sk_canvas())->accessBitmap(true));
56 virtual ~SampleApp() {
60 // SampleApp creates a ViewManager and a trivial node hierarchy.
61 scoped_ptr
<view_manager::ViewManager
> view_manager_
;
63 DISALLOW_COPY_AND_ASSIGN(SampleApp
);
66 } // namespace examples
69 extern "C" SAMPLE_APP_EXPORT MojoResult CDECL
MojoMain(
70 MojoHandle service_provider_handle
) {
71 base::MessageLoop loop
;
73 mojo::examples::SampleApp
app(service_provider_handle
);
75 return MOJO_RESULT_OK
;