layer_tree_owner.cc 803 B

1234567891011121314151617181920212223242526272829303132333435
  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.
  4. #include "ui/compositor/layer_tree_owner.h"
  5. #include "ui/compositor/layer.h"
  6. namespace ui {
  7. namespace {
  8. // Deletes |layer| and all its descendants.
  9. void DeepDeleteLayers(Layer* layer) {
  10. std::vector<Layer*> children = layer->children();
  11. for (std::vector<Layer*>::const_iterator it = children.begin();
  12. it != children.end();
  13. ++it) {
  14. Layer* child = *it;
  15. DeepDeleteLayers(child);
  16. }
  17. delete layer;
  18. }
  19. } // namespace
  20. LayerTreeOwner::LayerTreeOwner(std::unique_ptr<Layer> root)
  21. : root_(root.release()) {}
  22. LayerTreeOwner::~LayerTreeOwner() {
  23. if (root_)
  24. DeepDeleteLayers(root_);
  25. }
  26. } // namespace ui