~alan-griffiths/mir/migrate-tests-to-miral

« back to all changes in this revision

Viewing changes to playground/demo-shell/typo/typo_renderer.cpp

  • Committer: Christopher James Halse Rogers
  • Date: 2017-09-07 05:58:13 UTC
  • mfrom: (4242 development-branch)
  • mto: (4243.1.1 mir3)
  • mto: This revision was merged to the branch mainline in revision 4244.
  • Revision ID: christopher.halse.rogers@canonical.com-20170907055813-4qsg25nirybc8jj3
Merge trunk, resolving conflict

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright © 2015 Canonical Ltd.
3
 
 *
4
 
 * This program is free software: you can redistribute it and/or modify
5
 
 * it under the terms of the GNU General Public License version 2 or 3 as
6
 
 * published by the Free Software Foundation.
7
 
 *
8
 
 * This program is distributed in the hope that it will be useful,
9
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
 
 * GNU General Public License for more details.
12
 
 *
13
 
 * You should have received a copy of the GNU General Public License
14
 
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
15
 
 *
16
 
 * Authored by: Daniel van Vugt <daniel.van.vugt@canonical.com>
17
 
 */
18
 
 
19
 
#include "typo_renderer.h"
20
 
#include <cstring>
21
 
 
22
 
using namespace mir::typo;
23
 
 
24
 
Renderer::Image::Image()
25
 
    : buf(nullptr), width_(0), stride_(0), height_(0), align_(4),
26
 
      format_(alpha8)
27
 
{
28
 
}
29
 
 
30
 
Renderer::Image::~Image()
31
 
{
32
 
    delete[] buf;
33
 
}
34
 
 
35
 
void Renderer::Image::reserve(int w, int h, Format f)
36
 
{
37
 
    width_ = w;
38
 
    height_ = h;
39
 
    format_ = f;
40
 
    int const bpp = 1;  // format is always alpha8
41
 
    stride_ = (((width_ * bpp) + align_ - 1) / align_) * align_;
42
 
    delete[] buf;
43
 
    auto size = stride_ * height_;
44
 
    buf = new unsigned char[size];
45
 
    memset(buf, 0, size);
46
 
}
47
 
 
48
 
Renderer::~Renderer()
49
 
{
50
 
}
51
 
 
52
 
unsigned long Renderer::unicode_from_utf8(char const** utf8)
53
 
{
54
 
    int char_len = 1; // TODO: Add support for non-ASCII UTF-8
55
 
    unsigned long unicode = **utf8;
56
 
    if (unicode)
57
 
        *utf8 += char_len;
58
 
    return unicode;
59
 
}