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

Side by Side Diff: services/ui/demo/mus_demo.cc

Issue 2581163003: Don't hold onto SkBitmap in mus_demo. (Closed)
Patch Set: Move include. Created 4 years 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 | « services/ui/demo/mus_demo.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/ui/demo/mus_demo.h" 5 #include "services/ui/demo/mus_demo.h"
6 6
7 #include "base/memory/ptr_util.h" 7 #include "base/memory/ptr_util.h"
8 #include "base/time/time.h" 8 #include "base/time/time.h"
9 #include "services/service_manager/public/cpp/connector.h" 9 #include "services/service_manager/public/cpp/connector.h"
10 #include "services/service_manager/public/cpp/service_context.h" 10 #include "services/service_manager/public/cpp/service_context.h"
11 #include "services/ui/public/cpp/gpu/gpu.h" 11 #include "services/ui/public/cpp/gpu/gpu.h"
12 #include "third_party/skia/include/core/SkBitmap.h"
12 #include "third_party/skia/include/core/SkCanvas.h" 13 #include "third_party/skia/include/core/SkCanvas.h"
13 #include "third_party/skia/include/core/SkColor.h" 14 #include "third_party/skia/include/core/SkColor.h"
14 #include "third_party/skia/include/core/SkImageInfo.h" 15 #include "third_party/skia/include/core/SkImageInfo.h"
15 #include "third_party/skia/include/core/SkPaint.h" 16 #include "third_party/skia/include/core/SkPaint.h"
16 #include "third_party/skia/include/core/SkRect.h" 17 #include "third_party/skia/include/core/SkRect.h"
17 #include "ui/aura/client/default_capture_client.h" 18 #include "ui/aura/client/default_capture_client.h"
18 #include "ui/aura/env.h" 19 #include "ui/aura/env.h"
19 #include "ui/aura/mus/mus_context_factory.h" 20 #include "ui/aura/mus/mus_context_factory.h"
20 #include "ui/aura/mus/property_converter.h" 21 #include "ui/aura/mus/property_converter.h"
21 #include "ui/aura/mus/window_tree_client.h" 22 #include "ui/aura/mus/window_tree_client.h"
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 base::TimeTicks now = base::TimeTicks::Now(); 218 base::TimeTicks now = base::TimeTicks::Now();
218 219
219 VLOG(1) << (now - last_draw_frame_time_).InMilliseconds() 220 VLOG(1) << (now - last_draw_frame_time_).InMilliseconds()
220 << "ms since the last frame was drawn."; 221 << "ms since the last frame was drawn.";
221 last_draw_frame_time_ = now; 222 last_draw_frame_time_ = now;
222 223
223 angle_ += 2.0; 224 angle_ += 2.0;
224 if (angle_ >= 360.0) 225 if (angle_ >= 360.0)
225 angle_ = 0.0; 226 angle_ = 0.0;
226 227
227 // Re-initialize the bitmap 228 const gfx::Rect& bounds = bitmap_window_->bounds();
228 bitmap_.reset(); 229
229 const gfx::Rect bounds = bitmap_window_->bounds(); 230 // Allocate a bitmap of correct size.
231 SkBitmap bitmap;
230 SkImageInfo image_info = SkImageInfo::MakeN32(bounds.width(), bounds.height(), 232 SkImageInfo image_info = SkImageInfo::MakeN32(bounds.width(), bounds.height(),
231 kPremul_SkAlphaType); 233 kPremul_SkAlphaType);
232 bitmap_.allocPixels(image_info); 234 bitmap.allocPixels(image_info);
233 235
234 // Draw the rotated square on background in bitmap. 236 // Draw the rotated square on background in bitmap.
235 SkCanvas canvas(bitmap_); 237 SkCanvas canvas(bitmap);
236 canvas.clear(kBgColor); 238 canvas.clear(kBgColor);
237 // TODO(kylechar): Add GL drawing instead of software rasterization in future. 239 // TODO(kylechar): Add GL drawing instead of software rasterization in future.
238 DrawSquare(bounds, angle_, &canvas); 240 DrawSquare(bounds, angle_, &canvas);
239 canvas.flush(); 241 canvas.flush();
240 242
241 gfx::ImageSkiaRep image_skia_rep(bitmap_, 1); 243 gfx::ImageSkiaRep image_skia_rep(bitmap, 1);
242 gfx::ImageSkia image_skia(image_skia_rep); 244 gfx::ImageSkia image_skia(image_skia_rep);
243 gfx::Image image(image_skia); 245 gfx::Image image(image_skia);
244 246
245 window_delegate_->SetImage(image); 247 window_delegate_->SetImage(image);
246 bitmap_window_->SchedulePaintInRect(bitmap_window_->bounds()); 248 bitmap_window_->SchedulePaintInRect(bitmap_window_->bounds());
247 } 249 }
248 250
249 } // namespace demo 251 } // namespace demo
250 } // namespace aura 252 } // namespace aura
OLDNEW
« no previous file with comments | « services/ui/demo/mus_demo.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698