Mir
draw_pattern_checkered-inl.h
Go to the documentation of this file.
1 /*
2  * Copyright © 2012-2014 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 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: Kevin DuBois <kevin.dubois@canonical.com>
17  */
18 
19 #include "mir_toolkit/common.h"
20 
21 template<size_t Rows, size_t Cols>
23 {
24  for (size_t i=0; i<Rows; i++)
25  std::memcpy(color_pattern[i], pattern[i], sizeof(uint32_t) * Cols);
26 }
27 
28 template<size_t Rows, size_t Cols>
30 {
32  throw(std::runtime_error("cannot draw region, incorrect format"));
33 
35  for(int i=0; i < region.width; i++)
36  {
37  for(int j=0; j<region.height; j++)
38  {
39  int key_row = i % Rows;
40  int key_col = j % Cols;
41  uint32_t *pixel = reinterpret_cast<uint32_t*>(&region.vaddr[j*region.stride + (i * bpp)]);
42  *pixel = color_pattern[key_row][key_col];
43  }
44  }
45 }
46 
47 template<size_t Rows, size_t Cols>
49 {
51  throw(std::runtime_error("cannot check region, incorrect format"));
52 
54  for(int i=0; i< region.width; i++)
55  {
56  for(int j=0; j<region.height; j++)
57  {
58  int key_row = i % Rows;
59  int key_col = j % Cols;
60  uint32_t *pixel = reinterpret_cast<uint32_t*>(&region.vaddr[j*region.stride + (i * bpp)]);
61  if ( *pixel != color_pattern[key_row][key_col] )
62  {
63  return false;
64  }
65  }
66  }
67 
68  return true;
69 }
#define MIR_BYTES_PER_PIXEL(f)
Definition: common.h:156
int stride
Definition: client_types.h:240
int height
Definition: client_types.h:239
MirPixelFormat pixel_format
Definition: client_types.h:241
char * vaddr
Definition: client_types.h:242
Definition: patterns.h:60
Definition: common.h:137
Retrieved information about a MirSurface.
Definition: client_types.h:236
int width
Definition: client_types.h:238

Copyright © 2012-2015 Canonical Ltd.
Generated on Thu Sep 8 14:50:19 UTC 2016