blob: 674b6965a3a8fcd2b0cfcf1c5e8672c906fdeb75 [file] [log] [blame]
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <memory>
#include <vector>
#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "chrome/browser/vr/elements/ui_element.h"
#include "chrome/browser/vr/elements/ui_element_iterator.h"
#include "chrome/browser/vr/elements/ui_element_name.h"
#include "chrome/browser/vr/keyboard_delegate.h"
#include "third_party/skia/include/core/SkColor.h"
namespace base {
class TimeTicks;
} // namespace base
namespace gfx {
class Transform;
} // namespace gfx
namespace vr {
class UiElement;
class UiScene {
void AddUiElement(UiElementName parent, std::unique_ptr<UiElement> element);
std::unique_ptr<UiElement> RemoveUiElement(int element_id);
// Handles per-frame updates, giving each element the opportunity to update,
// if necessary (eg, for animations). NB: |current_time| is the shared,
// absolute begin frame time.
// Returns true if *anything* was updated.
bool OnBeginFrame(const base::TimeTicks& current_time,
const gfx::Transform& head_pose);
// Returns true if any textures were redrawn.
bool UpdateTextures();
UiElement& root_element();
UiElement* GetUiElementById(int element_id) const;
UiElement* GetUiElementByName(UiElementName name) const;
typedef std::vector<const UiElement*> Elements;
Elements GetVisibleElementsToDraw() const;
Elements GetVisibleWebVrOverlayElementsToDraw() const;
Elements GetPotentiallyVisibleElements() const;
float background_distance() const { return background_distance_; }
void set_background_distance(float d) { background_distance_ = d; }
void set_dirty() { is_dirty_ = true; }
void OnGlInitialized(SkiaSurfaceProvider* provider);
SkiaSurfaceProvider* SurfaceProviderForTesting() { return provider_; }
void InitializeElement(UiElement* element);
std::unique_ptr<UiElement> root_element_;
float background_distance_ = 10.0f;
bool gl_initialized_ = false;
bool initialized_scene_ = false;
// TODO(mthiesse): Convert everything that manipulates UI elements to
// bindings. Don't allow any code to go in and manipulate UI elements outside
// of bindings so that we can do a single pass and update everything and
// easily compute dirtiness.
bool is_dirty_ = false;
SkiaSurfaceProvider* provider_ = nullptr;
} // namespace vr