blob: 14130f831c3f5fb185335cc8476e42627253f6c2 [file] [log] [blame]
reed@google.comac10a2d2010-12-22 21:39:39 +00001/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00002 * Copyright 2010 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.
reed@google.comac10a2d2010-12-22 21:39:39 +00006 */
7
reed@google.comac10a2d2010-12-22 21:39:39 +00008#ifndef GrRect_DEFINED
9#define GrRect_DEFINED
10
commit-bot@chromium.orgfd03d4a2013-07-17 21:39:42 +000011#include "SkTypes.h"
reed@google.com20efde72011-05-09 17:00:02 +000012#include "SkRect.h"
reed@google.comac10a2d2010-12-22 21:39:39 +000013
reed@google.comac10a2d2010-12-22 21:39:39 +000014struct GrIRect16 {
15 int16_t fLeft, fTop, fRight, fBottom;
rmistry@google.comfbfcd562012-08-23 18:09:54 +000016
commit-bot@chromium.org2f569982014-04-10 18:36:19 +000017 static GrIRect16 SK_WARN_UNUSED_RESULT MakeEmpty() {
18 GrIRect16 r;
19 r.setEmpty();
20 return r;
21 }
22
robertphillips952841b2014-06-30 08:26:50 -070023 static GrIRect16 SK_WARN_UNUSED_RESULT MakeWH(int16_t w, int16_t h) {
24 GrIRect16 r;
25 r.set(0, 0, w, h);
26 return r;
27 }
28
29 static GrIRect16 SK_WARN_UNUSED_RESULT MakeXYWH(int16_t x, int16_t y, int16_t w, int16_t h) {
30 GrIRect16 r;
31 r.set(x, y, x + w, y + h);
32 return r;
33 }
34
reed@google.comac10a2d2010-12-22 21:39:39 +000035 int width() const { return fRight - fLeft; }
36 int height() const { return fBottom - fTop; }
37 int area() const { return this->width() * this->height(); }
38 bool isEmpty() const { return fLeft >= fRight || fTop >= fBottom; }
rmistry@google.comfbfcd562012-08-23 18:09:54 +000039
commit-bot@chromium.org2f569982014-04-10 18:36:19 +000040 void setEmpty() { memset(this, 0, sizeof(*this)); }
41
robertphillips952841b2014-06-30 08:26:50 -070042 void set(int16_t left, int16_t top, int16_t right, int16_t bottom) {
43 fLeft = left;
44 fTop = top;
45 fRight = right;
46 fBottom = bottom;
47 }
48
commit-bot@chromium.orgfd03d4a2013-07-17 21:39:42 +000049 void set(const SkIRect& r) {
reed@google.com20efde72011-05-09 17:00:02 +000050 fLeft = SkToS16(r.fLeft);
51 fTop = SkToS16(r.fTop);
52 fRight = SkToS16(r.fRight);
53 fBottom = SkToS16(r.fBottom);
bsalomon@google.comd302f142011-03-03 13:54:13 +000054 }
reed@google.comac10a2d2010-12-22 21:39:39 +000055};
56
57#endif