summaryrefslogtreecommitdiffstats
path: root/gfx/thebes/ContextStateTracker.h
blob: 01cd3c5b24be24bb17c39c4c9d6120ac82668863 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
 * 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 GFX_CONTEXTSTATETRACKER_H
#define GFX_CONTEXTSTATETRACKER_H

#include "GLTypes.h"
#include "mozilla/TimeStamp.h"
#include "nsTArray.h"
#include <string.h>

namespace mozilla {
namespace gl {
class GLContext;
} // namespace gl

/**
 * This class tracks the state of the context for debugging and profiling.
 * Each section pushes a new stack entry and must be matched by an end section.
 * All nested section must be ended before ending a parent section.
 */
class ContextStateTracker {
public:
  ContextStateTracker() {}

private:

  bool IsProfiling() { return true; }

protected:
  typedef GLuint TimerQueryHandle;

  class ContextState {
  public:
    explicit ContextState(const char* aSectionName)
      : mSectionName(aSectionName)
    {}

    const char* mSectionName;
    mozilla::TimeStamp mCpuTimeStart;
    mozilla::TimeStamp mCpuTimeEnd;
    TimerQueryHandle mStartQueryHandle;
  };

  ContextState& Top() {
    MOZ_ASSERT(mSectionStack.Length());
    return mSectionStack[mSectionStack.Length() - 1];
  }

  nsTArray<ContextState> mCompletedSections;
  nsTArray<ContextState> mSectionStack;
};

/*
class ID3D11DeviceContext;

class ContextStateTrackerD3D11 final : public ContextStateTracker {
public:
  // TODO Implement me
  void PushD3D11Section(ID3D11DeviceContext* aCtxt, const char* aSectionName) {}
  void PopD3D11Section(ID3D11DeviceContext* aCtxt, const char* aSectionName) {}
  void DestroyD3D11(ID3D11DeviceContext* aCtxt) {}

private:
  void Flush();
};
*/

class ContextStateTrackerOGL final : public ContextStateTracker {
  typedef mozilla::gl::GLContext GLContext;
public:
  void PushOGLSection(GLContext* aGL, const char* aSectionName);
  void PopOGLSection(GLContext* aGL, const char* aSectionName);
  void DestroyOGL(GLContext* aGL);
private:
  void Flush(GLContext* aGL);
};

} // namespace mozilla

#endif