~gerboland/qtmir/small-hooks-change

« back to all changes in this revision

Viewing changes to src/modules/Unity/Application/mirbuffersgtexture.cpp

  • Committer: Bileto Bot
  • Author(s): Alan Griffiths
  • Date: 2017-03-20 21:14:51 UTC
  • mfrom: (606.3.13 qtmir)
  • Revision ID: ci-train-bot@canonical.com-20170320211451-qj7mygvtyjhoc1pc
Reduce dependencies on mirserver by reworking ../Application/mirbuffersgtexture.cpp and ../Application/surfacemanager.cpp

Approved by: Gerry Boland, Unity8 CI Bot

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
#include "mirbuffersgtexture.h"
18
18
 
19
19
// Mir
20
 
#include <mir/graphics/buffer.h>
21
20
#include <mir/geometry/size.h>
22
 
#include <mir/renderer/gl/texture_source.h>
23
21
 
24
22
namespace mg = mir::geometry;
25
 
namespace mrg = mir::renderer::gl;
26
23
 
27
24
MirBufferSGTexture::MirBufferSGTexture()
28
25
    : QSGTexture()
53
50
 
54
51
void MirBufferSGTexture::setBuffer(const std::shared_ptr<mir::graphics::Buffer>& buffer)
55
52
{
56
 
    m_mirBuffer = buffer;
57
 
    mg::Size size = buffer->size();
 
53
    m_mirBuffer.reset(buffer);
 
54
    mg::Size size = m_mirBuffer.size();
58
55
    m_height = size.height.as_int();
59
56
    m_width = size.width.as_int();
60
57
}
61
58
 
62
59
bool MirBufferSGTexture::hasBuffer() const
63
60
{
64
 
    return !!m_mirBuffer;
 
61
    return m_mirBuffer;
65
62
}
66
63
 
67
64
int MirBufferSGTexture::textureId() const
76
73
 
77
74
bool MirBufferSGTexture::hasAlphaChannel() const
78
75
{
79
 
    if (hasBuffer()) {
80
 
        return m_mirBuffer->pixel_format() == mir_pixel_format_abgr_8888
81
 
            || m_mirBuffer->pixel_format() == mir_pixel_format_argb_8888;
82
 
    } else {
83
 
        return false;
84
 
    }
 
76
    return m_mirBuffer.has_alpha_channel();
85
77
}
86
78
 
87
79
void MirBufferSGTexture::bind()
90
82
    glBindTexture(GL_TEXTURE_2D, m_textureId);
91
83
    updateBindOptions(true/* force */);
92
84
 
93
 
    auto const texture_source =
94
 
        dynamic_cast<mrg::TextureSource*>(m_mirBuffer->native_buffer_base());
95
 
    if (!texture_source)
96
 
        throw std::logic_error("Buffer does not support GL rendering");
97
 
 
98
 
    texture_source->gl_bind_to_texture();
 
85
    m_mirBuffer.bind_to_texture();
99
86
 
100
87
    // Fix for lp:1583088 - For non-GL clients, Mir uploads the client pixel buffer to a GL texture.
101
88
    // But as it does so, it changes some GL state and neglects to restore it, which breaks Qt's rendering.