File: graphics_data.h

package info (click to toggle)
boinc 8.0.4%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 106,832 kB
  • sloc: cpp: 167,537; php: 111,699; pascal: 56,262; ansic: 49,284; xml: 18,762; python: 7,938; javascript: 6,538; sh: 5,719; makefile: 2,183; java: 2,041; objc: 1,867; perl: 1,843; sql: 830; lisp: 47; csh: 30
file content (83 lines) | stat: -rw-r--r-- 3,166 bytes parent folder | download | duplicates (6)
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
// This file is part of BOINC.
// http://boinc.berkeley.edu
// Copyright (C) 2008 University of California
//
// BOINC is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License
// as published by the Free Software Foundation,
// either version 3 of the License, or (at your option) any later version.
//
// BOINC is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
// See the GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with BOINC.  If not, see <http://www.gnu.org/licenses/>.

// The class GRAPHICS_DOUBLE_BUFFER provides a mechanism
// for synchronizing the generation of graphics information
// (done by the "science thread")
// with the graphics rendering (done by the "GUI thread",
// which periodically calls the application-supplied render() function)
//
// We assume that graphics info is generated incrementally
// and displayed incrementally.
// The scheme handles mismatches between generation and rendering rates:
// - if generation is faster than display, data cycles will be skipped
// - if display is faster than generation, the display will "linger"
//   on a cycle until the next cycle is available in its entirety.
//
// Here's what the application programmer does:
// - subclass GRAPHICS_BUFFER, adding your application-specific data
// - declare a GRAPHICS_DOUBLE_BUFFER object (call it gdb),
//   initializing it with pointers to two GRAPHICS_BUFFER structures.
// - when the science thread wants to add an increment of data,
//   it calls gdb->get_generate_buffer(first)
//   ("first" indicates whether this is the first data increment of a cycle).
//   If this returns nonzero, it adds data to the buffer.
//   If this addition causes it to be full, it calls gdb->generate_done();
// - render() calls gdb->get_render_buffer().
//   If this returns nonzero, it displays some or all the data.
//   If this completes the display of the data, it calls gdb->render_done().

// Here's how it works:
// There are two buffers, each with a "state" (see below).
// In a given state, only one thread can access the data or change the state.
//
#ifndef BOINC_GRAPHICS_DATA_H
#define BOINC_GRAPHICS_DATA_H

#define GB_STATE_IDLE       0
#define GB_STATE_GENERATING 1
#define GB_STATE_GENERATED  2
#define GB_STATE_RENDERING  3
#define GB_STATE_RENDERED   4

// subclass this for your applications
//
class GRAPHICS_BUFFER {
public:
    virtual ~GRAPHICS_BUFFER() {}
    virtual void clear();
    int state;
};

class GRAPHICS_DOUBLE_BUFFER {
    GRAPHICS_BUFFER* b1, *b2;
    GRAPHICS_BUFFER* get_buffer(int state);
public:
    void init(GRAPHICS_BUFFER*, GRAPHICS_BUFFER*);

    // the following called by app's render()
    //
    GRAPHICS_BUFFER* get_render_buffer();
    void render_done(GRAPHICS_BUFFER*);

    // the following called by app's science thread
    //
    GRAPHICS_BUFFER* get_generate_buffer(bool first);
    void generate_done(GRAPHICS_BUFFER*);
};

#endif