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 <algorithm> | 5 #include <algorithm> |
6 | 6 |
7 #include "base/macros.h" | 7 #include "base/macros.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/strings/string_tokenizer.h" | 10 #include "base/strings/string_tokenizer.h" |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 if (!bitmap_.isNull()) | 86 if (!bitmap_.isNull()) |
87 DrawBitmap(); | 87 DrawBitmap(); |
88 } | 88 } |
89 | 89 |
90 virtual void OnViewManagerDisconnected(ViewManager* view_manager) override { | 90 virtual void OnViewManagerDisconnected(ViewManager* view_manager) override { |
91 // TODO(aa): Need to figure out how shutdown works. | 91 // TODO(aa): Need to figure out how shutdown works. |
92 } | 92 } |
93 | 93 |
94 // Overridden from ViewObserver: | 94 // Overridden from ViewObserver: |
95 virtual void OnViewBoundsChanged(View* view, | 95 virtual void OnViewBoundsChanged(View* view, |
96 const gfx::Rect& old_bounds, | 96 const Rect& old_bounds, |
97 const gfx::Rect& new_bounds) override { | 97 const Rect& new_bounds) override { |
98 DCHECK_EQ(view, root_); | 98 DCHECK_EQ(view, root_); |
99 DrawBitmap(); | 99 DrawBitmap(); |
100 } | 100 } |
101 | 101 |
102 virtual void OnViewDestroyed(View* view) override { | 102 virtual void OnViewDestroyed(View* view) override { |
103 DCHECK_EQ(view, root_); | 103 DCHECK_EQ(view, root_); |
104 delete this; | 104 delete this; |
105 } | 105 } |
106 | 106 |
107 void DecodePNG(URLResponsePtr response) { | 107 void DecodePNG(URLResponsePtr response) { |
(...skipping 20 matching lines...) Expand all Loading... |
128 gfx::PNGCodec::Decode(static_cast<const unsigned char*>(data.get()), | 128 gfx::PNGCodec::Decode(static_cast<const unsigned char*>(data.get()), |
129 content_length, | 129 content_length, |
130 &bitmap_); | 130 &bitmap_); |
131 } | 131 } |
132 | 132 |
133 void DrawBitmap() { | 133 void DrawBitmap() { |
134 if (!root_) | 134 if (!root_) |
135 return; | 135 return; |
136 | 136 |
137 skia::RefPtr<SkCanvas> canvas(skia::AdoptRef(skia::CreatePlatformCanvas( | 137 skia::RefPtr<SkCanvas> canvas(skia::AdoptRef(skia::CreatePlatformCanvas( |
138 root_->bounds().width(), root_->bounds().height(), true))); | 138 root_->bounds().width, root_->bounds().height, true))); |
139 canvas->drawColor(SK_ColorGRAY); | 139 canvas->drawColor(SK_ColorGRAY); |
140 SkPaint paint; | 140 SkPaint paint; |
141 SkScalar scale = | 141 SkScalar scale = |
142 SkFloatToScalar(zoom_percentage_ * 1.0f / kDefaultZoomPercentage); | 142 SkFloatToScalar(zoom_percentage_ * 1.0f / kDefaultZoomPercentage); |
143 canvas->scale(scale, scale); | 143 canvas->scale(scale, scale); |
144 canvas->drawBitmap(bitmap_, 0, 0, &paint); | 144 canvas->drawBitmap(bitmap_, 0, 0, &paint); |
145 bitmap_uploader_->SetBitmap( | 145 bitmap_uploader_->SetBitmap( |
146 skia::GetTopDevice(*canvas)->accessBitmap(true)); | 146 skia::GetTopDevice(*canvas)->accessBitmap(true)); |
147 } | 147 } |
148 | 148 |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 DISALLOW_COPY_AND_ASSIGN(PNGViewer); | 240 DISALLOW_COPY_AND_ASSIGN(PNGViewer); |
241 }; | 241 }; |
242 | 242 |
243 } // namespace examples | 243 } // namespace examples |
244 } // namespace mojo | 244 } // namespace mojo |
245 | 245 |
246 MojoResult MojoMain(MojoHandle shell_handle) { | 246 MojoResult MojoMain(MojoHandle shell_handle) { |
247 mojo::ApplicationRunnerChromium runner(new mojo::examples::PNGViewer); | 247 mojo::ApplicationRunnerChromium runner(new mojo::examples::PNGViewer); |
248 return runner.Run(shell_handle); | 248 return runner.Run(shell_handle); |
249 } | 249 } |
OLD | NEW |