~ubuntu-branches/ubuntu/wily/mir/wily-proposed

« back to all changes in this revision

Viewing changes to tests/include/mir_test_doubles/fake_renderable.h

  • Committer: Package Import Robot
  • Author(s): Ubuntu daily release
  • Date: 2014-10-10 14:01:26 UTC
  • mto: This revision was merged to the branch mainline in revision 84.
  • Revision ID: package-import@ubuntu.com-20141010140126-n1czko8na1kuz4ll
Tags: upstream-0.8.0+14.10.20141010
Import upstream version 0.8.0+14.10.20141010

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright © 2013 Canonical Ltd.
 
3
 *
 
4
 * This program is free software: you can redistribute it and/or modify it
 
5
 * under the terms of the GNU General Public License version 3,
 
6
 * as published by the Free Software Foundation.
 
7
 *
 
8
 * This program is distributed in the hope that it will be useful,
 
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
 * GNU General Public License for more details.
 
12
 *
 
13
 * You should have received a copy of the GNU General Public License
 
14
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
15
 *
 
16
 * Authored by: Daniel van Vugt <daniel.van.vugt@canonical.com>
 
17
 */
 
18
 
 
19
#ifndef MIR_TEST_DOUBLES_FAKE_RENDERABLE_H_
 
20
#define MIR_TEST_DOUBLES_FAKE_RENDERABLE_H_
 
21
 
 
22
#include "stub_buffer.h"
 
23
#include "mir/graphics/renderable.h"
 
24
#define GLM_FORCE_RADIANS
 
25
#include <glm/gtc/matrix_transform.hpp>
 
26
#include <gmock/gmock.h>
 
27
 
 
28
namespace mir
 
29
{
 
30
namespace test
 
31
{
 
32
namespace doubles
 
33
{
 
34
 
 
35
class FakeRenderable : public graphics::Renderable
 
36
{
 
37
public:
 
38
    FakeRenderable(int x, int y, int width, int height)
 
39
        : FakeRenderable{geometry::Rectangle{{x,y},{width,height}}}
 
40
    {
 
41
    }
 
42
    FakeRenderable(geometry::Rectangle display_area)
 
43
        : FakeRenderable{display_area, 1.0f, true, true, true}
 
44
    {
 
45
    }
 
46
 
 
47
    FakeRenderable(geometry::Rectangle display_area,
 
48
                   float opacity)
 
49
        : FakeRenderable{display_area, opacity, true, true, true}
 
50
    {
 
51
    }
 
52
 
 
53
    FakeRenderable(geometry::Rectangle display_area,
 
54
                   float opacity,
 
55
                   bool rectangular,
 
56
                   bool visible)
 
57
        : FakeRenderable{display_area, opacity, rectangular, visible, true}
 
58
    {
 
59
    }
 
60
 
 
61
    FakeRenderable(geometry::Rectangle display_area,
 
62
                   float opacity,
 
63
                   bool rectangular,
 
64
                   bool visible,
 
65
                   bool posted)
 
66
        : buf{std::make_shared<StubBuffer>()},
 
67
          rect(display_area),
 
68
          opacity(opacity),
 
69
          rectangular(rectangular),
 
70
          visible_(visible),
 
71
          posted(posted)
 
72
    {
 
73
    }
 
74
 
 
75
    ID id() const override
 
76
    {
 
77
        return this;
 
78
    }
 
79
 
 
80
    float alpha() const override
 
81
    {
 
82
        return opacity;
 
83
    }
 
84
 
 
85
    glm::mat4 transformation() const override
 
86
    {
 
87
        return glm::mat4();
 
88
    }
 
89
 
 
90
    bool visible() const override
 
91
    {
 
92
        return visible_ && posted;
 
93
    }
 
94
 
 
95
    bool shaped() const override
 
96
    {
 
97
        return !rectangular;
 
98
    }
 
99
 
 
100
    void set_buffer(std::shared_ptr<graphics::Buffer> b)
 
101
    {
 
102
        buf = b;
 
103
    }
 
104
 
 
105
    std::shared_ptr<graphics::Buffer> buffer() const override
 
106
    {
 
107
        return buf;
 
108
    }
 
109
 
 
110
    geometry::Rectangle screen_position() const override
 
111
    {
 
112
        return rect;
 
113
    }
 
114
 
 
115
    int buffers_ready_for_compositor() const override
 
116
    {
 
117
        return 1;
 
118
    }
 
119
 
 
120
private:
 
121
    std::shared_ptr<graphics::Buffer> buf;
 
122
    mir::geometry::Rectangle rect;
 
123
    float opacity;
 
124
    bool rectangular;
 
125
    bool visible_;
 
126
    bool posted;
 
127
};
 
128
 
 
129
} // namespace doubles
 
130
} // namespace test
 
131
} // namespace mir
 
132
#endif // MIR_TEST_DOUBLES_FAKE_RENDERABLE_H_