]> Dogcows Code - chaz/yoink/blob - src/moof/backend.cc
fa3ad3102ab546a9cc630f49ff3d4a8a2fcb046b
[chaz/yoink] / src / moof / backend.cc
1
2 /*] Copyright (c) 2009-2011, Charles McGarvey [*****************************
3 **] All rights reserved.
4 *
5 * Distributable under the terms and conditions of the 2-clause BSD license;
6 * see the file COPYING for a complete text of the license.
7 *
8 *****************************************************************************/
9
10 #if HAVE_CONFIG_H
11 #include "config.h"
12 #endif
13
14 #include <stdexcept>
15
16 #include <SDL/SDL.h>
17 #include "fastevents.h"
18
19 #include "backend.hh"
20 #include "log.hh"
21
22
23 namespace moof {
24
25
26 static int retain_count = 0;
27
28 backend::backend()
29 {
30 if (retain_count++ == 0)
31 {
32 #if PLATFORM_WIN32
33 if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) != 0)
34 #else
35 if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTTHREAD) != 0)
36 #endif
37 {
38 throw std::runtime_error(SDL_GetError());
39 }
40 else
41 {
42 char name[128];
43 SDL_VideoDriverName(name, sizeof(name));
44 log_info << "initialized SDL; using video driver `" <<
45 name << "'" << std::endl;
46 }
47 if (FE_Init() != 0)
48 {
49 throw std::runtime_error(FE_GetError());
50 }
51 }
52 }
53
54 backend::backend(const backend& backend)
55 {
56 ++retain_count;
57 }
58
59 backend& backend::operator = (const backend& backend)
60 {
61 ++retain_count;
62 return *this;
63 }
64
65 backend::~backend()
66 {
67 if (--retain_count == 0)
68 {
69 log_info("shutting down SDL...");
70 FE_Quit();
71 SDL_Quit();
72 }
73 }
74
75 bool backend::is_initialized()
76 {
77 return 0 < retain_count;
78 }
79
80
81 } // namespace moof
82
This page took 0.037556 seconds and 4 git commands to generate.