~ubuntu-branches/ubuntu/utopic/mir/utopic-proposed

« back to all changes in this revision

Viewing changes to src/platform/graphics/android/hwc_layerlist.cpp

  • Committer: Package Import Robot
  • Author(s): Ubuntu daily release
  • Date: 2014-03-10 19:28:46 UTC
  • mto: This revision was merged to the branch mainline in revision 63.
  • Revision ID: package-import@ubuntu.com-20140310192846-rq9qm3ec26yrelo2
Tags: upstream-0.1.6+14.04.20140310
ImportĀ upstreamĀ versionĀ 0.1.6+14.04.20140310

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 * Authored by: Kevin DuBois <kevin.dubois@canonical.com>
17
17
 */
18
18
 
 
19
#include "mir/graphics/renderable.h"
 
20
#include "mir/graphics/buffer.h"
19
21
#include "mir/graphics/android/sync_fence.h"
20
22
#include "mir/graphics/android/native_buffer.h"
21
23
#include "hwc_layerlist.h"
26
28
namespace mga=mir::graphics::android;
27
29
namespace geom=mir::geometry;
28
30
 
29
 
mga::LayerList::LayerList(std::initializer_list<HWCLayer> const& layer_list)
30
 
{
31
 
    auto struct_size = sizeof(hwc_display_contents_1_t) + sizeof(hwc_layer_1_t)*(layer_list.size());
32
 
    hwc_representation = std::shared_ptr<hwc_display_contents_1_t>(
 
31
namespace
 
32
{
 
33
std::shared_ptr<hwc_display_contents_1_t> generate_hwc_list(size_t needed_size)
 
34
{
 
35
    /* hwc layer list uses hwLayers[0] at the end of the struct */
 
36
    auto struct_size = sizeof(hwc_display_contents_1_t) + sizeof(hwc_layer_1_t)*(needed_size);
 
37
    auto new_hwc_representation = std::shared_ptr<hwc_display_contents_1_t>(
33
38
        static_cast<hwc_display_contents_1_t*>( ::operator new(struct_size)));
34
39
 
35
 
    auto i = 0u;
36
 
    for(auto& layer : layer_list)
37
 
    {
38
 
        hwc_representation->hwLayers[i++] = layer;
39
 
    }
40
 
    hwc_representation->numHwLayers = layer_list.size();
41
 
    hwc_representation->retireFenceFd = -1;
42
 
    hwc_representation->flags = HWC_GEOMETRY_CHANGED;
 
40
    new_hwc_representation->numHwLayers = needed_size;
 
41
    new_hwc_representation->retireFenceFd = -1;
 
42
    new_hwc_representation->flags = HWC_GEOMETRY_CHANGED;
43
43
 
44
44
    //aosp exynos hwc in particular, checks that these fields are non-null in hwc1.1, although
45
45
    //these fields are deprecated in hwc1.1 and later.
46
 
    hwc_representation->dpy = reinterpret_cast<void*>(0xDECAF);
47
 
    hwc_representation->sur = reinterpret_cast<void*>(0xC0FFEE);
48
 
 
49
 
}
50
 
 
51
 
void mga::LayerList::set_fb_target(std::shared_ptr<NativeBuffer> const& native_buffer)
52
 
{
53
 
    if (hwc_representation->numHwLayers == 2)
54
 
    {
55
 
        if (hwc_representation->hwLayers[0].flags == HWC_SKIP_LAYER)
56
 
        {
57
 
            hwc_representation->hwLayers[0] = mga::ForceGLLayer(*native_buffer);
58
 
        }
59
 
 
60
 
        if (hwc_representation->hwLayers[1].compositionType == HWC_FRAMEBUFFER_TARGET)
61
 
        {
62
 
            hwc_representation->hwLayers[1] = mga::FramebufferLayer(*native_buffer);
63
 
            hwc_representation->hwLayers[1].acquireFenceFd = native_buffer->copy_fence();
64
 
        }
65
 
    }
66
 
}
67
 
 
68
 
mga::NativeFence mga::LayerList::framebuffer_fence()
69
 
{
70
 
    auto fb_position = hwc_representation->numHwLayers - 1;
71
 
    return hwc_representation->hwLayers[fb_position].releaseFenceFd;
72
 
}
73
 
 
74
 
hwc_display_contents_1_t* mga::LayerList::native_list() const
75
 
{
76
 
    return hwc_representation.get();
 
46
    static int fake_egl_values = 0;
 
47
    new_hwc_representation->dpy = &fake_egl_values;
 
48
    new_hwc_representation->sur = &fake_egl_values;
 
49
 
 
50
    return new_hwc_representation;
 
51
}
 
52
}
 
53
 
 
54
void mga::LayerListBase::update_representation(size_t needed_size)
 
55
{
 
56
    std::shared_ptr<hwc_display_contents_1_t> new_hwc_representation;
 
57
    std::list<HWCLayer> new_layers;
 
58
 
 
59
    if (hwc_representation->numHwLayers != needed_size)
 
60
    {
 
61
        new_hwc_representation = generate_hwc_list(needed_size);
 
62
    }
 
63
    else
 
64
    {
 
65
        new_hwc_representation = hwc_representation;
 
66
    }
 
67
 
 
68
    for (auto i = 0u; i < needed_size; i++)
 
69
    {
 
70
        new_layers.emplace_back(mga::HWCLayer(new_hwc_representation, i));
 
71
    }
 
72
 
 
73
    std::swap(new_layers, layers);
 
74
    hwc_representation = new_hwc_representation;
 
75
}
 
76
 
 
77
std::weak_ptr<hwc_display_contents_1_t> mga::LayerListBase::native_list()
 
78
{
 
79
    return hwc_representation;
 
80
}
 
81
 
 
82
mga::NativeFence mga::LayerListBase::retirement_fence()
 
83
{
 
84
    return hwc_representation->retireFenceFd;
 
85
}
 
86
 
 
87
mga::LayerListBase::LayerListBase(size_t initial_list_size)
 
88
    : hwc_representation{generate_hwc_list(initial_list_size)}
 
89
{
 
90
    update_representation(initial_list_size);
 
91
}
 
92
 
 
93
mga::LayerList::LayerList()
 
94
    : LayerListBase{1}
 
95
{
 
96
    layers.back().set_layer_type(mga::LayerType::skip);
 
97
}
 
98
 
 
99
mga::FBTargetLayerList::FBTargetLayerList()
 
100
    : LayerListBase{2}
 
101
{
 
102
    layers.front().set_layer_type(mga::LayerType::skip);
 
103
    layers.back().set_layer_type(mga::LayerType::framebuffer_target);
 
104
}
 
105
 
 
106
void mga::FBTargetLayerList::reset_composition_layers()
 
107
{
 
108
    update_representation(2);
 
109
 
 
110
    layers.front().set_layer_type(mga::LayerType::skip);
 
111
    layers.back().set_layer_type(mga::LayerType::framebuffer_target);
 
112
 
 
113
    skip_layers_present = true;
 
114
}
 
115
 
 
116
void mga::FBTargetLayerList::set_composition_layers(std::list<std::shared_ptr<graphics::Renderable>> const& list)
 
117
{
 
118
    auto const needed_size = list.size() + 1;
 
119
    update_representation(needed_size);
 
120
 
 
121
    auto layers_it = layers.begin();
 
122
    for(auto const& renderable : list)
 
123
    {
 
124
        layers_it->set_layer_type(mga::LayerType::gl_rendered);
 
125
        layers_it->set_render_parameters(renderable->screen_position(), renderable->alpha_enabled());
 
126
        layers_it->set_buffer(*renderable->buffer());
 
127
        layers_it++;
 
128
    }
 
129
 
 
130
    layers_it->set_layer_type(mga::LayerType::framebuffer_target);
 
131
    skip_layers_present = false;
 
132
}
 
133
 
 
134
 
 
135
void mga::FBTargetLayerList::set_fb_target(mg::Buffer const& buffer)
 
136
{
 
137
    geom::Rectangle const disp_frame{{0,0}, {buffer.size()}};
 
138
    if (skip_layers_present)
 
139
    {
 
140
        layers.front().set_render_parameters(disp_frame, false);
 
141
        layers.front().set_buffer(buffer);
 
142
    }
 
143
 
 
144
    layers.back().set_render_parameters(disp_frame, false);
 
145
    layers.back().set_buffer(buffer);
 
146
}
 
147
 
 
148
mga::NativeFence mga::FBTargetLayerList::fb_target_fence()
 
149
{
 
150
   return layers.back().release_fence();
77
151
}