1// Copyright 2006 The Android Open Source Project
2// Copyright 2020 Yevhenii Reizner
3//
4// Use of this source code is governed by a BSD-style license that can be
5// found in the LICENSE file.
6
7use crate::geom::ScreenIntRect;
8
9use crate::alpha_runs::AlphaRun;
10use crate::color::AlphaU8;
11use crate::LengthU32;
12
13/// Mask is used to describe alpha bitmaps.
14pub struct Mask {
15 pub image: [u8; 2],
16 pub bounds: ScreenIntRect,
17 pub row_bytes: u32,
18}
19
20/// Blitter is responsible for actually writing pixels into memory.
21///
22/// Besides efficiency, they handle clipping and antialiasing.
23/// An object that implements Blitter contains all the context needed to generate pixels
24/// for the destination and how src/generated pixels map to the destination.
25/// The coordinates passed to the `blit_*` calls are in destination pixel space.
26pub trait Blitter {
27 /// Blits a horizontal run of one or more pixels.
28 fn blit_h(&mut self, _x: u32, _y: u32, _width: LengthU32) {
29 unreachable!()
30 }
31
32 /// Blits a horizontal run of antialiased pixels.
33 ///
34 /// runs[] is a *sparse* zero-terminated run-length encoding of spans of constant alpha values.
35 ///
36 /// The runs[] and antialias[] work together to represent long runs of pixels with the same
37 /// alphas. The runs[] contains the number of pixels with the same alpha, and antialias[]
38 /// contain the coverage value for that number of pixels. The runs[] (and antialias[]) are
39 /// encoded in a clever way. The runs array is zero terminated, and has enough entries for
40 /// each pixel plus one, in most cases some of the entries will not contain valid data. An entry
41 /// in the runs array contains the number of pixels (np) that have the same alpha value. The
42 /// next np value is found np entries away. For example, if runs[0] = 7, then the next valid
43 /// entry will by at runs[7]. The runs array and antialias[] are coupled by index. So, if the
44 /// np entry is at runs[45] = 12 then the alpha value can be found at antialias[45] = 0x88.
45 /// This would mean to use an alpha value of 0x88 for the next 12 pixels starting at pixel 45.
46 fn blit_anti_h(
47 &mut self,
48 _x: u32,
49 _y: u32,
50 _antialias: &mut [AlphaU8],
51 _runs: &mut [AlphaRun],
52 ) {
53 unreachable!()
54 }
55
56 /// Blits a vertical run of pixels with a constant alpha value.
57 fn blit_v(&mut self, _x: u32, _y: u32, _height: LengthU32, _alpha: AlphaU8) {
58 unreachable!()
59 }
60
61 fn blit_anti_h2(&mut self, _x: u32, _y: u32, _alpha0: AlphaU8, _alpha1: AlphaU8) {
62 unreachable!()
63 }
64
65 fn blit_anti_v2(&mut self, _x: u32, _y: u32, _alpha0: AlphaU8, _alpha1: AlphaU8) {
66 unreachable!()
67 }
68
69 /// Blits a solid rectangle one or more pixels wide.
70 fn blit_rect(&mut self, _rect: &ScreenIntRect) {
71 unreachable!()
72 }
73
74 /// Blits a pattern of pixels defined by a rectangle-clipped mask.
75 fn blit_mask(&mut self, _mask: &Mask, _clip: &ScreenIntRect) {
76 unreachable!()
77 }
78}
79