• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2021 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 
8 #include "experimental/graphite/src/geom/Transform_graphite.h"
9 
10 #include "experimental/graphite/src/geom/Rect.h"
11 #include "src/core/SkMatrixPriv.h"
12 
13 namespace skgpu {
14 
15 namespace {
16 
map_rect(const SkM44 & m,const Rect & r)17 Rect map_rect(const SkM44& m, const Rect& r) {
18     // TODO: Can Rect's (l,t,-r,-b) structure be used to optimize mapRect?
19     // TODO: Can take this opportunity to implement 100% accurate perspective plane clipping since
20     //       it doesn't have to match raster/ganesh rendering behavior.
21     return SkMatrixPriv::MapRect(m, r.asSkRect());
22 }
23 
24 } // anonymous namespace
25 
Transform(const SkM44 & m)26 Transform::Transform(const SkM44& m)
27         : fM(m) {
28     if (fM.invert(&fInvM)) {
29         // TODO: actually detect these
30         fType = (fM == SkM44()) ? Type::kIdentity : Type::kPerspective;
31         fScale = {1.f, 1.f};
32     } else {
33         fType = Type::kInvalid;
34         fInvM = SkM44();
35         fScale = {1.f, 1.f};
36     }
37 }
38 
operator ==(const Transform & t) const39 bool Transform::operator==(const Transform& t) const {
40     // Checking fM should be sufficient as all other values are computed from it.
41     SkASSERT(fM != t.fM || (fInvM == t.fInvM && fType == t.fType && fScale == t.fScale));
42     return fM == t.fM;
43 }
44 
mapRect(const Rect & rect) const45 Rect Transform::mapRect(const Rect& rect) const { return map_rect(fM, rect); }
inverseMapRect(const Rect & rect) const46 Rect Transform::inverseMapRect(const Rect& rect) const { return map_rect(fInvM, rect); }
47 
48 } // namespace skgpu
49