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

« back to all changes in this revision

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

  • Committer: Package Import Robot
  • Author(s): CI Train Bot
  • Date: 2015-05-12 13:12:55 UTC
  • mto: This revision was merged to the branch mainline in revision 96.
  • Revision ID: package-import@ubuntu.com-20150512131255-y7z12i8n4pbvo70x
Tags: upstream-0.13.0+15.10.20150512
ImportĀ upstreamĀ versionĀ 0.13.0+15.10.20150512

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
#include "mir/geometry/size.h"
25
25
#include "mir/graphics/buffer_id.h"
26
26
#include <vector>
 
27
#include <string.h>
27
28
 
28
29
namespace mir
29
30
{
54
55
                  size,
55
56
                  mir_pixel_format_abgr_8888,
56
57
                  graphics::BufferUsage::hardware},
57
 
             geometry::Stride{}}
 
58
                  geometry::Stride{}}
58
59
 
59
60
    {
60
61
    }
65
66
    }
66
67
 
67
68
    StubBuffer(graphics::BufferProperties const& properties)
68
 
        : StubBuffer{create_native_buffer(), properties, geometry::Stride{}}
 
69
        : StubBuffer{create_native_buffer(), properties, geometry::Stride{properties.size.width.as_int() * MIR_BYTES_PER_PIXEL(properties.format)}}
69
70
    {
70
71
    }
71
72
 
100
101
    virtual std::shared_ptr<graphics::NativeBuffer> native_buffer_handle() const override { return native_buffer; }
101
102
    virtual void gl_bind_to_texture() override {}
102
103
 
103
 
    virtual bool can_bypass() const override { return true; }
104
 
    
105
104
    void write(unsigned char const* pixels, size_t len) override
106
105
    {
107
106
        if (pixels) written_pixels.assign(pixels, pixels + len);
108
107
    }
 
108
    void read(std::function<void(unsigned char const*)> const& do_with_pixels) override
 
109
    {
 
110
        if (written_pixels.size() == 0)
 
111
        {
 
112
            auto length = buf_size.width.as_int()*buf_size.height.as_int()*MIR_BYTES_PER_PIXEL(buf_pixel_format);
 
113
            written_pixels.resize(length);
 
114
            memset(written_pixels.data(), 0, length);
 
115
        }
 
116
        do_with_pixels(written_pixels.data());
 
117
    }
109
118
 
110
119
    std::shared_ptr<graphics::NativeBuffer> const native_buffer;
111
120
    geometry::Size const buf_size;