xref: /aosp_15_r20/external/skia/src/core/SkWritePixelsRec.h (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
1 /*
2  * Copyright 2017 Google Inc.
3  *
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  */
7 
8 #ifndef SkWritePixelsRec_DEFINED
9 #define SkWritePixelsRec_DEFINED
10 
11 #include "include/core/SkImageInfo.h"
12 #include "include/core/SkPixmap.h"
13 
14 #include <cstddef>
15 
16 /**
17  *  Helper class to package and trim the parameters passed to writePixels()
18  */
19 struct SkWritePixelsRec {
SkWritePixelsRecSkWritePixelsRec20     SkWritePixelsRec(const SkImageInfo& info, const void* pixels, size_t rowBytes, int x, int y)
21         : fPixels(pixels)
22         , fRowBytes(rowBytes)
23         , fInfo(info)
24         , fX(x)
25         , fY(y)
26     {}
27 
SkWritePixelsRecSkWritePixelsRec28     SkWritePixelsRec(const SkPixmap& pm, int x, int y)
29         : fPixels(pm.addr())
30         , fRowBytes(pm.rowBytes())
31         , fInfo(pm.info())
32         , fX(x)
33         , fY(y)
34     {}
35 
36     const void* fPixels;
37     size_t      fRowBytes;
38     SkImageInfo fInfo;
39     int         fX;
40     int         fY;
41 
42     /*
43      *  On true, may have modified its fields (except fRowBytes) to make it a legal subset
44      *  of the specified dst width/height.
45      *
46      *  On false, leaves self unchanged, but indicates that it does not overlap dst, or
47      *  is not valid (e.g. bad fInfo) for writePixels().
48      */
49     bool trim(int dstWidth, int dstHeight);
50 };
51 
52 #endif
53