Flutter Engine
The Flutter Engine
SkWritePixelsRec.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2023 Google LLC
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
9
10#include "include/core/SkRect.h"
11
12bool SkWritePixelsRec::trim(int dstWidth, int dstHeight) {
13 if (nullptr == fPixels || fRowBytes < fInfo.minRowBytes()) {
14 return false;
15 }
16 if (0 >= fInfo.width() || 0 >= fInfo.height()) {
17 return false;
18 }
19
20 int x = fX;
21 int y = fY;
23 if (!dstR.intersect({0, 0, dstWidth, dstHeight})) {
24 return false;
25 }
26
27 // if x or y are negative, then we have to adjust pixels
28 if (x > 0) {
29 x = 0;
30 }
31 if (y > 0) {
32 y = 0;
33 }
34 // here x,y are either 0 or negative
35 // we negate and add them so UBSAN (pointer-overflow) doesn't get confused.
36 fPixels = ((const char*)fPixels + -y*fRowBytes + -x*fInfo.bytesPerPixel());
37 // the intersect may have shrunk info's logical size
39 fX = dstR.x();
40 fY = dstR.y();
41
42 return true;
43}
double y
double x
Definition: SkRect.h:32
constexpr int32_t x() const
Definition: SkRect.h:141
constexpr int32_t y() const
Definition: SkRect.h:148
bool intersect(const SkIRect &r)
Definition: SkRect.h:513
constexpr SkISize size() const
Definition: SkRect.h:172
static constexpr SkIRect MakeXYWH(int32_t x, int32_t y, int32_t w, int32_t h)
Definition: SkRect.h:104
size_t minRowBytes() const
Definition: SkImageInfo.h:517
SkImageInfo makeDimensions(SkISize newSize) const
Definition: SkImageInfo.h:454
int bytesPerPixel() const
Definition: SkImageInfo.h:492
int width() const
Definition: SkImageInfo.h:365
int height() const
Definition: SkImageInfo.h:371
bool trim(int dstWidth, int dstHeight)
const void * fPixels