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
=== modified file 'playground/demo-shell/typo/typo_freetype_renderer.cpp'
--- playground/demo-shell/typo/typo_freetype_renderer.cpp 2015-02-27 03:22:32 +0000
+++ playground/demo-shell/typo/typo_freetype_renderer.cpp 2016-10-10 06:06:06 +0000
@@ -105,17 +105,17 @@
105 int right = x + bitmap.width;105 int right = x + bitmap.width;
106 int bottom = y + bitmap.rows;106 int bottom = y + bitmap.rows;
107107
108 if (x >= 0 && right <= img.width && y >= 0 && bottom <= img.height)108 if (x >= 0 && right <= width && y >= 0 && bottom <= height)
109 {109 {
110 unsigned char* src = bitmap.buffer;110 unsigned char* src = bitmap.buffer;
111 unsigned char* dest = img.buf + y*img.stride + x;111 unsigned char* dest = img.data() + y*img.stride() + x;
112112
113 int ylimit = y + bitmap.rows;113 int ylimit = y + bitmap.rows;
114 for (; y < ylimit; ++y)114 for (; y < ylimit; ++y)
115 {115 {
116 memcpy(dest, src, bitmap.width);116 memcpy(dest, src, bitmap.width);
117 src += bitmap.pitch;117 src += bitmap.pitch;
118 dest += img.stride;118 dest += img.stride();
119 }119 }
120 }120 }
121121
122122
=== modified file 'playground/demo-shell/typo/typo_glcache.cpp'
--- playground/demo-shell/typo/typo_glcache.cpp 2016-05-13 08:03:23 +0000
+++ playground/demo-shell/typo/typo_glcache.cpp 2016-10-10 06:06:06 +0000
@@ -76,10 +76,10 @@
76 {76 {
77 Renderer::Image img;77 Renderer::Image img;
78 renderer->render(str, img);78 renderer->render(str, img);
79 if (img.buf)79 if (img.data())
80 {80 {
81 entry.width = img.width;81 entry.width = img.width();
82 entry.height = img.height;82 entry.height = img.height();
83 glGenTextures(1, &entry.tex);83 glGenTextures(1, &entry.tex);
84 glBindTexture(GL_TEXTURE_2D, entry.tex);84 glBindTexture(GL_TEXTURE_2D, entry.tex);
85 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,85 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
@@ -87,10 +87,10 @@
87 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);87 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
88 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);88 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
89 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);89 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
90 glPixelStorei(GL_UNPACK_ALIGNMENT, img.align);90 glPixelStorei(GL_UNPACK_ALIGNMENT, img.alignment());
91 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA,91 glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA,
92 img.width, img.height, 0, GL_ALPHA,92 img.width(), img.height(), 0, GL_ALPHA,
93 GL_UNSIGNED_BYTE, img.buf);93 GL_UNSIGNED_BYTE, img.data());
94 glGenerateMipmap(GL_TEXTURE_2D); // Antialiasing shrinkage please94 glGenerateMipmap(GL_TEXTURE_2D); // Antialiasing shrinkage please
95 }95 }
96 }96 }
9797
=== modified file 'playground/demo-shell/typo/typo_renderer.cpp'
--- playground/demo-shell/typo/typo_renderer.cpp 2015-02-19 09:30:02 +0000
+++ playground/demo-shell/typo/typo_renderer.cpp 2016-10-10 06:06:06 +0000
@@ -22,7 +22,8 @@
22using namespace mir::examples::typo;22using namespace mir::examples::typo;
2323
24Renderer::Image::Image()24Renderer::Image::Image()
25 : buf(nullptr), width(0), stride(0), height(0), align(4), format(alpha8)25 : buf(nullptr), width_(0), stride_(0), height_(0), align_(4),
26 format_(alpha8)
26{27{
27}28}
2829
@@ -33,13 +34,13 @@
3334
34void Renderer::Image::reserve(int w, int h, Format f)35void Renderer::Image::reserve(int w, int h, Format f)
35{36{
36 width = w;37 width_ = w;
37 height = h;38 height_ = h;
38 format = f;39 format_ = f;
39 int const bpp = 1; // format is always alpha840 int const bpp = 1; // format is always alpha8
40 stride = (((width * bpp) + align - 1) / align) * align;41 stride_ = (((width_ * bpp) + align_ - 1) / align_) * align_;
41 delete[] buf;42 delete[] buf;
42 auto size = stride * height;43 auto size = stride_ * height_;
43 buf = new unsigned char[size];44 buf = new unsigned char[size];
44 memset(buf, 0, size);45 memset(buf, 0, size);
45}46}
4647
=== modified file 'playground/demo-shell/typo/typo_renderer.h'
--- playground/demo-shell/typo/typo_renderer.h 2015-02-20 06:24:57 +0000
+++ playground/demo-shell/typo/typo_renderer.h 2016-10-10 06:06:06 +0000
@@ -24,15 +24,29 @@
24class Renderer24class Renderer
25{25{
26public:26public:
27 struct Image27 class Image
28 {28 {
29 public:
29 Image();30 Image();
31 Image(Image const&) = delete;
32 Image(Image const&&) = delete;
33 Image& operator=(Image const&) = delete;
30 ~Image();34 ~Image();
35
31 typedef enum {alpha8} Format;36 typedef enum {alpha8} Format;
37
32 void reserve(int w, int h, Format f);38 void reserve(int w, int h, Format f);
39 unsigned char* data() const { return buf; };
40 int width() const { return width_; }
41 int height() const { return height_; }
42 int stride() const { return stride_; }
43 int alignment() const { return align_; }
44 Format format() const { return format_; }
45
46 private:
33 unsigned char* buf;47 unsigned char* buf;
34 int width, stride, height, align;48 int width_, stride_, height_, align_;
35 Format format;49 Format format_;
36 };50 };
3751
38 virtual ~Renderer();52 virtual ~Renderer();
3953
=== modified file 'playground/demo-shell/typo/typo_stub_renderer.cpp'
--- playground/demo-shell/typo/typo_stub_renderer.cpp 2015-02-19 09:12:04 +0000
+++ playground/demo-shell/typo/typo_stub_renderer.cpp 2016-10-10 06:06:06 +0000
@@ -36,12 +36,12 @@
36 char const* s = str;36 char const* s = str;
37 for (int n = 0; unicode_from_utf8(&s); ++n)37 for (int n = 0; unicode_from_utf8(&s); ++n)
38 {38 {
39 unsigned char* row = img.buf + top*img.stride +39 unsigned char* row = img.data() + top*img.stride() +
40 n*(char_width+char_space);40 n*(char_width+char_space);
41 for (int y = 0; y < char_height; ++y)41 for (int y = 0; y < char_height; ++y)
42 {42 {
43 memset(row, 255, char_width);43 memset(row, 255, char_width);
44 row += img.stride;44 row += img.stride();
45 }45 }
46 }46 }
47}47}

Subscribers

People subscribed via source and target branches