gecko-dev/gfx/layers/BSPTree.h
Emilio Cobos Álvarez 256c124f94 Bug 1609996 - Reorder some includes affected by the previous patches. r=froydnj
This was done by:

This was done by applying:

```
diff --git a/python/mozbuild/mozbuild/code-analysis/mach_commands.py b/python/mozbuild/mozbuild/code-analysis/mach_commands.py
index 789affde7bbf..fe33c4c7d4d1 100644
--- a/python/mozbuild/mozbuild/code-analysis/mach_commands.py
+++ b/python/mozbuild/mozbuild/code-analysis/mach_commands.py
@@ -2007,7 +2007,7 @@ class StaticAnalysis(MachCommandBase):
         from subprocess import Popen, PIPE, check_output, CalledProcessError

         diff_process = Popen(self._get_clang_format_diff_command(commit), stdout=PIPE)
-        args = [sys.executable, clang_format_diff, "-p1", "-binary=%s" % clang_format]
+        args = [sys.executable, clang_format_diff, "-p1", "-binary=%s" % clang_format, '-sort-includes']

         if not output_file:
             args.append("-i")
```

Then running `./mach clang-format -c <commit-hash>`

Then undoing that patch.

Then running check_spidermonkey_style.py --fixup

Then running `./mach clang-format`

I had to fix four things:

 * I needed to move <utility> back down in GuardObjects.h because I was hitting
   obscure problems with our system include wrappers like this:

0:03.94 /usr/include/stdlib.h:550:14: error: exception specification in declaration does not match previous declaration
0:03.94 extern void *realloc (void *__ptr, size_t __size)
0:03.94              ^
0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/malloc_decls.h:53:1: note: previous declaration is here
0:03.94 MALLOC_DECL(realloc, void*, void*, size_t)
0:03.94 ^
0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/mozilla/mozalloc.h:22:32: note: expanded from macro 'MALLOC_DECL'
0:03.94     MOZ_MEMORY_API return_type name##_impl(__VA_ARGS__);
0:03.94                                ^
0:03.94 <scratch space>:178:1: note: expanded from here
0:03.94 realloc_impl
0:03.94 ^
0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/mozmemory_wrap.h:142:41: note: expanded from macro 'realloc_impl'
0:03.94 #define realloc_impl mozmem_malloc_impl(realloc)

   Which I really didn't feel like digging into.

 * I had to restore the order of TrustOverrideUtils.h and related files in nss
   because the .inc files depend on TrustOverrideUtils.h being included earlier.

 * I had to add a missing include to RollingNumber.h

 * Also had to partially restore include order in JsepSessionImpl.cpp to avoid
   some -WError issues due to some static inline functions being defined in a
   header but not used in the rest of the compilation unit.

Differential Revision: https://phabricator.services.mozilla.com/D60327

--HG--
extra : moz-landing-system : lando
2020-01-20 16:19:48 +00:00

137 lines
3.7 KiB
C++

/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef MOZILLA_LAYERS_BSPTREE_H
#define MOZILLA_LAYERS_BSPTREE_H
#include <list>
#include <utility>
#include "mozilla/ArenaAllocator.h"
#include "mozilla/UniquePtr.h"
#include "mozilla/gfx/Polygon.h"
#include "nsTArray.h"
namespace mozilla {
namespace layers {
class Layer;
/**
* Represents a layer that might have a non-rectangular geometry.
*/
struct LayerPolygon {
explicit LayerPolygon(Layer* aLayer) : layer(aLayer) {}
LayerPolygon(Layer* aLayer, gfx::Polygon&& aGeometry)
: layer(aLayer), geometry(Some(std::move(aGeometry))) {}
LayerPolygon(Layer* aLayer, nsTArray<gfx::Point4D>&& aPoints,
const gfx::Point4D& aNormal)
: layer(aLayer) {
geometry.emplace(std::move(aPoints), aNormal);
}
Layer* layer;
Maybe<gfx::Polygon> geometry;
};
/**
* Allocate BSPTreeNodes from a memory arena to improve performance with
* complex scenes.
* The arena size of 4096 bytes was selected as an arbitrary power of two.
* Depending on the platform, this size accommodates roughly 100 BSPTreeNodes.
*/
typedef mozilla::ArenaAllocator<4096, 8> BSPTreeArena;
/**
* Aliases the container type used to store layers within BSPTreeNodes.
*/
typedef std::list<LayerPolygon> LayerList;
/**
* Represents a node in a BSP tree. The node contains at least one layer with
* associated geometry that is used as a splitting plane, and at most two child
* nodes that represent the splitting planes that further subdivide the space.
*/
struct BSPTreeNode {
explicit BSPTreeNode(nsTArray<LayerList*>& aListPointers)
: front(nullptr), back(nullptr) {
// Store the layer list pointer to free memory when BSPTree is destroyed.
aListPointers.AppendElement(&layers);
}
const gfx::Polygon& First() const {
MOZ_ASSERT(!layers.empty());
MOZ_ASSERT(layers.front().geometry);
return *layers.front().geometry;
}
static void* operator new(size_t aSize, BSPTreeArena& mPool) {
return mPool.Allocate(aSize);
}
BSPTreeNode* front;
BSPTreeNode* back;
LayerList layers;
};
/**
* BSPTree class takes a list of layers as an input and uses binary space
* partitioning algorithm to create a tree structure that can be used for
* depth sorting.
* Sources for more information:
* https://en.wikipedia.org/wiki/Binary_space_partitioning
* ftp://ftp.sgi.com/other/bspfaq/faq/bspfaq.html
*/
class BSPTree final {
public:
/**
* The constructor modifies layers in the given list.
*/
explicit BSPTree(std::list<LayerPolygon>& aLayers) {
MOZ_ASSERT(!aLayers.empty());
mRoot = new (mPool) BSPTreeNode(mListPointers);
BuildTree(mRoot, aLayers);
}
~BSPTree() {
for (LayerList* listPtr : mListPointers) {
listPtr->~LayerList();
}
}
/**
* Builds and returns the back-to-front draw order for the created BSP tree.
*/
nsTArray<LayerPolygon> GetDrawOrder() const {
nsTArray<LayerPolygon> layers;
BuildDrawOrder(mRoot, layers);
return layers;
}
private:
BSPTreeArena mPool;
BSPTreeNode* mRoot;
nsTArray<LayerList*> mListPointers;
/**
* BuildDrawOrder and BuildTree are called recursively. The depth of the
* recursion depends on the amount of polygons and their intersections.
*/
void BuildDrawOrder(BSPTreeNode* aNode,
nsTArray<LayerPolygon>& aLayers) const;
void BuildTree(BSPTreeNode* aRoot, std::list<LayerPolygon>& aLayers);
};
} // namespace layers
} // namespace mozilla
#endif /* MOZILLA_LAYERS_BSPTREE_H */