~ubuntu-branches/ubuntu/trusty/mir/trusty-proposed

« back to all changes in this revision

Viewing changes to src/server/compositor/gl_renderer.cpp

  • Committer: Package Import Robot
  • Author(s): Ubuntu daily release, Daniel van Vugt, Ubuntu daily release
  • Date: 2014-03-17 15:12:00 UTC
  • mfrom: (1.1.58)
  • Revision ID: package-import@ubuntu.com-20140317151200-6ufbr8xngfydvn7l
Tags: 0.1.7+14.04.20140317.1-0ubuntu1
[ Daniel van Vugt ]
* New upstream release 0.1.7 (https://launchpad.net/mir/+milestone/0.1.7)
  - mirserver ABI bumped to 17
  - mirclient ABI unchanged, still at 7. Clients do not need rebuilding.
  - Server API changes (AKA why doesn't my code build any more?):
    . Class "CompositingCriteria" has been removed. It's replaced by the more
      flexible "Renderable" interface. This also resulted in parameter
      changes for the Renderer and scene filtering classes.
    . The function "DisplayConfiguration::configure_output()" has been
      removed. Instead, please use the new mutable version of
      "DisplayConfiguration::for_each_output()" with which you can modify
      the output structure passed in on each iteration.
    . Exposed formerly private class "GLRenderer" and demonstrated how
      to override its behaviour in demo-shell. This area is under
      construction and may experience further major changes.
  - Added initial support for hardware (HWC) overlays to accelerate
    rendering and reduce power consumption. Not complete yet.
  - Screen rotation: Added mouse cursor rotation support, so you can now
    still control things on a rotated screen. Still missing rotation of
    the cursor bitmap itself.
  - Lots of fixes to support nested Mir servers (see below).
  - Major simplification to how surface size/position/transformation
    interact, making transformations much easier to manage and work with.
  - Bugs fixed:
    . ./cross-compile-chroot.sh: line 83: popd: build-android-arm: invalid
      argument popd: usage: popd [-n] [+N | -N] (LP: #1287600)
    . Key events sent to the wrong client (and delayed) (LP: #1213804)
    . Nested servers never receive input events (in their filters)
      (LP: #1260612)
    . Software clients crash immediately on nested servers - what(): Failed
      to mmap buffer (LP: #1261286)
    . MirMotionEvent lacks local coordinates. Reports only screen
      coordinates. (LP: #1268819)
    . Nested Mir crashes with - what():
      MesaNativePlatform::create_internal_client is not implemented yet!
      (LP: #1279092)
    . clients fail to find some libraries if mir installed via "make install"
      (LP: #1285566)
    . Nested server hangs with multimonitor and internal clients.
      (LP: #1287282)
    . [regression] Multi-monitor frame sync no longer works (not
      synchronized), and frames skip/jump/stutter (LP: #1288570)
    . Mir FTBFS: /usr/bin/ld: cannot find -lmirtestdraw (when cmake ..
      -DMIR_ENABLE_TESTS=OFF) (LP: #1283951)
    . nested Mir library calls next_buffer() during startup (LP: #1284739)
    . Building Mir produces lots of warnings from GLM headers about
      deprecated degrees values vs radians (LP: #1286010)
    . [enhancement] screencast of a single window (LP: #1288478)
    . Nexus4 + mir_demo_client_eglplasma starts to stutter after a while
      (LP: #1189753)
    . --host-socket documented default argument isn't used as default
      (LP: #1262091)

[ Ubuntu daily release ]
* New rebuild forced

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
 * Authored By: Alexandros Frantzis <alexandros.frantzis@canonical.com>
16
16
 */
17
17
 
18
 
#include "gl_renderer.h"
19
 
#include "mir/compositor/compositing_criteria.h"
 
18
#include "mir/compositor/gl_renderer.h"
20
19
#include "mir/compositor/buffer_stream.h"
 
20
#include "mir/graphics/renderable.h"
21
21
#include "mir/graphics/buffer.h"
22
22
 
 
23
#define GLM_FORCE_RADIANS
23
24
#include <glm/gtc/matrix_transform.hpp>
24
25
#include <glm/gtc/type_ptr.hpp>
25
26
 
42
43
    "uniform mat4 screen_to_gl_coords;\n"
43
44
    "uniform mat4 display_transform;\n"
44
45
    "uniform mat4 transform;\n"
 
46
    "uniform vec2 centre;\n"
45
47
    "varying vec2 v_texcoord;\n"
46
48
    "void main() {\n"
47
 
    "   gl_Position = display_transform * screen_to_gl_coords * transform * vec4(position, 1.0);\n"
 
49
    "   vec4 mid = vec4(centre, 0.0, 0.0);\n"
 
50
    "   vec4 transformed = (transform * (vec4(position, 1.0) - mid)) + mid;\n"
 
51
    "   transformed.z = 0.0;\n" // avoid clipping while we lack depth/perspective
 
52
    "   gl_Position = display_transform * screen_to_gl_coords * transformed;\n"
48
53
    "   v_texcoord = texcoord;\n"
49
54
    "}\n"
50
55
};
61
66
    "}\n"
62
67
};
63
68
 
64
 
struct VertexAttributes
65
 
{
66
 
    glm::vec3 position;
67
 
    glm::vec2 texcoord;
68
 
};
69
 
 
70
 
/*
71
 
 * The texture coordinates are y-inverted to account for the difference in the
72
 
 * texture and renderable pixel data row order. In particular, GL textures
73
 
 * expect pixel data in rows starting from the bottom and moving up the image,
74
 
 * whereas our renderables provide data in rows starting from the top and
75
 
 * moving down the image.
76
 
 */
77
 
VertexAttributes vertex_attribs[4] =
78
 
{
79
 
    {
80
 
        glm::vec3{-0.5f, -0.5f, 0.0f},
81
 
        glm::vec2{0.0f, 0.0f}
82
 
    },
83
 
    {
84
 
        glm::vec3{-0.5f, 0.5f, 0.0f},
85
 
        glm::vec2{0.0f, 1.0f},
86
 
    },
87
 
    {
88
 
        glm::vec3{0.5f, -0.5f, 0.0f},
89
 
        glm::vec2{1.0f, 0.0f},
90
 
    },
91
 
    {
92
 
        glm::vec3{0.5f, 0.5f, 0.0f},
93
 
        glm::vec2{1.0f, 1.0f}
94
 
    }
95
 
};
96
 
 
97
69
typedef void(*MirGLGetObjectInfoLog)(GLuint, GLsizei, GLsizei *, GLchar *);
98
70
typedef void(*MirGLGetObjectiv)(GLuint, GLenum, GLint *);
99
71
 
126
98
    program(0),
127
99
    position_attr_loc(0),
128
100
    texcoord_attr_loc(0),
 
101
    centre_uniform_loc(0),
129
102
    transform_uniform_loc(0),
130
103
    alpha_uniform_loc(0),
131
 
    vertex_attribs_vbo(0),
132
104
    rotation(NAN) // ensure the first set_rotation succeeds
133
105
{
134
106
    /*
189
161
    alpha_uniform_loc = glGetUniformLocation(program, "alpha");
190
162
    position_attr_loc = glGetAttribLocation(program, "position");
191
163
    texcoord_attr_loc = glGetAttribLocation(program, "texcoord");
 
164
    centre_uniform_loc = glGetUniformLocation(program, "centre");
192
165
 
193
166
    glUniform1i(tex_loc, 0);
194
167
 
195
 
    /* Create VBO */
196
 
    glGenBuffers(1, &vertex_attribs_vbo);
197
 
 
198
 
    glBindBuffer(GL_ARRAY_BUFFER, vertex_attribs_vbo);
199
 
    glBufferData(GL_ARRAY_BUFFER, sizeof(vertex_attribs),
200
 
            glm::value_ptr(vertex_attribs[0].position), GL_STATIC_DRAW);
201
 
 
202
168
    glBindBuffer(GL_ARRAY_BUFFER, 0);
203
169
    glUseProgram(0);
204
170
 
214
180
        glDeleteShader(fragment_shader);
215
181
    if (program)
216
182
        glDeleteProgram(program);
217
 
    if (vertex_attribs_vbo)
218
 
        glDeleteBuffers(1, &vertex_attribs_vbo);
219
183
    for (auto& t : textures)
220
184
        glDeleteTextures(1, &t.second.id);
221
185
}
222
186
 
223
 
void mc::GLRenderer::render(CompositingCriteria const& criteria, mg::Buffer& buffer) const
 
187
GLenum mc::GLRenderer::tessellate(graphics::Renderable const& renderable,
 
188
                                  std::vector<Vertex>& vertices) const
 
189
{
 
190
    auto const& rect = renderable.screen_position();
 
191
    GLfloat left = rect.top_left.x.as_int();
 
192
    GLfloat right = left + rect.size.width.as_int();
 
193
    GLfloat top = rect.top_left.y.as_int();
 
194
    GLfloat bottom = top + rect.size.height.as_int();
 
195
 
 
196
    vertices.resize(4);
 
197
    vertices[0] = {{left,  top,    0.0f}, {0.0f, 0.0f}};
 
198
    vertices[1] = {{left,  bottom, 0.0f}, {0.0f, 1.0f}};
 
199
    vertices[2] = {{right, top,    0.0f}, {1.0f, 0.0f}};
 
200
    vertices[3] = {{right, bottom, 0.0f}, {1.0f, 1.0f}};
 
201
    return GL_TRIANGLE_STRIP;
 
202
}
 
203
 
 
204
void mc::GLRenderer::render(mg::Renderable const& renderable, mg::Buffer& buffer) const
224
205
{
225
206
    glUseProgram(program);
226
207
 
227
 
    if (criteria.shaped() || criteria.alpha() < 1.0f)
 
208
    if (renderable.shaped() || renderable.alpha() < 1.0f)
228
209
    {
229
210
        glEnable(GL_BLEND);
230
211
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
235
216
    }
236
217
    glActiveTexture(GL_TEXTURE0);
237
218
 
 
219
    auto const& rect = renderable.screen_position();
 
220
    GLfloat centrex = rect.top_left.x.as_int() +
 
221
                      rect.size.width.as_int() / 2.0f;
 
222
    GLfloat centrey = rect.top_left.y.as_int() +
 
223
                      rect.size.height.as_int() / 2.0f;
 
224
    glUniform2f(centre_uniform_loc, centrex, centrey);
 
225
 
238
226
    glUniformMatrix4fv(transform_uniform_loc, 1, GL_FALSE,
239
 
                       glm::value_ptr(criteria.transformation()));
240
 
    glUniform1f(alpha_uniform_loc, criteria.alpha());
 
227
                       glm::value_ptr(renderable.transformation()));
 
228
    glUniform1f(alpha_uniform_loc, renderable.alpha());
241
229
 
242
 
    /* Set up vertex attribute data */
243
 
    glBindBuffer(GL_ARRAY_BUFFER, vertex_attribs_vbo);
 
230
    std::vector<Vertex> vertices;
 
231
    GLenum draw_mode = tessellate(renderable, vertices);
 
232
   
244
233
    glVertexAttribPointer(position_attr_loc, 3, GL_FLOAT,
245
 
                          GL_FALSE, sizeof(VertexAttributes), 0);
 
234
                          GL_FALSE, sizeof(Vertex), &vertices[0].position);
246
235
    glVertexAttribPointer(texcoord_attr_loc, 2, GL_FLOAT,
247
 
                          GL_FALSE, sizeof(VertexAttributes),
248
 
                          reinterpret_cast<void*>(sizeof(glm::vec3)));
 
236
                          GL_FALSE, sizeof(Vertex), &vertices[0].texcoord);
249
237
 
250
 
    SurfaceID surf = &criteria; // temporary hack till we rearrange classes
 
238
    SurfaceID surf = &renderable; // TODO: Add an id() to Renderable
251
239
    auto& tex = textures[surf];
252
240
    bool changed = true;
253
241
    auto const& buf_id = buffer.id();
273
261
    /* Draw */
274
262
    glEnableVertexAttribArray(position_attr_loc);
275
263
    glEnableVertexAttribArray(texcoord_attr_loc);
276
 
    glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
 
264
    glDrawArrays(draw_mode, 0, vertices.size());
277
265
    glDisableVertexAttribArray(texcoord_attr_loc);
278
266
    glDisableVertexAttribArray(position_attr_loc);
279
267
}