Mir

Merge lp:~vanvugt/mir/safer-typo-image into lp:mir

Proposed by Daniel van Vugt
Status: Merged
Approved by: Daniel van Vugt
Approved revision: no longer in the source branch.
Merged at revision: 3754
Proposed branch: lp:~vanvugt/mir/safer-typo-image
Merge into: lp:mir
Diff against target: 145 lines (+35/-20)
5 files modified
playground/demo-shell/typo/typo_freetype_renderer.cpp (+3/-3)
playground/demo-shell/typo/typo_glcache.cpp (+6/-6)
playground/demo-shell/typo/typo_renderer.cpp (+7/-6)
playground/demo-shell/typo/typo_renderer.h (+17/-3)
playground/demo-shell/typo/typo_stub_renderer.cpp (+2/-2)
To merge this branch: bzr merge lp:~vanvugt/mir/safer-typo-image
Reviewer Review Type Date Requested Status
Mir CI Bot continuous-integration Approve
Alan Griffiths Approve
Review via email: mp+308020@code.launchpad.net

Commit message

Make typo::Renderer::Image safer

To post a comment you must log in.
Revision history for this message
Mir CI Bot (mir-ci-bot) wrote :

PASSED: Continuous integration, rev:3746
https://mir-jenkins.ubuntu.com/job/mir-ci/1931/
Executed test runs:
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-mir/2448
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-0-fetch/2511
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=vivid+overlay/2503
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=xenial+overlay/2503
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=yakkety/2503
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=clang,platform=mesa,release=yakkety/2477
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=clang,platform=mesa,release=yakkety/2477/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=xenial+overlay/2477
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=xenial+overlay/2477/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=yakkety/2477
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=yakkety/2477/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=cross-armhf,compiler=gcc,platform=android,release=vivid+overlay/2477
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=cross-armhf,compiler=gcc,platform=android,release=vivid+overlay/2477/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=android,release=vivid+overlay/2477
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=android,release=vivid+overlay/2477/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=mesa,release=xenial+overlay/2477
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=mesa,release=xenial+overlay/2477/artifact/output/*zip*/output.zip

Click here to trigger a rebuild:
https://mir-jenkins.ubuntu.com/job/mir-ci/1931/rebuild

review: Approve (continuous-integration)
Revision history for this message
Alan Griffiths (alan-griffiths) wrote :

Well, the interface is still easy to use wrongly & hard to use right, but I guess this is a marginal improvement.

review: Approve
Revision history for this message
Mir CI Bot (mir-ci-bot) wrote :

FAILED: Autolanding.
More details in the following jenkins job:
https://mir-jenkins.ubuntu.com/job/mir-autolanding/672/
Executed test runs:
    FAILURE: https://mir-jenkins.ubuntu.com/job/build-mir/2463/console
    None: https://mir-jenkins.ubuntu.com/job/generic-land-mp/713/console
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-0-fetch/2526
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=vivid+overlay/2518
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=xenial+overlay/2518
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=yakkety/2518
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=clang,platform=mesa,release=yakkety/2492
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=clang,platform=mesa,release=yakkety/2492/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=xenial+overlay/2492
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=xenial+overlay/2492/artifact/output/*zip*/output.zip
    FAILURE: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=yakkety/2492/console
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=cross-armhf,compiler=gcc,platform=android,release=vivid+overlay/2492
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=cross-armhf,compiler=gcc,platform=android,release=vivid+overlay/2492/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=android,release=vivid+overlay/2492
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=android,release=vivid+overlay/2492/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=mesa,release=xenial+overlay/2492
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=mesa,release=xenial+overlay/2492/artifact/output/*zip*/output.zip

review: Needs Fixing (continuous-integration)
Revision history for this message
Daniel van Vugt (vanvugt) wrote :
Revision history for this message
Mir CI Bot (mir-ci-bot) :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'playground/demo-shell/typo/typo_freetype_renderer.cpp'
2--- playground/demo-shell/typo/typo_freetype_renderer.cpp 2015-02-27 03:22:32 +0000
3+++ playground/demo-shell/typo/typo_freetype_renderer.cpp 2016-10-10 06:06:06 +0000
4@@ -105,17 +105,17 @@
5 int right = x + bitmap.width;
6 int bottom = y + bitmap.rows;
7
8- if (x >= 0 && right <= img.width && y >= 0 && bottom <= img.height)
9+ if (x >= 0 && right <= width && y >= 0 && bottom <= height)
10 {
11 unsigned char* src = bitmap.buffer;
12- unsigned char* dest = img.buf + y*img.stride + x;
13+ unsigned char* dest = img.data() + y*img.stride() + x;
14
15 int ylimit = y + bitmap.rows;
16 for (; y < ylimit; ++y)
17 {
18 memcpy(dest, src, bitmap.width);
19 src += bitmap.pitch;
20- dest += img.stride;
21+ dest += img.stride();
22 }
23 }
24
25
26=== modified file 'playground/demo-shell/typo/typo_glcache.cpp'
27--- playground/demo-shell/typo/typo_glcache.cpp 2016-05-13 08:03:23 +0000
28+++ playground/demo-shell/typo/typo_glcache.cpp 2016-10-10 06:06:06 +0000
29@@ -76,10 +76,10 @@
30 {
31 Renderer::Image img;
32 renderer->render(str, img);
33- if (img.buf)
34+ if (img.data())
35 {
36- entry.width = img.width;
37- entry.height = img.height;
38+ entry.width = img.width();
39+ entry.height = img.height();
40 glGenTextures(1, &entry.tex);
41 glBindTexture(GL_TEXTURE_2D, entry.tex);
42 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
43@@ -87,10 +87,10 @@
44 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
45 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
46 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
47- glPixelStorei(GL_UNPACK_ALIGNMENT, img.align);
48+ glPixelStorei(GL_UNPACK_ALIGNMENT, img.alignment());
49 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA,
50- img.width, img.height, 0, GL_ALPHA,
51- GL_UNSIGNED_BYTE, img.buf);
52+ img.width(), img.height(), 0, GL_ALPHA,
53+ GL_UNSIGNED_BYTE, img.data());
54 glGenerateMipmap(GL_TEXTURE_2D); // Antialiasing shrinkage please
55 }
56 }
57
58=== modified file 'playground/demo-shell/typo/typo_renderer.cpp'
59--- playground/demo-shell/typo/typo_renderer.cpp 2015-02-19 09:30:02 +0000
60+++ playground/demo-shell/typo/typo_renderer.cpp 2016-10-10 06:06:06 +0000
61@@ -22,7 +22,8 @@
62 using namespace mir::examples::typo;
63
64 Renderer::Image::Image()
65- : buf(nullptr), width(0), stride(0), height(0), align(4), format(alpha8)
66+ : buf(nullptr), width_(0), stride_(0), height_(0), align_(4),
67+ format_(alpha8)
68 {
69 }
70
71@@ -33,13 +34,13 @@
72
73 void Renderer::Image::reserve(int w, int h, Format f)
74 {
75- width = w;
76- height = h;
77- format = f;
78+ width_ = w;
79+ height_ = h;
80+ format_ = f;
81 int const bpp = 1; // format is always alpha8
82- stride = (((width * bpp) + align - 1) / align) * align;
83+ stride_ = (((width_ * bpp) + align_ - 1) / align_) * align_;
84 delete[] buf;
85- auto size = stride * height;
86+ auto size = stride_ * height_;
87 buf = new unsigned char[size];
88 memset(buf, 0, size);
89 }
90
91=== modified file 'playground/demo-shell/typo/typo_renderer.h'
92--- playground/demo-shell/typo/typo_renderer.h 2015-02-20 06:24:57 +0000
93+++ playground/demo-shell/typo/typo_renderer.h 2016-10-10 06:06:06 +0000
94@@ -24,15 +24,29 @@
95 class Renderer
96 {
97 public:
98- struct Image
99+ class Image
100 {
101+ public:
102 Image();
103+ Image(Image const&) = delete;
104+ Image(Image const&&) = delete;
105+ Image& operator=(Image const&) = delete;
106 ~Image();
107+
108 typedef enum {alpha8} Format;
109+
110 void reserve(int w, int h, Format f);
111+ unsigned char* data() const { return buf; };
112+ int width() const { return width_; }
113+ int height() const { return height_; }
114+ int stride() const { return stride_; }
115+ int alignment() const { return align_; }
116+ Format format() const { return format_; }
117+
118+ private:
119 unsigned char* buf;
120- int width, stride, height, align;
121- Format format;
122+ int width_, stride_, height_, align_;
123+ Format format_;
124 };
125
126 virtual ~Renderer();
127
128=== modified file 'playground/demo-shell/typo/typo_stub_renderer.cpp'
129--- playground/demo-shell/typo/typo_stub_renderer.cpp 2015-02-19 09:12:04 +0000
130+++ playground/demo-shell/typo/typo_stub_renderer.cpp 2016-10-10 06:06:06 +0000
131@@ -36,12 +36,12 @@
132 char const* s = str;
133 for (int n = 0; unicode_from_utf8(&s); ++n)
134 {
135- unsigned char* row = img.buf + top*img.stride +
136+ unsigned char* row = img.data() + top*img.stride() +
137 n*(char_width+char_space);
138 for (int y = 0; y < char_height; ++y)
139 {
140 memset(row, 255, char_width);
141- row += img.stride;
142+ row += img.stride();
143 }
144 }
145 }

Subscribers

People subscribed via source and target branches