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

Side by Side Diff: chrome/browser/android/vr_shell/textures/loading_indicator_texture.cc

Issue 2877133002: VR: Add a loading indicator to the scene. (Closed)
Patch Set: Add units to timeout constant. Created 3 years, 7 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
OLDNEW
(Empty)
1 // Copyright 2017 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.
4
5 #include "chrome/browser/android/vr_shell/textures/loading_indicator_texture.h"
6
7 #include "base/logging.h"
8 #include "cc/paint/skia_paint_canvas.h"
9 #include "third_party/skia/include/core/SkCanvas.h"
10 #include "third_party/skia/include/core/SkColor.h"
11
12 namespace vr_shell {
13
14 namespace {
15
16 static constexpr SkColor kBackground = 0xCCAAAAAA;
17 static constexpr SkColor kForeground = 0xCC444444;
18 static constexpr float kWidth = 0.268;
19 static constexpr float kHeight = 0.008;
20
21 } // namespace
22
23 LoadingIndicatorTexture::LoadingIndicatorTexture() = default;
24
25 LoadingIndicatorTexture::~LoadingIndicatorTexture() = default;
26
27 gfx::Size LoadingIndicatorTexture::GetPreferredTextureSize(
28 int maximum_width) const {
29 return gfx::Size(maximum_width, maximum_width * kHeight / kWidth);
30 }
31
32 gfx::SizeF LoadingIndicatorTexture::GetDrawnSize() const {
33 return size_;
34 }
35
36 void LoadingIndicatorTexture::SetLoading(bool loading) {
37 loading_ = loading;
38 }
39
40 void LoadingIndicatorTexture::SetLoadProgress(float progress) {
41 DCHECK_GE(progress, 0.0f);
42 DCHECK_LE(progress, 1.0f);
43 progress_ = progress;
44 }
45
46 void LoadingIndicatorTexture::Draw(SkCanvas* canvas,
47 const gfx::Size& texture_size) {
48 size_.set_height(texture_size.height());
49 size_.set_width(texture_size.width());
50
51 canvas->save();
52 canvas->scale(size_.width() / kWidth, size_.width() / kWidth);
53
54 SkPaint paint;
55 paint.setColor(kBackground);
56 canvas->drawRoundRect({0, 0, kWidth, kHeight}, kHeight / 2, kHeight / 2,
57 paint);
58
59 if (loading_) {
60 paint.setColor(kForeground);
61 float progress_width = kHeight + (kWidth - kHeight) * progress_;
62 canvas->drawRoundRect({0, 0, progress_width, kHeight}, kHeight / 2,
63 kHeight / 2, paint);
64 }
65
66 canvas->restore();
67 }
68
69 } // namespace vr_shell
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698