diff --git a/.idea/misc.xml b/.idea/misc.xml
index 8279ef6651..fc71b0b47d 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -8,8 +8,13 @@
+
-
+
+
+
+
+
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 7b5a304061..d4205e4d07 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -65,6 +65,7 @@ endif ()
if (MSVC)
add_compile_options("/utf-8")
+ add_compile_options(/w44251 /w44275)
endif (MSVC)
# Sets flags
diff --git a/include/pag/pag.h b/include/pag/pag.h
index 2dc4ab48e6..bd8413a98a 100644
--- a/include/pag/pag.h
+++ b/include/pag/pag.h
@@ -24,11 +24,17 @@
#include "pag/gpu.h"
#include "pag/types.h"
+namespace tgfx {
+struct Rect;
+class Context;
+class Surface;
+class Device;
+class Image;
+} // namespace tgfx
+
namespace pag {
class Recorder;
-class Path;
-
class RenderCache;
class Content {
@@ -36,7 +42,7 @@ class Content {
virtual ~Content() = default;
protected:
- virtual void measureBounds(Rect* bounds) = 0;
+ virtual void measureBounds(tgfx::Rect* bounds) = 0;
virtual void draw(Recorder* recorder) = 0;
@@ -57,8 +63,6 @@ class Content {
friend class PAGTextLayer;
};
-class Image;
-
/**
* A still image used to replace the image contents in a PAGFile.
*/
@@ -135,9 +139,9 @@ class PAG_API PAGImage : public Content {
protected:
PAGImage();
- virtual Rect getContentSize() const = 0;
+ virtual tgfx::Rect getContentSize() const = 0;
- virtual std::shared_ptr getImage() const {
+ virtual std::shared_ptr getImage() const {
return nullptr;
}
@@ -426,7 +430,7 @@ class PAG_API PAGLayer : public Content {
Frame globalToLocalFrame(Frame globalFrame) const;
Point globalToLocalPoint(float stageX, float stageY);
void draw(Recorder* recorder) override;
- void measureBounds(Rect* bounds) override;
+ void measureBounds(tgfx::Rect* bounds) override;
Matrix getTotalMatrixInternal();
virtual void setMatrixInternal(const Matrix& matrix);
virtual float frameRateInternal() const;
@@ -758,7 +762,7 @@ class PAG_API PAGImageLayer : public PAGLayer {
static Frame ScaleTimeRemap(AnimatableProperty* property, const TimeRange& visibleRange,
double frameScale, Frame fileEndFrame);
Frame getFrameFromTimeRemap(Frame value);
- void measureBounds(Rect* bounds) override;
+ void measureBounds(tgfx::Rect* bounds) override;
friend class RenderCache;
@@ -912,7 +916,7 @@ class PAG_API PAGComposition : public PAGLayer {
int heightInternal() const;
void setContentSizeInternal(int width, int height);
void draw(Recorder* recorder) override;
- void measureBounds(Rect* bounds) override;
+ void measureBounds(tgfx::Rect* bounds) override;
bool hasClip() const;
Frame frameDuration() const override;
bool cacheFilters() const override;
@@ -932,7 +936,7 @@ class PAG_API PAGComposition : public PAGLayer {
static void FindLayers(std::function filterFunc,
std::vector>* result,
std::shared_ptr pagLayer);
- static void MeasureChildLayer(Rect* bounds, PAGLayer* childLayer);
+ static void MeasureChildLayer(tgfx::Rect* bounds, PAGLayer* childLayer);
static void DrawChildLayer(Recorder* recorder, PAGLayer* childLayer);
static bool GetTrackMatteLayerAtPoint(PAGLayer* childLayer, float x, float y,
std::vector>* results);
@@ -1093,12 +1097,6 @@ class Composition;
class PAGPlayer;
-class Context;
-
-class Surface;
-
-class Device;
-
class Drawable {
public:
virtual ~Drawable() = default;
@@ -1121,18 +1119,18 @@ class Drawable {
/**
* Returns the GPU device associated with this drawable.
*/
- virtual std::shared_ptr getDevice() = 0;
+ virtual std::shared_ptr getDevice() = 0;
/**
* Creates a new Surface from this drawable.
*/
- virtual std::shared_ptr createSurface(Context* context) = 0;
+ virtual std::shared_ptr createSurface(tgfx::Context* context) = 0;
/**
* Apply all pending changes to the drawable.
* Note: The associated GPUDevice must be the current rendering device on the calling thread.
*/
- virtual void present(Context* context) = 0;
+ virtual void present(tgfx::Context* context) = 0;
/**
* Set the presenting timeStamp, used for android
@@ -1212,15 +1210,15 @@ class PAG_API PAGSurface {
PAGPlayer* pagPlayer = nullptr;
std::shared_ptr rootLocker = nullptr;
std::shared_ptr drawable = nullptr;
- std::shared_ptr device = nullptr;
- std::shared_ptr surface = nullptr;
+ std::shared_ptr device = nullptr;
+ std::shared_ptr surface = nullptr;
explicit PAGSurface(std::shared_ptr drawable);
bool draw(RenderCache* cache, std::shared_ptr graphic, BackendSemaphore* signalSemaphore,
bool autoClear = true);
bool hitTest(RenderCache* cache, std::shared_ptr graphic, float x, float y);
- Context* lockContext();
+ tgfx::Context* lockContext();
void unlockContext();
bool wait(const BackendSemaphore& waitSemaphore);
diff --git a/include/pag/types.h b/include/pag/types.h
index 47f8692e26..846a332ecd 100644
--- a/include/pag/types.h
+++ b/include/pag/types.h
@@ -501,24 +501,18 @@ struct PAG_API Rect {
* Returns true if Rect intersects construction.
* Returns false if either construction or Rect is empty, or do not intersect.
*/
- bool intersects(float l, float t, float r, float b) const {
- return Intersects(left, top, right, bottom, l, t, r, b);
- }
+ bool intersects(float l, float t, float r, float b) const;
/**
* Returns true if Rect intersects r. Returns false if either r or Rect is empty, or do not
* intersect.
*/
- bool intersects(const Rect& r) const {
- return Intersects(left, top, right, bottom, r.left, r.top, r.right, r.bottom);
- }
+ bool intersects(const Rect& r) const;
/**
* Returns true if a intersects b. Returns false if either a or b is empty, or do not intersect.
*/
- static bool Intersects(const Rect& a, const Rect& b) {
- return Intersects(a.left, a.top, a.right, a.bottom, b.left, b.top, b.right, b.bottom);
- }
+ static bool Intersects(const Rect& a, const Rect& b);
/**
* Constructs Rect to intersect from (left, top, right, bottom). Does not sort construction.
@@ -554,64 +548,25 @@ struct PAG_API Rect {
* Sets Rect by discarding the fractional portion of left and top; and rounding up right and
* bottom.
*/
- void roundOut() {
- left = floorf(left);
- top = floorf(top);
- right = ceilf(right);
- bottom = ceilf(bottom);
- }
+ void roundOut();
/**
* Sets Rect by rounding of left, top, right and bottom.
*/
- void round() {
- left = roundf(left);
- top = roundf(top);
- right = roundf(right);
- bottom = roundf(bottom);
- }
+ void round();
/**
* Swaps left and right if left is greater than right; and swaps top and bottom if top is
* greater than bottom. Result may be empty; and width() and height() will be zero or positive.
*/
- void sort() {
- if (left > right) {
- std::swap(left, right);
- }
-
- if (top > bottom) {
- std::swap(top, bottom);
- }
- }
+ void sort();
/**
* Returns Rect with left and right swapped if left is greater than right, and with top and
* bottom swapped if top is greater than bottom. Result may be empty, and width() and height()
* will be zero or positive.
*/
- Rect makeSorted() const {
- return MakeLTRB(std::min(left, right), std::min(top, bottom), std::max(left, right),
- std::max(top, bottom));
- }
-
- private:
- static bool Intersects(float al, float at, float ar, float ab, float bl, float bt, float br,
- float bb) {
- float L = al > bl ? al : bl;
- float R = ar < br ? ar : br;
- float T = at > bt ? at : bt;
- float B = ab < bb ? ab : bb;
- return L < R && T < B;
- }
-};
-
-/**
- * Round Rect.
- */
-struct RRect {
- Rect rect = Rect::MakeEmpty();
- Point radii = Point::Zero();
+ Rect makeSorted() const;
};
/***
@@ -1090,15 +1045,7 @@ class PAG_API Matrix {
* If this matrix can be inverted, return true and if inverse is not null, set inverse to be the
* inverse of this matrix. If this matrix cannot be inverted, ignore inverse and return false.
*/
- bool invert(Matrix* inverse) const {
- if (this->isIdentity()) {
- if (inverse) {
- inverse->reset();
- }
- return true;
- }
- return this->invertNonIdentity(inverse);
- }
+ bool invert(Matrix* inverse) const;
bool invertible() const;
@@ -1292,10 +1239,6 @@ class PAG_API Matrix {
static constexpr int PERSP_0 = 6; //!< input x perspective factor
static constexpr int PERSP_1 = 7; //!< input y perspective factor
static constexpr int PERSP_2 = 8; //!< perspective bias
-
- void setScaleTranslate(float sx, float sy, float tx, float ty);
- bool invertNonIdentity(Matrix* inverse) const;
- bool getMinMaxScaleFactors(float results[2]) const;
};
/**
diff --git a/src/base/ByteData.cpp b/src/base/ByteData.cpp
index c3da82a69e..80f299a5c0 100644
--- a/src/base/ByteData.cpp
+++ b/src/base/ByteData.cpp
@@ -21,7 +21,7 @@
namespace pag {
std::unique_ptr ByteData::FromPath(const std::string& filePath) {
- auto stream = Stream::MakeFromFile(filePath);
+ auto stream = tgfx::Stream::MakeFromFile(filePath);
if (stream == nullptr) {
return nullptr;
}
diff --git a/src/base/Matrix.cpp b/src/base/Matrix.cpp
index d4e2a1a438..802814a70b 100644
--- a/src/base/Matrix.cpp
+++ b/src/base/Matrix.cpp
@@ -16,449 +16,162 @@
//
/////////////////////////////////////////////////////////////////////////////////////////////////
-#include "base/utils/MathExtra.h"
+#include "base/utils/TGFXCast.h"
#include "pag/types.h"
namespace pag {
void Matrix::reset() {
- values[SCALE_X] = values[SCALE_Y] = values[PERSP_2] = 1;
- values[SKEW_X] = values[SKEW_Y] = values[TRANS_X] = values[TRANS_Y] = values[PERSP_0] =
- values[PERSP_1] = 0;
+ ToTGFX(this)->reset();
}
bool operator==(const Matrix& a, const Matrix& b) {
- const float* ma = a.values;
- const float* mb = b.values;
- return ma[0] == mb[0] && ma[1] == mb[1] && ma[2] == mb[2] && ma[3] == mb[3] && ma[4] == mb[4] &&
- ma[5] == mb[5] && ma[6] == mb[6] && ma[7] == mb[7] && ma[8] == mb[8];
+ return ToTGFX(a) == ToTGFX(b);
}
void Matrix::setAll(float scaleX, float skewX, float transX, float skewY, float scaleY,
float transY, float persp0, float persp1, float persp2) {
- values[SCALE_X] = scaleX;
- values[SKEW_X] = skewX;
- values[TRANS_X] = transX;
- values[SKEW_Y] = skewY;
- values[SCALE_Y] = scaleY;
- values[TRANS_Y] = transY;
- values[PERSP_0] = persp0;
- values[PERSP_1] = persp1;
- values[PERSP_2] = persp2;
+ ToTGFX(this)->setAll(scaleX, skewX, transX, skewY, scaleY, transY, persp0, persp1, persp2);
}
void Matrix::setAffine(float a, float b, float c, float d, float tx, float ty) {
- values[SCALE_X] = a;
- values[SKEW_X] = c;
- values[TRANS_X] = tx;
- values[SKEW_Y] = b;
- values[SCALE_Y] = d;
- values[TRANS_Y] = ty;
- values[PERSP_0] = 0;
- values[PERSP_1] = 0;
- values[PERSP_2] = 1;
+ ToTGFX(this)->setAffine(a, b, c, d, tx, ty);
}
void Matrix::setTranslate(float dx, float dy) {
- if ((dx != 0) | (dy != 0)) {
- values[TRANS_X] = dx;
- values[TRANS_Y] = dy;
-
- values[SCALE_X] = values[SCALE_Y] = values[PERSP_2] = 1;
- values[SKEW_X] = values[SKEW_Y] = values[PERSP_0] = values[PERSP_1] = 0;
- } else {
- this->reset();
- }
-}
-
-static inline float sdot(float a, float b, float c, float d) {
- return a * b + c * d;
+ ToTGFX(this)->setTranslate(dx, dy);
}
void Matrix::preTranslate(float dx, float dy) {
- values[TRANS_X] += sdot(values[SCALE_X], dx, values[SKEW_X], dy);
- values[TRANS_Y] += sdot(values[SKEW_Y], dx, values[SCALE_Y], dy);
+ ToTGFX(this)->preTranslate(dx, dy);
}
void Matrix::postTranslate(float dx, float dy) {
- values[TRANS_X] += dx;
- values[TRANS_Y] += dy;
-}
-
-void Matrix::setScaleTranslate(float sx, float sy, float tx, float ty) {
- values[SCALE_X] = sx;
- values[SKEW_X] = 0;
- values[TRANS_X] = tx;
-
- values[SKEW_Y] = 0;
- values[SCALE_Y] = sy;
- values[TRANS_Y] = ty;
-
- values[PERSP_0] = 0;
- values[PERSP_1] = 0;
- values[PERSP_2] = 1;
+ ToTGFX(this)->postTranslate(dx, dy);
}
void Matrix::setScale(float sx, float sy, float px, float py) {
- if (1 == sx && 1 == sy) {
- this->reset();
- } else {
- values[SCALE_X] = sx;
- values[SKEW_X] = 0;
- values[TRANS_X] = 0;
-
- values[SKEW_Y] = 0;
- values[SCALE_Y] = sy;
- values[TRANS_Y] = 0;
-
- values[PERSP_0] = 0;
- values[PERSP_1] = 0;
- values[PERSP_2] = 1;
- this->setScaleTranslate(sx, sy, px - sx * px, py - sy * py);
- }
+ ToTGFX(this)->setScale(sx, sy, px, py);
}
void Matrix::setScale(float sx, float sy) {
- if (1 == sx && 1 == sy) {
- this->reset();
- } else {
- values[SCALE_X] = sx;
- values[SCALE_Y] = sy;
- values[PERSP_2] = 1;
-
- values[TRANS_X] = values[TRANS_Y] = values[SKEW_X] = values[SKEW_Y] = values[PERSP_0] =
- values[PERSP_1] = 0;
- }
+ ToTGFX(this)->setScale(sx, sy);
}
void Matrix::preScale(float sx, float sy, float px, float py) {
- if (1 == sx && 1 == sy) {
- return;
- }
-
- Matrix m = {};
- m.setScale(sx, sy, px, py);
- this->preConcat(m);
+ ToTGFX(this)->preScale(sx, sy, px, py);
}
void Matrix::preScale(float sx, float sy) {
- if (1 == sx && 1 == sy) {
- return;
- }
- values[SCALE_X] *= sx;
- values[SKEW_Y] *= sx;
- values[PERSP_0] *= sx;
-
- values[SKEW_X] *= sy;
- values[SCALE_Y] *= sy;
- values[PERSP_1] *= sy;
+ ToTGFX(this)->preScale(sx, sy);
}
void Matrix::postScale(float sx, float sy, float px, float py) {
- if (1 == sx && 1 == sy) {
- return;
- }
- Matrix m = {};
- m.setScale(sx, sy, px, py);
- this->postConcat(m);
+ ToTGFX(this)->postScale(sx, sy, px, py);
}
void Matrix::postScale(float sx, float sy) {
- if (1 == sx && 1 == sy) {
- return;
- }
- Matrix m = {};
- m.setScale(sx, sy);
- this->postConcat(m);
+ ToTGFX(this)->postScale(sx, sy);
}
void Matrix::setSinCos(float sinV, float cosV, float px, float py) {
- const float oneMinusCosV = 1 - cosV;
-
- values[SCALE_X] = cosV;
- values[SKEW_X] = -sinV;
- values[TRANS_X] = sdot(sinV, py, oneMinusCosV, px);
-
- values[SKEW_Y] = sinV;
- values[SCALE_Y] = cosV;
- values[TRANS_Y] = sdot(-sinV, px, oneMinusCosV, py);
-
- values[PERSP_0] = values[PERSP_1] = 0;
- values[PERSP_2] = 1;
+ ToTGFX(this)->setSinCos(sinV, cosV, px, py);
}
void Matrix::setSinCos(float sinV, float cosV) {
- values[SCALE_X] = cosV;
- values[SKEW_X] = -sinV;
- values[TRANS_X] = 0;
-
- values[SKEW_Y] = sinV;
- values[SCALE_Y] = cosV;
- values[TRANS_Y] = 0;
-
- values[PERSP_0] = values[PERSP_1] = 0;
- values[PERSP_2] = 1;
+ ToTGFX(this)->setSinCos(sinV, cosV);
}
void Matrix::setRotate(float degrees, float px, float py) {
- float rad = DegreesToRadians(degrees);
- this->setSinCos(SinSnapToZero(rad), CosSnapToZero(rad), px, py);
+ ToTGFX(this)->setRotate(degrees, px, py);
}
void Matrix::setRotate(float degrees) {
- float rad = DegreesToRadians(degrees);
- this->setSinCos(SinSnapToZero(rad), CosSnapToZero(rad));
+ ToTGFX(this)->setRotate(degrees);
}
void Matrix::preRotate(float degrees, float px, float py) {
- Matrix m = {};
- m.setRotate(degrees, px, py);
- this->preConcat(m);
+ ToTGFX(this)->preRotate(degrees, px, py);
}
void Matrix::preRotate(float degrees) {
- Matrix m = {};
- m.setRotate(degrees);
- this->preConcat(m);
+ ToTGFX(this)->preRotate(degrees);
}
void Matrix::postRotate(float degrees, float px, float py) {
- Matrix m = {};
- m.setRotate(degrees, px, py);
- this->postConcat(m);
+ ToTGFX(this)->postRotate(degrees, px, py);
}
void Matrix::postRotate(float degrees) {
- Matrix m = {};
- m.setRotate(degrees);
- this->postConcat(m);
+ ToTGFX(this)->postRotate(degrees);
}
void Matrix::setSkew(float sx, float sy, float px, float py) {
- values[SCALE_X] = 1;
- values[SKEW_X] = sx;
- values[TRANS_X] = -sx * py;
-
- values[SKEW_Y] = sy;
- values[SCALE_Y] = 1;
- values[TRANS_Y] = -sy * px;
-
- values[PERSP_0] = values[PERSP_1] = 0;
- values[PERSP_2] = 1;
+ ToTGFX(this)->setSkew(sx, sy, px, py);
}
void Matrix::setSkew(float sx, float sy) {
- values[SCALE_X] = 1;
- values[SKEW_X] = sx;
- values[TRANS_X] = 0;
-
- values[SKEW_Y] = sy;
- values[SCALE_Y] = 1;
- values[TRANS_Y] = 0;
-
- values[PERSP_0] = values[PERSP_1] = 0;
- values[PERSP_2] = 1;
+ ToTGFX(this)->setSkew(sx, sy);
}
void Matrix::preSkew(float sx, float sy, float px, float py) {
- Matrix m = {};
- m.setSkew(sx, sy, px, py);
- this->preConcat(m);
+ ToTGFX(this)->preSkew(sx, sy, px, py);
}
void Matrix::preSkew(float sx, float sy) {
- Matrix m = {};
- m.setSkew(sx, sy);
- this->preConcat(m);
+ ToTGFX(this)->preSkew(sx, sy);
}
void Matrix::postSkew(float sx, float sy, float px, float py) {
- Matrix m = {};
- m.setSkew(sx, sy, px, py);
- this->postConcat(m);
+ ToTGFX(this)->postSkew(sx, sy, px, py);
}
void Matrix::postSkew(float sx, float sy) {
- Matrix m = {};
- m.setSkew(sx, sy);
- this->postConcat(m);
+ ToTGFX(this)->postSkew(sx, sy);
}
void Matrix::setConcat(const Matrix& first, const Matrix& second) {
- auto& matA = first.values;
- auto& matB = second.values;
- auto a = matB[SCALE_X] * matA[SCALE_X];
- auto b = 0.0;
- auto c = 0.0;
- auto d = matB[SCALE_Y] * matA[SCALE_Y];
- auto tx = matB[TRANS_X] * matA[SCALE_X] + matA[TRANS_X];
- auto ty = matB[TRANS_Y] * matA[SCALE_Y] + matA[TRANS_Y];
-
- if (matB[SKEW_Y] != 0.0 || matB[SKEW_X] != 0.0 || matA[SKEW_Y] != 0.0 || matA[SKEW_X] != 0.0) {
- a += matB[SKEW_Y] * matA[SKEW_X];
- d += matB[SKEW_X] * matA[SKEW_Y];
- b += matB[SCALE_X] * matA[SKEW_Y] + matB[SKEW_Y] * matA[SCALE_Y];
- c += matB[SKEW_X] * matA[SCALE_X] + matB[SCALE_Y] * matA[SKEW_X];
- tx += matB[TRANS_Y] * matA[SKEW_X];
- ty += matB[TRANS_X] * matA[SKEW_Y];
- }
-
- values[SCALE_X] = a;
- values[SKEW_Y] = b;
- values[SKEW_X] = c;
- values[SCALE_Y] = d;
- values[TRANS_X] = tx;
- values[TRANS_Y] = ty;
- values[PERSP_0] = 0;
- values[PERSP_1] = 0;
- values[PERSP_2] = 1;
+ ToTGFX(this)->setConcat(ToTGFX(first), ToTGFX(second));
}
void Matrix::preConcat(const Matrix& mat) {
- // check for identity first, so we don't do a needless copy of ourselves
- // to ourselves inside setConcat()
- if (!mat.isIdentity()) {
- this->setConcat(*this, mat);
- }
+ ToTGFX(this)->preConcat(ToTGFX(mat));
}
void Matrix::postConcat(const Matrix& mat) {
- // check for identity first, so we don't do a needless copy of ourselves
- // to ourselves inside setConcat()
- if (!mat.isIdentity()) {
- this->setConcat(mat, *this);
- }
+ ToTGFX(this)->postConcat(ToTGFX(mat));
+}
+
+bool Matrix::invert(Matrix* inverse) const {
+ return ToTGFX(this)->invert(ToTGFX(inverse));
}
bool Matrix::invertible() const {
- float determinant = values[SCALE_X] * values[SCALE_Y] - values[SKEW_Y] * values[SKEW_X];
- return !(FloatNearlyZero(determinant, FLOAT_NEARLY_ZERO * FLOAT_NEARLY_ZERO * FLOAT_NEARLY_ZERO));
-}
-
-bool Matrix::invertNonIdentity(Matrix* inverse) const {
- auto a = values[SCALE_X];
- auto d = values[SCALE_Y];
- auto c = values[SKEW_X];
- auto b = values[SKEW_Y];
- auto tx = values[TRANS_X];
- auto ty = values[TRANS_Y];
-
- if (b == 0 && c == 0) {
- if (a == 0 || d == 0) {
- return false;
- }
- a = 1 / a;
- d = 1 / d;
- tx = -a * tx;
- ty = -d * ty;
- inverse->setAffine(a, b, c, d, tx, ty);
- return true;
- }
- float determinant = a * d - b * c;
- if (FloatNearlyZero(determinant, FLOAT_NEARLY_ZERO * FLOAT_NEARLY_ZERO * FLOAT_NEARLY_ZERO)) {
- return false;
- }
- determinant = 1 / determinant;
- a = d * determinant;
- b = -b * determinant;
- c = -c * determinant;
- d = values[SCALE_X] * determinant;
- tx = -(a * values[TRANS_X] + c * values[TRANS_Y]);
- ty = -(b * values[TRANS_X] + d * values[TRANS_Y]);
- inverse->setAffine(a, b, c, d, tx, ty);
- return true;
+ return ToTGFX(this)->invertible();
}
void Matrix::mapPoints(Point dst[], const Point src[], int count) const {
- auto tx = values[TRANS_X];
- auto ty = values[TRANS_Y];
- auto sx = values[SCALE_X];
- auto sy = values[SCALE_Y];
- auto kx = values[SKEW_X];
- auto ky = values[SKEW_Y];
- for (int i = 0; i < count; i++) {
- auto x = src[i].x * sx + src[i].y * kx + tx;
- auto y = src[i].x * ky + src[i].y * sy + ty;
- dst[i].set(x, y);
- }
+ ToTGFX(this)->mapPoints(ToTGFX(dst), ToTGFX(src), count);
}
void Matrix::mapXY(float x, float y, Point* result) const {
- auto tx = values[TRANS_X];
- auto ty = values[TRANS_Y];
- auto sx = values[SCALE_X];
- auto sy = values[SCALE_Y];
- auto kx = values[SKEW_X];
- auto ky = values[SKEW_Y];
- result->set(x * sx + y * kx + tx, x * ky + y * sy + ty);
+ ToTGFX(this)->mapXY(x, y, ToTGFX(result));
}
void Matrix::mapRect(Rect* dst, const Rect& src) const {
- Point quad[4];
- quad[0].set(src.left, src.top);
- quad[1].set(src.right, src.top);
- quad[2].set(src.right, src.bottom);
- quad[3].set(src.left, src.bottom);
- mapPoints(quad, quad, 4);
- dst->setBounds(quad, 4);
+ ToTGFX(this)->mapRect(ToTGFX(dst), ToTGFX(src));
}
float Matrix::getMinScale() const {
- float results[2];
- if (getMinMaxScaleFactors(results)) {
- return results[0];
- }
- return -1.0f;
+ return ToTGFX(this)->getMinScale();
}
float Matrix::getMaxScale() const {
- float results[2];
- if (getMinMaxScaleFactors(results)) {
- return results[1];
- }
- return -1.0f;
-}
-
-bool Matrix::getMinMaxScaleFactors(float* results) const {
- float a = sdot(values[SCALE_X], values[SCALE_X], values[SKEW_Y], values[SKEW_Y]);
- float b = sdot(values[SCALE_X], values[SKEW_X], values[SCALE_Y], values[SKEW_Y]);
- float c = sdot(values[SKEW_X], values[SKEW_X], values[SCALE_Y], values[SCALE_Y]);
- float bSqd = b * b;
- if (bSqd <= FLOAT_NEARLY_ZERO * FLOAT_NEARLY_ZERO) {
- results[0] = a;
- results[1] = c;
- if (results[0] > results[1]) {
- using std::swap;
- swap(results[0], results[1]);
- }
- } else {
- float aminusc = a - c;
- float apluscdiv2 = (a + c) * 0.5f;
- float x = sqrtf(aminusc * aminusc + 4 * bSqd) * 0.5f;
- results[0] = apluscdiv2 - x;
- results[1] = apluscdiv2 + x;
- }
- auto isFinite = (results[0] * 0 == 0);
- if (!isFinite) {
- return false;
- }
- if (results[0] < 0) {
- results[0] = 0;
- }
- results[0] = sqrtf(results[0]);
- isFinite = (results[1] * 0 == 0);
- if (!isFinite) {
- return false;
- }
- if (results[1] < 0) {
- results[1] = 0;
- }
- results[1] = sqrtf(results[1]);
- return true;
+ return ToTGFX(this)->getMaxScale();
}
bool Matrix::isFinite() const {
- return FloatsAreFinite(values, 9);
+ return ToTGFX(this)->isFinite();
}
const Matrix& Matrix::I() {
diff --git a/src/base/Rect.cpp b/src/base/Rect.cpp
index d85af84c6b..9e6bcfc616 100644
--- a/src/base/Rect.cpp
+++ b/src/base/Rect.cpp
@@ -16,89 +16,56 @@
//
/////////////////////////////////////////////////////////////////////////////////////////////////
+#include "base/utils/TGFXCast.h"
#include "pag/types.h"
namespace pag {
void Rect::scale(float scaleX, float scaleY) {
- left *= scaleX;
- right *= scaleY;
- top *= scaleX;
- bottom *= scaleY;
+ ToTGFX(this)->scale(scaleX, scaleY);
}
bool Rect::setBounds(const Point pts[], int count) {
- if (count <= 0) {
- this->setEmpty();
- return true;
- }
- float minX, maxX;
- float minY, maxY;
- minX = maxX = pts[0].x;
- minY = maxY = pts[0].y;
-
- for (int i = 1; i < count; i++) {
- auto x = pts[i].x;
- auto y = pts[i].y;
- auto isFinite = ((x + y) * 0 == 0);
- if (!isFinite) {
- setEmpty();
- return false;
- }
- if (x < minX) {
- minX = x;
- }
- if (x > maxX) {
- maxX = x;
- }
- if (y < minY) {
- minY = y;
- }
- if (y > maxY) {
- maxY = y;
- }
- }
- setLTRB(minX, minY, maxX, maxY);
- return true;
+ return ToTGFX(this)->setBounds(ToTGFX(pts), count);
}
-#define CHECK_INTERSECT(al, at, ar, ab, bl, bt, br, bb) \
- float L = al > bl ? al : bl; \
- float R = ar < br ? ar : br; \
- float T = at > bt ? at : bt; \
- float B = ab < bb ? ab : bb; \
- do { \
- if (!(L < R && T < B)) { \
- return false; \
- } \
- } while (0)
-// do the !(opposite) check so we return false if either arg is NaN
-
bool Rect::intersect(float l, float t, float r, float b) {
- CHECK_INTERSECT(l, t, r, b, left, top, right, bottom);
- this->setLTRB(L, T, R, B);
- return true;
+ return ToTGFX(this)->intersect(l, t, r, b);
}
bool Rect::intersect(const Rect& a, const Rect& b) {
- CHECK_INTERSECT(a.left, a.top, a.right, a.bottom, b.left, b.top, b.right, b.bottom);
- this->setLTRB(L, T, R, B);
- return true;
+ return ToTGFX(this)->intersect(ToTGFX(a), ToTGFX(b));
}
void Rect::join(float l, float t, float r, float b) {
- // do nothing if the params are empty
- if (l >= r || t >= b) {
- return;
- }
- // if we are empty, just assign
- if (left >= right || top >= bottom) {
- this->setLTRB(l, t, r, b);
- } else {
- left = left < l ? left : l;
- top = top < t ? top : t;
- right = right > r ? right : r;
- bottom = bottom > b ? bottom : b;
- }
+ ToTGFX(this)->join(l, t, r, b);
+}
+
+bool Rect::intersects(float l, float t, float r, float b) const {
+ return ToTGFX(this)->intersects(l, t, r, b);
+}
+
+bool Rect::intersects(const Rect& r) const {
+ return ToTGFX(this)->intersects(ToTGFX(r));
+}
+
+bool Rect::Intersects(const Rect& a, const Rect& b) {
+ return tgfx::Rect::Intersects(ToTGFX(a), ToTGFX(b));
+}
+
+void Rect::roundOut() {
+ ToTGFX(this)->roundOut();
+}
+
+void Rect::round() {
+ ToTGFX(this)->round();
+}
+
+void Rect::sort() {
+ ToTGFX(this)->sort();
+}
+
+Rect Rect::makeSorted() const {
+ return ToPAG(ToTGFX(this)->makeSorted());
}
} // namespace pag
\ No newline at end of file
diff --git a/src/base/effects/BulgeEffect.cpp b/src/base/effects/BulgeEffect.cpp
index 980ffafdfc..b4cb0d83d3 100644
--- a/src/base/effects/BulgeEffect.cpp
+++ b/src/base/effects/BulgeEffect.cpp
@@ -16,16 +16,15 @@
//
/////////////////////////////////////////////////////////////////////////////////////////////////
-#include "base/utils/MathExtra.h"
#include "base/utils/Verify.h"
#include "core/Path.h"
#include "pag/file.h"
namespace pag {
-static void ConvertEllipseToPath(Path* path, float centerX, float centerY, float radiusX,
+static void ConvertEllipseToPath(tgfx::Path* path, float centerX, float centerY, float radiusX,
float radiusY) {
- auto start = -M_PI_2_F;
- auto endAngle = M_PI_F + M_PI_2_F;
+ auto start = -static_cast(M_PI_2);
+ auto endAngle = static_cast(M_PI + M_PI_2);
auto end = 0;
auto currentX = centerX + cosf(start) * radiusX;
auto currentY = centerY + sinf(start) * radiusY;
@@ -48,7 +47,7 @@ static void ConvertEllipseToPath(Path* path, float centerX, float centerY, float
break;
}
start = end;
- end = start + M_PI_2_F;
+ end = start + static_cast(M_PI_2);
if (end > endAngle) {
end = endAngle;
}
@@ -120,14 +119,14 @@ void BulgeEffect::transformBounds(Rect* contentBounds, const Point&, Frame layer
auto right = contentBounds->right;
auto bottom = contentBounds->bottom;
- Path ellipsePath = {};
+ tgfx::Path ellipsePath = {};
// radius 需要加 1,如果 2 者相交只有一个点时,intersectPath.isEmpty 为 true
ConvertEllipseToPath(&ellipsePath, bulgeCenterValue.x, bulgeCenterValue.y,
horizontalRadiusValue + 1, verticalRadiusValue + 1);
- Path boundsPath = {};
+ tgfx::Path boundsPath = {};
boundsPath.addRect(left, top, right, bottom);
auto intersectPath = ellipsePath;
- intersectPath.addPath(boundsPath, PathOp::Intersect);
+ intersectPath.addPath(boundsPath, tgfx::PathOp::Intersect);
// 凸出效果的椭圆与内容 bounds 没有交集,不改变尺寸
if (intersectPath.isEmpty() && !intersectPath.isInverseFillType()) {
return;
diff --git a/src/base/layerStyles/DropShadowStyle.cpp b/src/base/layerStyles/DropShadowStyle.cpp
index 6a87f8bade..87b7a9ef36 100644
--- a/src/base/layerStyles/DropShadowStyle.cpp
+++ b/src/base/layerStyles/DropShadowStyle.cpp
@@ -16,7 +16,7 @@
//
/////////////////////////////////////////////////////////////////////////////////////////////////
-#include "base/utils/MathExtra.h"
+#include "base/utils/MathUtil.h"
#include "base/utils/Verify.h"
#include "pag/file.h"
diff --git a/src/base/utils/Log.h b/src/base/utils/Log.h
index 8014bdc96b..947a86be49 100644
--- a/src/base/utils/Log.h
+++ b/src/base/utils/Log.h
@@ -22,10 +22,10 @@
#include "platform/Print.h"
namespace pag {
-#define ABORT(msg) \
- do { \
- pag::PrintError("%s:%d: fatal error: \"%s\"\n", __FILE__, __LINE__, #msg); \
- ::abort(); \
+#define ABORT(msg) \
+ do { \
+ tgfx::PrintError("%s:%d: fatal error: \"%s\"\n", __FILE__, __LINE__, #msg); \
+ ::abort(); \
} while (false)
#ifdef NO_LOG
@@ -36,8 +36,8 @@ namespace pag {
#else
-#define LOGI(...) pag::PrintLog(__VA_ARGS__)
-#define LOGE(...) pag::PrintError(__VA_ARGS__)
+#define LOGI(...) tgfx::PrintLog(__VA_ARGS__)
+#define LOGE(...) tgfx::PrintError(__VA_ARGS__)
#define ASSERT(assertion) \
if (!(assertion)) { \
ABORT(#assertion); \
diff --git a/src/rendering/utils/TGFXTypes.h b/src/base/utils/MathUtil.h
similarity index 76%
rename from src/rendering/utils/TGFXTypes.h
rename to src/base/utils/MathUtil.h
index 05f3ab39e1..8c386a4253 100644
--- a/src/rendering/utils/TGFXTypes.h
+++ b/src/base/utils/MathUtil.h
@@ -18,19 +18,14 @@
#pragma once
-#include "core/Blend.h"
-#include "core/Color4f.h"
-#include "core/Stroke.h"
-#include "pag/file.h"
+#include
namespace pag {
-Blend ToTGFXBlend(Enum blendMode);
+static inline float DegreesToRadians(float degrees) {
+ return degrees * (static_cast(M_PI) / 180.0f);
+}
-Stroke::Cap ToTGFXCap(Enum cap);
-
-Stroke::Join ToTGFXJoin(Enum join);
-
-Color4f ToTGFXColor(Color color, Opacity opacity = Opaque);
-
-float ToAlpha(Opacity opacity);
+static inline float RadiansToDegrees(float radians) {
+ return radians * (180.0f / static_cast(M_PI));
+}
} // namespace pag
diff --git a/src/base/utils/MatrixUtil.cpp b/src/base/utils/MatrixUtil.cpp
index 53a103ac35..481928e535 100644
--- a/src/base/utils/MatrixUtil.cpp
+++ b/src/base/utils/MatrixUtil.cpp
@@ -19,8 +19,8 @@
#include "MatrixUtil.h"
namespace pag {
-bool MapPointInverted(const Matrix& matrix, Point* point) {
- Matrix inverted = {};
+bool MapPointInverted(const tgfx::Matrix& matrix, tgfx::Point* point) {
+ tgfx::Matrix inverted = {};
bool canInvert = matrix.invert(&inverted);
if (canInvert) {
inverted.mapPoints(point, 1);
@@ -29,13 +29,13 @@ bool MapPointInverted(const Matrix& matrix, Point* point) {
return false;
}
-float GetMaxScaleFactor(const Matrix& matrix) {
+float GetMaxScaleFactor(const tgfx::Matrix& matrix) {
auto scale = GetScaleFactor(matrix);
return std::max(fabsf(scale.x), fabsf(scale.y));
}
-Point GetScaleFactor(const Matrix& matrix, float contentScale, bool inverted) {
- Point scale = {};
+tgfx::Point GetScaleFactor(const tgfx::Matrix& matrix, float contentScale, bool inverted) {
+ tgfx::Point scale = {};
auto a = matrix.get(0);
auto c = matrix.get(1);
auto b = matrix.get(3);
diff --git a/src/base/utils/MatrixUtil.h b/src/base/utils/MatrixUtil.h
index 7623c72d38..0d9ae60c31 100644
--- a/src/base/utils/MatrixUtil.h
+++ b/src/base/utils/MatrixUtil.h
@@ -18,10 +18,11 @@
#pragma once
-#include "pag/types.h"
+#include "core/Matrix.h"
namespace pag {
-bool MapPointInverted(const Matrix& matrix, Point* point);
-float GetMaxScaleFactor(const Matrix& matrix);
-Point GetScaleFactor(const Matrix& matrix, float contentScale = 1.0f, bool inverted = false);
+bool MapPointInverted(const tgfx::Matrix& matrix, tgfx::Point* point);
+float GetMaxScaleFactor(const tgfx::Matrix& matrix);
+tgfx::Point GetScaleFactor(const tgfx::Matrix& matrix, float contentScale = 1.0f,
+ bool inverted = false);
} // namespace pag
diff --git a/src/base/utils/TGFXCast.cpp b/src/base/utils/TGFXCast.cpp
new file mode 100644
index 0000000000..28ad7a3050
--- /dev/null
+++ b/src/base/utils/TGFXCast.cpp
@@ -0,0 +1,144 @@
+/////////////////////////////////////////////////////////////////////////////////////////////////
+//
+// Tencent is pleased to support the open source community by making libpag available.
+//
+// Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
+// except in compliance with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// unless required by applicable law or agreed to in writing, software distributed under the
+// license is distributed on an "as is" basis, without warranties or conditions of any kind,
+// either express or implied. see the license for the specific language governing permissions
+// and limitations under the license.
+//
+/////////////////////////////////////////////////////////////////////////////////////////////////
+
+#include "TGFXCast.h"
+
+namespace pag {
+static constexpr std::pair kBlendModeMap[] = {
+ {BlendMode::Normal, tgfx::BlendMode::SrcOver},
+ {BlendMode::Multiply, tgfx::BlendMode::Multiply},
+ {BlendMode::Screen, tgfx::BlendMode::Screen},
+ {BlendMode::Overlay, tgfx::BlendMode::Overlay},
+ {BlendMode::Darken, tgfx::BlendMode::Darken},
+ {BlendMode::Lighten, tgfx::BlendMode::Lighten},
+ {BlendMode::ColorDodge, tgfx::BlendMode::ColorDodge},
+ {BlendMode::ColorBurn, tgfx::BlendMode::ColorBurn},
+ {BlendMode::HardLight, tgfx::BlendMode::HardLight},
+ {BlendMode::SoftLight, tgfx::BlendMode::SoftLight},
+ {BlendMode::Difference, tgfx::BlendMode::Difference},
+ {BlendMode::Exclusion, tgfx::BlendMode::Exclusion},
+ {BlendMode::Hue, tgfx::BlendMode::Hue},
+ {BlendMode::Saturation, tgfx::BlendMode::Saturation},
+ {BlendMode::Color, tgfx::BlendMode::Color},
+ {BlendMode::Luminosity, tgfx::BlendMode::Luminosity},
+ {BlendMode::Add, tgfx::BlendMode::Plus}};
+
+tgfx::BlendMode ToTGFXBlend(Enum blendMode) {
+ for (const auto& pair : kBlendModeMap) {
+ if (pair.first == blendMode) {
+ return pair.second;
+ }
+ }
+ return tgfx::BlendMode::SrcOver;
+}
+
+tgfx::LineCap ToTGFXCap(Enum cap) {
+ switch (cap) {
+ case LineCap::Round:
+ return tgfx::LineCap::Round;
+ case LineCap::Square:
+ return tgfx::LineCap::Square;
+ default:
+ return tgfx::LineCap::Butt;
+ }
+}
+
+tgfx::LineJoin ToTGFXJoin(Enum join) {
+ switch (join) {
+ case LineJoin::Round:
+ return tgfx::LineJoin::Round;
+ case LineJoin::Bevel:
+ return tgfx::LineJoin::Bevel;
+ default:
+ return tgfx::LineJoin::Miter;
+ }
+}
+
+tgfx::Color ToTGFX(Color color, Opacity opacity) {
+ return {static_cast(color.red) / 255.0f, static_cast(color.green) / 255.0f,
+ static_cast(color.blue) / 255.0f, ToAlpha(opacity)};
+}
+
+float ToAlpha(Opacity opacity) {
+ if (opacity == 255) {
+ return 1.0f;
+ }
+ return static_cast(opacity) / 255.0f;
+}
+
+tgfx::ImageOrigin ToTGFX(ImageOrigin origin) {
+ return origin == ImageOrigin::TopLeft ? tgfx::ImageOrigin::TopLeft
+ : tgfx::ImageOrigin::BottomLeft;
+}
+
+ImageOrigin ToPAG(tgfx::ImageOrigin origin) {
+ return origin == tgfx::ImageOrigin::TopLeft ? ImageOrigin::TopLeft : ImageOrigin::BottomLeft;
+}
+
+tgfx::AlphaType ToTGFX(AlphaType alphaType) {
+ switch (alphaType) {
+ case AlphaType::Opaque:
+ return tgfx::AlphaType::Opaque;
+ case AlphaType::Premultiplied:
+ return tgfx::AlphaType::Premultiplied;
+ case AlphaType::Unpremultiplied:
+ return tgfx::AlphaType::Unpremultiplied;
+ default:
+ return tgfx::AlphaType::Unknown;
+ }
+}
+
+AlphaType ToPAG(tgfx::AlphaType alphaType) {
+ switch (alphaType) {
+ case tgfx::AlphaType::Opaque:
+ return AlphaType::Opaque;
+ case tgfx::AlphaType::Premultiplied:
+ return AlphaType::Premultiplied;
+ case tgfx::AlphaType::Unpremultiplied:
+ return AlphaType::Unpremultiplied;
+ default:
+ return AlphaType::Unknown;
+ }
+}
+
+tgfx::ColorType ToTGFX(ColorType colorType) {
+ switch (colorType) {
+ case ColorType::ALPHA_8:
+ return tgfx::ColorType::ALPHA_8;
+ case ColorType::RGBA_8888:
+ return tgfx::ColorType::RGBA_8888;
+ case ColorType::BGRA_8888:
+ return tgfx::ColorType::BGRA_8888;
+ default:
+ return tgfx::ColorType::Unknown;
+ }
+}
+
+ColorType ToPAG(tgfx::ColorType colorType) {
+ switch (colorType) {
+ case tgfx::ColorType::ALPHA_8:
+ return ColorType::ALPHA_8;
+ case tgfx::ColorType::RGBA_8888:
+ return ColorType::RGBA_8888;
+ case tgfx::ColorType::BGRA_8888:
+ return ColorType::BGRA_8888;
+ default:
+ return ColorType::Unknown;
+ }
+}
+} // namespace pag
diff --git a/src/base/utils/TGFXCast.h b/src/base/utils/TGFXCast.h
new file mode 100644
index 0000000000..0ec25de4a5
--- /dev/null
+++ b/src/base/utils/TGFXCast.h
@@ -0,0 +1,139 @@
+/////////////////////////////////////////////////////////////////////////////////////////////////
+//
+// Tencent is pleased to support the open source community by making libpag available.
+//
+// Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
+// except in compliance with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// unless required by applicable law or agreed to in writing, software distributed under the
+// license is distributed on an "as is" basis, without warranties or conditions of any kind,
+// either express or implied. see the license for the specific language governing permissions
+// and limitations under the license.
+//
+/////////////////////////////////////////////////////////////////////////////////////////////////
+
+#pragma once
+
+#include "core/BlendMode.h"
+#include "core/Color.h"
+#include "core/ImageInfo.h"
+#include "core/ImageOrigin.h"
+#include "core/Matrix.h"
+#include "core/Stroke.h"
+#include "gpu/Backend.h"
+#include "pag/file.h"
+#include "pag/gpu.h"
+
+namespace pag {
+
+tgfx::BlendMode ToTGFXBlend(Enum blendMode);
+
+tgfx::LineCap ToTGFXCap(Enum cap);
+
+tgfx::LineJoin ToTGFXJoin(Enum join);
+
+tgfx::Color ToTGFX(Color color, Opacity opacity = Opaque);
+
+float ToAlpha(Opacity opacity);
+
+tgfx::ImageOrigin ToTGFX(ImageOrigin origin);
+
+ImageOrigin ToPAG(tgfx::ImageOrigin origin);
+
+tgfx::AlphaType ToTGFX(AlphaType alphaType);
+
+AlphaType ToPAG(tgfx::AlphaType alphaType);
+
+tgfx::ColorType ToTGFX(ColorType colorType);
+
+ColorType ToPAG(tgfx::ColorType colorType);
+
+static inline tgfx::BackendTexture ToTGFX(const BackendTexture& texture) {
+ return *reinterpret_cast(&texture);
+}
+
+static inline BackendTexture ToPAG(const tgfx::BackendTexture& texture) {
+ return *reinterpret_cast(&texture);
+}
+
+static inline tgfx::BackendRenderTarget ToTGFX(const BackendRenderTarget& renderTarget) {
+ return *reinterpret_cast(&renderTarget);
+}
+
+static inline BackendRenderTarget ToPAG(const tgfx::BackendRenderTarget& renderTarget) {
+ return *reinterpret_cast(&renderTarget);
+}
+
+static inline tgfx::BackendSemaphore* ToTGFX(BackendSemaphore* semaphore) {
+ return reinterpret_cast(semaphore);
+}
+
+static inline tgfx::BackendSemaphore ToTGFX(const BackendSemaphore& semaphore) {
+ return *reinterpret_cast(&semaphore);
+}
+
+static inline const tgfx::Matrix* ToTGFX(const Matrix* matrix) {
+ return reinterpret_cast(matrix);
+}
+
+static inline tgfx::Matrix* ToTGFX(Matrix* matrix) {
+ return reinterpret_cast(matrix);
+}
+
+static inline tgfx::Matrix ToTGFX(const Matrix& matrix) {
+ return *ToTGFX(&matrix);
+}
+
+static inline Matrix ToPAG(const tgfx::Matrix& matrix) {
+ return *reinterpret_cast(&matrix);
+}
+
+static inline Matrix* ToPAG(tgfx::Matrix* matrix) {
+ return reinterpret_cast(matrix);
+}
+
+static inline const tgfx::Rect* ToTGFX(const Rect* rect) {
+ return reinterpret_cast(rect);
+}
+
+static inline tgfx::Rect* ToTGFX(Rect* rect) {
+ return reinterpret_cast(rect);
+}
+
+static inline tgfx::Rect ToTGFX(const Rect& rect) {
+ return *ToTGFX(&rect);
+}
+
+static inline const tgfx::Point* ToTGFX(const Point* point) {
+ return reinterpret_cast(point);
+}
+
+static inline Rect ToPAG(const tgfx::Rect& rect) {
+ return *reinterpret_cast(&rect);
+}
+
+static inline Rect* ToPAG(tgfx::Rect* rect) {
+ return reinterpret_cast(rect);
+}
+
+static inline tgfx::Point* ToTGFX(Point* point) {
+ return reinterpret_cast(point);
+}
+
+static inline tgfx::Point ToTGFX(const Point& point) {
+ return {point.x, point.y};
+}
+
+static inline Point ToPAG(const tgfx::Point& point) {
+ return {point.x, point.y};
+}
+
+static inline Point* ToPAG(tgfx::Point* point) {
+ return reinterpret_cast(point);
+}
+
+} // namespace pag
diff --git a/src/platform/Platform.cpp b/src/platform/Platform.cpp
index 4a91d4dd04..97775eb2de 100644
--- a/src/platform/Platform.cpp
+++ b/src/platform/Platform.cpp
@@ -38,6 +38,6 @@ NALUType Platform::naluType() const {
return NALUType::AnnexB;
}
-void Platform::traceImage(const ImageInfo&, const void*, const std::string&) const {
+void Platform::traceImage(const tgfx::ImageInfo&, const void*, const std::string&) const {
}
} // namespace pag
\ No newline at end of file
diff --git a/src/platform/Platform.h b/src/platform/Platform.h
index 8d9ae16c47..0b61512e73 100644
--- a/src/platform/Platform.h
+++ b/src/platform/Platform.h
@@ -23,12 +23,12 @@
#include
#include
#include "codec/NALUType.h"
+#include "core/Data.h"
#include "core/ImageInfo.h"
namespace pag {
struct VideoConfig;
class VideoDecoder;
-class Data;
/**
* Defines methods for native platforms to implement.
@@ -68,6 +68,7 @@ class Platform {
/**
* Provides a utility to view the PixelMap data.
*/
- virtual void traceImage(const ImageInfo& info, const void* pixels, const std::string& tag) const;
+ virtual void traceImage(const tgfx::ImageInfo& info, const void* pixels,
+ const std::string& tag) const;
};
} // namespace pag
\ No newline at end of file
diff --git a/src/platform/android/GPUDrawable.cpp b/src/platform/android/GPUDrawable.cpp
index 809bdd7c0e..d0306fc8d3 100644
--- a/src/platform/android/GPUDrawable.cpp
+++ b/src/platform/android/GPUDrawable.cpp
@@ -46,21 +46,21 @@ void GPUDrawable::updateSize() {
}
}
-std::shared_ptr GPUDrawable::getDevice() {
+std::shared_ptr GPUDrawable::getDevice() {
if (_width <= 0 || _height <= 0) {
return nullptr;
}
if (window == nullptr) {
- window = EGLWindow::MakeFrom(nativeWindow, sharedContext);
+ window = tgfx::EGLWindow::MakeFrom(nativeWindow, sharedContext);
}
return window ? window->getDevice() : nullptr;
}
-std::shared_ptr GPUDrawable::createSurface(Context* context) {
+std::shared_ptr GPUDrawable::createSurface(tgfx::Context* context) {
return window ? window->createSurface(context) : nullptr;
}
-void GPUDrawable::present(Context* context) {
+void GPUDrawable::present(tgfx::Context* context) {
if (window == nullptr) {
return;
}
diff --git a/src/platform/android/GPUDrawable.h b/src/platform/android/GPUDrawable.h
index 0e7cade712..d82e186b77 100644
--- a/src/platform/android/GPUDrawable.h
+++ b/src/platform/android/GPUDrawable.h
@@ -41,11 +41,11 @@ class GPUDrawable : public Drawable {
void updateSize() override;
- std::shared_ptr getDevice() override;
+ std::shared_ptr getDevice() override;
- std::shared_ptr createSurface(Context* context) override;
+ std::shared_ptr createSurface(tgfx::Context* context) override;
- void present(Context* context) override;
+ void present(tgfx::Context* context) override;
void setTimeStamp(int64_t timeStamp) override;
@@ -55,7 +55,7 @@ class GPUDrawable : public Drawable {
ANativeWindow* nativeWindow = nullptr;
EGLContext sharedContext = nullptr;
int64_t currentTimeStamp = 0;
- std::shared_ptr window = nullptr;
+ std::shared_ptr window = nullptr;
explicit GPUDrawable(ANativeWindow* nativeWindow, EGLContext eglContext = EGL_NO_CONTEXT);
};
diff --git a/src/platform/android/JNIEnvironment.cpp b/src/platform/android/JNIEnvironment.cpp
index c73297fa26..a4718425f2 100644
--- a/src/platform/android/JNIEnvironment.cpp
+++ b/src/platform/android/JNIEnvironment.cpp
@@ -34,7 +34,7 @@ static void JNI_Thread_Destroy(void* value) {
extern "C" jint JNI_OnLoad(JavaVM* vm, void*) {
globalJavaVM = vm;
- pag::SetJavaVM(vm);
+ tgfx::SetJavaVM(vm);
pthread_key_create(&threadKey, JNI_Thread_Destroy);
return JNI_VERSION_1_4;
}
diff --git a/src/platform/android/JNIHelper.cpp b/src/platform/android/JNIHelper.cpp
index 34c5bd3916..57f3ea63fd 100644
--- a/src/platform/android/JNIHelper.cpp
+++ b/src/platform/android/JNIHelper.cpp
@@ -254,27 +254,27 @@ jobject ToPAGVideoRangeObject(JNIEnv* env, const pag::PAGVideoRange& range) {
range.endTime(), range.playDuration(), range.reversed());
}
-pag::ImageInfo GetImageInfo(JNIEnv* env, jobject bitmap) {
+tgfx::ImageInfo GetImageInfo(JNIEnv* env, jobject bitmap) {
AndroidBitmapInfo bitmapInfo = {};
if (bitmap == nullptr || AndroidBitmap_getInfo(env, bitmap, &bitmapInfo) != 0 ||
(bitmapInfo.flags & BITMAP_FLAGS_IS_HARDWARE)) {
return {};
}
- pag::AlphaType alphaType = (bitmapInfo.flags & BITMAP_FLAGS_ALPHA_UNPREMUL)
- ? pag::AlphaType::Unpremultiplied
- : pag::AlphaType::Premultiplied;
- pag::ColorType colorType;
+ tgfx::AlphaType alphaType = (bitmapInfo.flags & BITMAP_FLAGS_ALPHA_UNPREMUL)
+ ? tgfx::AlphaType::Unpremultiplied
+ : tgfx::AlphaType::Premultiplied;
+ tgfx::ColorType colorType;
switch (bitmapInfo.format) {
case ANDROID_BITMAP_FORMAT_RGBA_8888:
- colorType = pag::ColorType::RGBA_8888;
+ colorType = tgfx::ColorType::RGBA_8888;
break;
case ANDROID_BITMAP_FORMAT_A_8:
- colorType = pag::ColorType::ALPHA_8;
+ colorType = tgfx::ColorType::ALPHA_8;
break;
default:
- colorType = pag::ColorType::Unknown;
+ colorType = tgfx::ColorType::Unknown;
break;
}
- return pag::ImageInfo::Make(bitmapInfo.width, bitmapInfo.height, colorType, alphaType,
- bitmapInfo.stride);
+ return tgfx::ImageInfo::Make(bitmapInfo.width, bitmapInfo.height, colorType, alphaType,
+ bitmapInfo.stride);
}
\ No newline at end of file
diff --git a/src/platform/android/JNIHelper.h b/src/platform/android/JNIHelper.h
index 7274b827c0..83c5328213 100644
--- a/src/platform/android/JNIHelper.h
+++ b/src/platform/android/JNIHelper.h
@@ -59,4 +59,4 @@ jobject ToPAGMarkerObject(JNIEnv* env, const pag::Marker* marker);
jobject ToPAGVideoRangeObject(JNIEnv* env, const pag::PAGVideoRange& range);
-pag::ImageInfo GetImageInfo(JNIEnv* env, jobject bitmap);
+tgfx::ImageInfo GetImageInfo(JNIEnv* env, jobject bitmap);
diff --git a/src/platform/android/JPAGImage.cpp b/src/platform/android/JPAGImage.cpp
index 08352a93db..f772917d0e 100644
--- a/src/platform/android/JPAGImage.cpp
+++ b/src/platform/android/JPAGImage.cpp
@@ -23,6 +23,7 @@
#include
#include "JNIHelper.h"
#include "NativePlatform.h"
+#include "base/utils/TGFXCast.h"
namespace pag {
static jfieldID PAGImage_nativeContext;
@@ -78,7 +79,7 @@ JNIEXPORT jlong Java_org_libpag_PAGImage_LoadFromBitmap(JNIEnv* env, jclass, job
return 0;
}
auto pagImage = PAGImage::FromPixels(pixels, info.width(), info.height(), info.rowBytes(),
- info.colorType(), info.alphaType());
+ ToPAG(info.colorType()), ToPAG(info.alphaType()));
AndroidBitmap_unlockPixels(env, bitmap);
if (pagImage == nullptr) {
LOGE("PAGImage.LoadFromPixels() Invalid pixels specified.");
@@ -193,7 +194,7 @@ JNIEXPORT void Java_org_libpag_PAGImage_nativeGetMatrix(JNIEnv* env, jobject thi
auto matrix = image->matrix();
matrix.get9(list);
} else {
- Matrix matrix = {};
+ tgfx::Matrix matrix = {};
matrix.setIdentity();
matrix.get9(list);
}
diff --git a/src/platform/android/JTraceImage.cpp b/src/platform/android/JTraceImage.cpp
index fdea798c90..f6e57cb4fa 100644
--- a/src/platform/android/JTraceImage.cpp
+++ b/src/platform/android/JTraceImage.cpp
@@ -30,7 +30,7 @@ void JTraceImage::InitJNI(JNIEnv* env) {
"(Ljava/lang/String;Ljava/nio/ByteBuffer;II)V");
}
-void JTraceImage::Trace(const ImageInfo& info, const void* pixels, const std::string& tag) {
+void JTraceImage::Trace(const tgfx::ImageInfo& info, const void* pixels, const std::string& tag) {
auto env = JNIEnvironment::Current();
if (env == nullptr || info.isEmpty() || pixels == nullptr) {
return;
@@ -41,9 +41,9 @@ void JTraceImage::Trace(const ImageInfo& info, const void* pixels, const std::st
if (dstPixels == nullptr) {
return;
}
- auto dstInfo = ImageInfo::Make(info.width(), info.height(), ColorType::RGBA_8888,
- AlphaType::Premultiplied, rowBytes);
- Bitmap bitmap(dstInfo, dstPixels);
+ auto dstInfo = tgfx::ImageInfo::Make(info.width(), info.height(), tgfx::ColorType::RGBA_8888,
+ tgfx::AlphaType::Premultiplied, rowBytes);
+ tgfx::Bitmap bitmap(dstInfo, dstPixels);
bitmap.writePixels(info, pixels);
Local byteBuffer = {env, MakeByteBufferObject(env, dstPixels, dstInfo.byteSize())};
Local tagString = {env, SafeConvertToJString(env, tag.c_str())};
diff --git a/src/platform/android/JTraceImage.h b/src/platform/android/JTraceImage.h
index 254a42b401..5a0d3994ad 100644
--- a/src/platform/android/JTraceImage.h
+++ b/src/platform/android/JTraceImage.h
@@ -25,6 +25,6 @@ class JTraceImage {
public:
static void InitJNI(JNIEnv* env);
- static void Trace(const ImageInfo& info, const void* pixels, const std::string& tag);
+ static void Trace(const tgfx::ImageInfo& info, const void* pixels, const std::string& tag);
};
} // namespace pag
diff --git a/src/platform/android/NativePlatform.cpp b/src/platform/android/NativePlatform.cpp
index bde6a860ce..8d19dca760 100644
--- a/src/platform/android/NativePlatform.cpp
+++ b/src/platform/android/NativePlatform.cpp
@@ -62,7 +62,7 @@ bool NativePlatform::registerFallbackFonts() const {
return FontConfigAndroid::RegisterFallbackFonts();
}
-void NativePlatform::traceImage(const ImageInfo& info, const void* pixels,
+void NativePlatform::traceImage(const tgfx::ImageInfo& info, const void* pixels,
const std::string& tag) const {
JTraceImage::Trace(info, pixels, tag);
}
diff --git a/src/platform/android/NativePlatform.h b/src/platform/android/NativePlatform.h
index bad50baa67..6556f58a0c 100644
--- a/src/platform/android/NativePlatform.h
+++ b/src/platform/android/NativePlatform.h
@@ -34,6 +34,7 @@ class NativePlatform : public Platform {
bool registerFallbackFonts() const override;
- void traceImage(const ImageInfo& info, const void* pixels, const std::string& tag) const override;
+ void traceImage(const tgfx::ImageInfo& info, const void* pixels,
+ const std::string& tag) const override;
};
} // namespace pag
diff --git a/src/platform/android/VideoImage.cpp b/src/platform/android/VideoImage.cpp
index c197b9d32a..743a3c1c8b 100644
--- a/src/platform/android/VideoImage.cpp
+++ b/src/platform/android/VideoImage.cpp
@@ -34,7 +34,7 @@ VideoImage::VideoImage(std::shared_ptr videoSurface, int width, in
this->videoSurface->markHasNewTextureImage();
}
-std::shared_ptr VideoImage::makeTexture(Context* context) const {
+std::shared_ptr VideoImage::makeTexture(tgfx::Context* context) const {
std::lock_guard autoLock(locker);
if (!videoSurface->attachToContext(context)) {
return nullptr;
diff --git a/src/platform/android/VideoImage.h b/src/platform/android/VideoImage.h
index 022f59380f..28874109a7 100644
--- a/src/platform/android/VideoImage.h
+++ b/src/platform/android/VideoImage.h
@@ -33,7 +33,7 @@ class VideoImage : public VideoBuffer {
}
protected:
- std::shared_ptr makeTexture(Context* context) const override;
+ std::shared_ptr makeTexture(tgfx::Context* context) const override;
private:
mutable std::mutex locker = {};
diff --git a/src/platform/android/VideoSurface.cpp b/src/platform/android/VideoSurface.cpp
index c3059a8665..86312c263f 100644
--- a/src/platform/android/VideoSurface.cpp
+++ b/src/platform/android/VideoSurface.cpp
@@ -44,10 +44,10 @@ void VideoSurface::InitJNI(JNIEnv* env, const std::string& className) {
VideoSurface_onRelease = env->GetMethodID(VideoSurfaceClass.get(), "onRelease", "()V");
}
-OESTexture::OESTexture(GLTextureInfo info, int width, int height, bool hasAlpha)
- : GLTexture(width, height, ImageOrigin::TopLeft), hasAlpha(hasAlpha) {
+OESTexture::OESTexture(tgfx::GLTextureInfo info, int width, int height, bool hasAlpha)
+ : GLTexture(width, height, tgfx::ImageOrigin::TopLeft), hasAlpha(hasAlpha) {
sampler.glInfo = info;
- sampler.config = PixelConfig::RGBA_8888;
+ sampler.config = tgfx::PixelConfig::RGBA_8888;
}
void OESTexture::setTextureSize(int width, int height) {
@@ -80,7 +80,7 @@ void OESTexture::computeTransform() {
}
}
-Point OESTexture::getTextureCoord(float x, float y) const {
+tgfx::Point OESTexture::getTextureCoord(float x, float y) const {
if (hasAlpha) {
// 如果有 alpha 通道,不需要缩小纹素
return {x / static_cast(textureWidth), y / static_cast(textureHeight)};
@@ -88,9 +88,9 @@ Point OESTexture::getTextureCoord(float x, float y) const {
return {x / static_cast(width()) * sx + tx, y / static_cast(height()) * sy + ty};
}
-void OESTexture::onRelease(pag::Context* context) {
+void OESTexture::onRelease(tgfx::Context* context) {
if (sampler.glInfo.id > 0) {
- auto gl = GLContext::Unwrap(context);
+ auto gl = tgfx::GLContext::Unwrap(context);
gl->deleteTextures(1, &sampler.glInfo.id);
}
}
@@ -126,7 +126,7 @@ jobject VideoSurface::getOutputSurface(JNIEnv* env) const {
return env->CallObjectMethod(videoSurface.get(), VideoSurface_getOutputSurface);
}
-bool VideoSurface::attachToContext(Context* context) {
+bool VideoSurface::attachToContext(tgfx::Context* context) {
if (oesTexture) {
if (deviceID != context->device()->uniqueID()) {
LOGE("VideoSurface::attachToGLContext(): VideoSurface has already attached to a Context!");
@@ -134,12 +134,12 @@ bool VideoSurface::attachToContext(Context* context) {
}
return true;
}
- auto gl = GLContext::Unwrap(context);
- GLTextureInfo glInfo = {};
+ auto gl = tgfx::GLContext::Unwrap(context);
+ tgfx::GLTextureInfo glInfo = {};
glInfo.target = GL::TEXTURE_EXTERNAL_OES;
glInfo.format = GL::RGBA8;
gl->genTextures(1, &glInfo.id);
- oesTexture = Resource::Wrap(context, new OESTexture(glInfo, width, height, hasAlpha));
+ oesTexture = tgfx::Resource::Wrap(context, new OESTexture(glInfo, width, height, hasAlpha));
auto env = JNIEnvironment::Current();
if (env == nullptr) {
return false;
diff --git a/src/platform/android/VideoSurface.h b/src/platform/android/VideoSurface.h
index 80d960dd00..f3eeec80f6 100644
--- a/src/platform/android/VideoSurface.h
+++ b/src/platform/android/VideoSurface.h
@@ -22,18 +22,18 @@
#include "platform/android/Global.h"
namespace pag {
-class OESTexture : public GLTexture {
+class OESTexture : public tgfx::GLTexture {
public:
- OESTexture(GLTextureInfo info, int width, int height, bool hasAlpha);
+ OESTexture(tgfx::GLTextureInfo info, int width, int height, bool hasAlpha);
- Point getTextureCoord(float x, float y) const override;
+ tgfx::Point getTextureCoord(float x, float y) const override;
size_t memoryUsage() const override {
return 0;
}
protected:
- void onRelease(Context* context) override;
+ void onRelease(tgfx::Context* context) override;
private:
void setTextureSize(int width, int height);
@@ -63,7 +63,7 @@ class VideoSurface {
jobject getOutputSurface(JNIEnv* env) const;
- bool attachToContext(Context* context);
+ bool attachToContext(tgfx::Context* context);
bool updateTexImage();
@@ -76,7 +76,7 @@ class VideoSurface {
int width = 0;
int height = 0;
bool hasAlpha = false;
- ID deviceID = 0;
+ uint32_t deviceID = 0;
std::shared_ptr oesTexture = nullptr;
mutable std::atomic_bool hasPendingTextureImage = {false};
diff --git a/src/platform/cocoa/private/CocoaPlatform.h b/src/platform/cocoa/private/CocoaPlatform.h
index 4067430956..19d4653b3a 100644
--- a/src/platform/cocoa/private/CocoaPlatform.h
+++ b/src/platform/cocoa/private/CocoaPlatform.h
@@ -33,6 +33,7 @@ class CocoaPlatform : public Platform {
return NALUType::AVCC;
}
- void traceImage(const ImageInfo& info, const void* pixels, const std::string& tag) const override;
+ void traceImage(const tgfx::ImageInfo& info, const void* pixels,
+ const std::string& tag) const override;
};
} // namespace pag
diff --git a/src/platform/cocoa/private/CocoaPlatform.mm b/src/platform/cocoa/private/CocoaPlatform.mm
index 29590acc02..3edd1806f2 100644
--- a/src/platform/cocoa/private/CocoaPlatform.mm
+++ b/src/platform/cocoa/private/CocoaPlatform.mm
@@ -51,7 +51,7 @@
return true;
}
-void CocoaPlatform::traceImage(const ImageInfo& info, const void* pixels,
+void CocoaPlatform::traceImage(const tgfx::ImageInfo& info, const void* pixels,
const std::string& tag) const {
TraceImage(info, pixels, tag);
}
diff --git a/src/platform/cocoa/private/PAGImageImpl.mm b/src/platform/cocoa/private/PAGImageImpl.mm
index f71577aecb..030a0649dc 100644
--- a/src/platform/cocoa/private/PAGImageImpl.mm
+++ b/src/platform/cocoa/private/PAGImageImpl.mm
@@ -62,7 +62,7 @@ + (PAGImageImpl*)FromPixelBuffer:(CVPixelBufferRef)pixelBuffer {
#else
+ (PAGImageImpl*)FromPixelBuffer:(CVPixelBufferRef)pixelBuffer {
- auto hardwareBuffer = pag::PixelBuffer::MakeFrom(pixelBuffer);
+ auto hardwareBuffer = tgfx::PixelBuffer::MakeFrom(pixelBuffer);
auto image = pag::StillImage::FromPixelBuffer(hardwareBuffer);
if (image == nullptr) {
return nil;
@@ -78,8 +78,8 @@ + (PAGImageImpl*)FromCGImage:(CGImageRef)cgImage {
}
auto width = static_cast(CGImageGetWidth(cgImage));
auto height = static_cast(CGImageGetHeight(cgImage));
- auto pixelBuffer = pag::PixelBuffer::Make(width, height);
- pag::Bitmap bitmap(pixelBuffer);
+ auto pixelBuffer = tgfx::PixelBuffer::Make(width, height);
+ tgfx::Bitmap bitmap(pixelBuffer);
if (bitmap.isEmpty()) {
return nil;
}
diff --git a/src/platform/cocoa/private/TraceImage.h b/src/platform/cocoa/private/TraceImage.h
index 8b27ebb9b7..d3d9ca130d 100644
--- a/src/platform/cocoa/private/TraceImage.h
+++ b/src/platform/cocoa/private/TraceImage.h
@@ -21,5 +21,5 @@
#include "core/ImageInfo.h"
namespace pag {
-void TraceImage(const ImageInfo& info, const void* pixels, const std::string& tag);
+void TraceImage(const tgfx::ImageInfo& info, const void* pixels, const std::string& tag);
}
diff --git a/src/platform/cocoa/private/TraceImage.mm b/src/platform/cocoa/private/TraceImage.mm
index 979ac7fd44..9fc310cdc7 100644
--- a/src/platform/cocoa/private/TraceImage.mm
+++ b/src/platform/cocoa/private/TraceImage.mm
@@ -22,7 +22,7 @@
#include "core/Bitmap.h"
namespace pag {
-void TraceImage(const ImageInfo& info, const void* pixels, const std::string& tag) {
+void TraceImage(const tgfx::ImageInfo& info, const void* pixels, const std::string& tag) {
if (info.isEmpty() || pixels == nullptr) {
return;
}
@@ -34,9 +34,9 @@ void TraceImage(const ImageInfo& info, const void* pixels, const std::string& ta
CVPixelBufferLockBaseAddress(pixelBuffer, 0);
auto dstPixels = CVPixelBufferGetBaseAddress(pixelBuffer);
auto rowBytes = CVPixelBufferGetBytesPerRow(pixelBuffer);
- auto dstInfo = ImageInfo::Make(info.width(), info.height(), ColorType::BGRA_8888,
- AlphaType::Premultiplied, rowBytes);
- Bitmap bitmap(dstInfo, dstPixels);
+ auto dstInfo = tgfx::ImageInfo::Make(info.width(), info.height(), tgfx::ColorType::BGRA_8888,
+ tgfx::AlphaType::Premultiplied, rowBytes);
+ tgfx::Bitmap bitmap(dstInfo, dstPixels);
bitmap.writePixels(info, pixels);
CVPixelBufferUnlockBaseAddress(pixelBuffer, 0);
LOGI("%s : Image(width = %d, height = %d)", tag.c_str(), info.width(), info.height());
diff --git a/src/platform/ios/private/GPUDecoder.h b/src/platform/ios/private/GPUDecoder.h
index ce43712c4f..39820ecc58 100644
--- a/src/platform/ios/private/GPUDecoder.h
+++ b/src/platform/ios/private/GPUDecoder.h
@@ -48,9 +48,9 @@ class GPUDecoder : public VideoDecoder {
private:
VTDecompressionSessionRef session = nullptr;
CMFormatDescriptionRef videoFormatDescription = nullptr;
- YUVColorSpace sourceColorSpace = YUVColorSpace::Rec601;
- YUVColorSpace destinationColorSpace = YUVColorSpace::Rec601;
- YUVColorRange colorRange = YUVColorRange::MPEG;
+ tgfx::YUVColorSpace sourceColorSpace = tgfx::YUVColorSpace::Rec601;
+ tgfx::YUVColorSpace destinationColorSpace = tgfx::YUVColorSpace::Rec601;
+ tgfx::YUVColorRange colorRange = tgfx::YUVColorRange::MPEG;
bool initVideoToolBox(const std::vector>& headers,
const std::string& mimeType);
diff --git a/src/platform/ios/private/GPUDecoder.mm b/src/platform/ios/private/GPUDecoder.mm
index d4f131f27e..e4b5d393e4 100644
--- a/src/platform/ios/private/GPUDecoder.mm
+++ b/src/platform/ios/private/GPUDecoder.mm
@@ -150,7 +150,7 @@ void initParameterSets(const std::vector>& headers,
kCVPixelBufferIOSurfacePropertiesKey};
uint32_t openGLESCompatibility = true;
- uint32_t pixelFormatType = colorRange == YUVColorRange::JPEG
+ uint32_t pixelFormatType = colorRange == tgfx::YUVColorRange::JPEG
? kCVPixelFormatType_420YpCbCr8BiPlanarFullRange
: kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange;
@@ -178,7 +178,7 @@ void initParameterSets(const std::vector>& headers,
CFRelease(ioSurfaceParam);
if (@available(iOS 10.0, *)) {
- if (sourceColorSpace == YUVColorSpace::Rec2020) {
+ if (sourceColorSpace == tgfx::YUVColorSpace::Rec2020) {
CFStringRef destinationColorPrimaries = CFStringCreateWithCString(
kCFAllocatorDefault, "DestinationColorPrimaries", kCFStringEncodingUTF8);
CFStringRef destinationTransferFunction = CFStringCreateWithCString(
@@ -203,7 +203,7 @@ void initParameterSets(const std::vector>& headers,
CFRelease(destinationYCbCrMatrix);
CFRelease(pixelTransferProperties);
- destinationColorSpace = YUVColorSpace::Rec709;
+ destinationColorSpace = tgfx::YUVColorSpace::Rec709;
}
}
diff --git a/src/platform/ios/private/GPUDrawable.h b/src/platform/ios/private/GPUDrawable.h
index 6e5f8c0a8d..9f50d7024e 100644
--- a/src/platform/ios/private/GPUDrawable.h
+++ b/src/platform/ios/private/GPUDrawable.h
@@ -41,11 +41,11 @@ class GPUDrawable : public Drawable {
void updateSize() override;
- std::shared_ptr getDevice() override;
+ std::shared_ptr getDevice() override;
- std::shared_ptr createSurface(Context* context) override;
+ std::shared_ptr createSurface(tgfx::Context* context) override;
- void present(Context* context) override;
+ void present(tgfx::Context* context) override;
CVPixelBufferRef getCVPixelBuffer();
@@ -56,8 +56,8 @@ class GPUDrawable : public Drawable {
CAEAGLLayer* layer = nil;
CVPixelBufferRef pixelBuffer = nil;
EAGLContext* eaglContext = nil;
- std::shared_ptr window = nullptr;
- std::shared_ptr surface = nullptr;
+ std::shared_ptr window = nullptr;
+ std::shared_ptr surface = nullptr;
std::atomic bufferPreparing;
static bool IsInMainThread();
diff --git a/src/platform/ios/private/GPUDrawable.mm b/src/platform/ios/private/GPUDrawable.mm
index 7dc709988f..03f59c1cb0 100644
--- a/src/platform/ios/private/GPUDrawable.mm
+++ b/src/platform/ios/private/GPUDrawable.mm
@@ -88,22 +88,22 @@
surface = nullptr;
}
-std::shared_ptr GPUDrawable::getDevice() {
+std::shared_ptr GPUDrawable::getDevice() {
if (_width <= 0 || _height <= 0) {
return nullptr;
}
if (window == nullptr) {
- auto device = EAGLDevice::MakeAdopted(eaglContext);
+ auto device = tgfx::EAGLDevice::MakeAdopted(eaglContext);
if (pixelBuffer) {
- window = EAGLWindow::MakeFrom(pixelBuffer, device);
+ window = tgfx::EAGLWindow::MakeFrom(pixelBuffer, device);
} else {
- window = EAGLWindow::MakeFrom(layer, device);
+ window = tgfx::EAGLWindow::MakeFrom(layer, device);
}
}
return window ? window->getDevice() : nullptr;
}
-std::shared_ptr GPUDrawable::createSurface(Context* context) {
+std::shared_ptr GPUDrawable::createSurface(tgfx::Context* context) {
if (window == nullptr || bufferPreparing) {
return nullptr;
}
@@ -151,7 +151,7 @@
}
}
-void GPUDrawable::present(Context* context) {
+void GPUDrawable::present(tgfx::Context* context) {
if (window == nullptr) {
return;
}
diff --git a/src/platform/ios/private/VideoImage.h b/src/platform/ios/private/VideoImage.h
index 9076c58ca8..ef51d7b073 100644
--- a/src/platform/ios/private/VideoImage.h
+++ b/src/platform/ios/private/VideoImage.h
@@ -24,22 +24,24 @@ namespace pag {
class VideoImage : public VideoBuffer {
public:
static std::shared_ptr MakeFrom(CVPixelBufferRef pixelBuffer,
- YUVColorSpace colorSpace, YUVColorRange colorRange);
+ tgfx::YUVColorSpace colorSpace,
+ tgfx::YUVColorRange colorRange);
~VideoImage() override;
size_t planeCount() const override;
protected:
- std::shared_ptr makeTexture(Context* context) const override {
- return YUVTexture::MakeFrom(context, _colorSpace, _colorRange, pixelBuffer);
+ std::shared_ptr makeTexture(tgfx::Context* context) const override {
+ return tgfx::YUVTexture::MakeFrom(context, _colorSpace, _colorRange, pixelBuffer);
}
private:
CVPixelBufferRef pixelBuffer = nullptr;
- YUVColorSpace _colorSpace = YUVColorSpace::Rec601;
- YUVColorRange _colorRange = YUVColorRange::MPEG;
+ tgfx::YUVColorSpace _colorSpace = tgfx::YUVColorSpace::Rec601;
+ tgfx::YUVColorRange _colorRange = tgfx::YUVColorRange::MPEG;
- VideoImage(CVPixelBufferRef pixelBuffer, YUVColorSpace colorSpace, YUVColorRange colorRange);
+ VideoImage(CVPixelBufferRef pixelBuffer, tgfx::YUVColorSpace colorSpace,
+ tgfx::YUVColorRange colorRange);
};
} // namespace pag
diff --git a/src/platform/ios/private/VideoImage.mm b/src/platform/ios/private/VideoImage.mm
index a1b38efa02..a9bab229d2 100644
--- a/src/platform/ios/private/VideoImage.mm
+++ b/src/platform/ios/private/VideoImage.mm
@@ -25,8 +25,8 @@
static std::unordered_map> videoImageMap = {};
std::shared_ptr VideoImage::MakeFrom(CVPixelBufferRef pixelBuffer,
- YUVColorSpace colorSpace,
- YUVColorRange colorRange) {
+ tgfx::YUVColorSpace colorSpace,
+ tgfx::YUVColorRange colorRange) {
if (pixelBuffer == nil) {
return nullptr;
}
@@ -50,8 +50,8 @@
return videoImage;
}
-VideoImage::VideoImage(CVPixelBufferRef pixelBuffer, YUVColorSpace colorSpace,
- YUVColorRange colorRange)
+VideoImage::VideoImage(CVPixelBufferRef pixelBuffer, tgfx::YUVColorSpace colorSpace,
+ tgfx::YUVColorRange colorRange)
: VideoBuffer(static_cast(CVPixelBufferGetWidth(pixelBuffer)),
static_cast(CVPixelBufferGetHeight(pixelBuffer))),
pixelBuffer(pixelBuffer),
diff --git a/src/platform/mac/private/GPUDecoder.h b/src/platform/mac/private/GPUDecoder.h
index 96ab7150cc..367d6e7902 100644
--- a/src/platform/mac/private/GPUDecoder.h
+++ b/src/platform/mac/private/GPUDecoder.h
@@ -48,7 +48,7 @@ class GPUDecoder : public VideoDecoder {
private:
VTDecompressionSessionRef session = nullptr;
CMFormatDescriptionRef videoFormatDescription = nullptr;
- YUVColorSpace colorSpace = YUVColorSpace::Rec601;
+ tgfx::YUVColorSpace colorSpace = tgfx::YUVColorSpace::Rec601;
bool initVideoToolBox(const std::vector>& headers,
const std::string& mimeType);
diff --git a/src/platform/mac/private/GPUDecoder.mm b/src/platform/mac/private/GPUDecoder.mm
index bd76f62a67..5c2cea1238 100644
--- a/src/platform/mac/private/GPUDecoder.mm
+++ b/src/platform/mac/private/GPUDecoder.mm
@@ -167,7 +167,7 @@ void initParameterSets(const std::vector>& headers,
CFRelease(openGLCompatibilityValue);
CFRelease(ioSurfaceParam);
- if (colorSpace == YUVColorSpace::Rec2020) {
+ if (colorSpace == tgfx::YUVColorSpace::Rec2020) {
CFMutableDictionaryRef pixelTransferProperties = CFDictionaryCreateMutable(
kCFAllocatorDefault, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
CFDictionarySetValue(pixelTransferProperties,
diff --git a/src/platform/mac/private/GPUDrawable.h b/src/platform/mac/private/GPUDrawable.h
index 92241f4659..21795e592c 100644
--- a/src/platform/mac/private/GPUDrawable.h
+++ b/src/platform/mac/private/GPUDrawable.h
@@ -40,18 +40,18 @@ class GPUDrawable : public Drawable {
void updateSize() override;
- std::shared_ptr getDevice() override;
+ std::shared_ptr getDevice() override;
- std::shared_ptr createSurface(Context* context) override;
+ std::shared_ptr createSurface(tgfx::Context* context) override;
- void present(Context* context) override;
+ void present(tgfx::Context* context) override;
private:
int _width = 0;
int _height = 0;
NSView* view = nil;
CVPixelBufferRef pixelBuffer = nil;
- std::shared_ptr window = nullptr;
+ std::shared_ptr window = nullptr;
explicit GPUDrawable(NSView* view);
explicit GPUDrawable(CVPixelBufferRef pixelBuffer);
diff --git a/src/platform/mac/private/GPUDrawable.mm b/src/platform/mac/private/GPUDrawable.mm
index 8d014342c6..5237868e7e 100644
--- a/src/platform/mac/private/GPUDrawable.mm
+++ b/src/platform/mac/private/GPUDrawable.mm
@@ -68,29 +68,29 @@
_height = static_cast(floor(height));
}
-std::shared_ptr GPUDrawable::getDevice() {
+std::shared_ptr GPUDrawable::getDevice() {
if (_width <= 0 || _height <= 0) {
return nullptr;
}
if (window == nullptr) {
if (pixelBuffer) {
- auto device = std::static_pointer_cast(GLDevice::Make());
- window = CGLWindow::MakeFrom(pixelBuffer, device);
+ auto device = std::static_pointer_cast(tgfx::GLDevice::Make());
+ window = tgfx::CGLWindow::MakeFrom(pixelBuffer, device);
} else {
- window = CGLWindow::MakeFrom(view);
+ window = tgfx::CGLWindow::MakeFrom(view);
}
}
return window ? window->getDevice() : nullptr;
}
-std::shared_ptr GPUDrawable::createSurface(Context* context) {
+std::shared_ptr GPUDrawable::createSurface(tgfx::Context* context) {
if (window == nullptr) {
return nullptr;
}
return window->createSurface(context);
}
-void GPUDrawable::present(Context* context) {
+void GPUDrawable::present(tgfx::Context* context) {
if (window == nullptr) {
return;
}
diff --git a/src/platform/mac/private/VideoImage.h b/src/platform/mac/private/VideoImage.h
index 82ea45eef8..108c5780ef 100644
--- a/src/platform/mac/private/VideoImage.h
+++ b/src/platform/mac/private/VideoImage.h
@@ -30,8 +30,8 @@ class VideoImage : public VideoBuffer {
size_t planeCount() const override;
protected:
- std::shared_ptr makeTexture(Context* context) const override {
- return Texture::MakeFrom(context, pixelBuffer);
+ std::shared_ptr makeTexture(tgfx::Context* context) const override {
+ return tgfx::Texture::MakeFrom(context, pixelBuffer);
}
private:
diff --git a/src/platform/qt/GPUDrawable.cpp b/src/platform/qt/GPUDrawable.cpp
index 82c45c1aca..d072213e24 100644
--- a/src/platform/qt/GPUDrawable.cpp
+++ b/src/platform/qt/GPUDrawable.cpp
@@ -24,14 +24,14 @@
namespace pag {
std::shared_ptr GPUDrawable::MakeFrom(QQuickItem* quickItem,
QOpenGLContext* sharedContext) {
- auto window = QGLWindow::MakeFrom(quickItem, sharedContext);
+ auto window = tgfx::QGLWindow::MakeFrom(quickItem, sharedContext);
if (window == nullptr) {
return nullptr;
}
return std::shared_ptr(new GPUDrawable(quickItem, std::move(window)));
}
-GPUDrawable::GPUDrawable(QQuickItem* quickItem, std::shared_ptr window)
+GPUDrawable::GPUDrawable(QQuickItem* quickItem, std::shared_ptr window)
: quickItem(quickItem), window(std::move(window)) {
GPUDrawable::updateSize();
}
@@ -43,18 +43,18 @@ void GPUDrawable::updateSize() {
_height = static_cast(ceil(quickItem->height() * pixelRatio));
}
-std::shared_ptr GPUDrawable::getDevice() {
+std::shared_ptr GPUDrawable::getDevice() {
if (_width <= 0 || _height <= 0) {
return nullptr;
}
return window->getDevice();
}
-std::shared_ptr GPUDrawable::createSurface(Context* context) {
+std::shared_ptr GPUDrawable::createSurface(tgfx::Context* context) {
return window->createSurface(context);
}
-void GPUDrawable::present(Context* context) {
+void GPUDrawable::present(tgfx::Context* context) {
window->present(context);
}
diff --git a/src/platform/qt/GPUDrawable.h b/src/platform/qt/GPUDrawable.h
index be9ed0440f..87df32b02e 100644
--- a/src/platform/qt/GPUDrawable.h
+++ b/src/platform/qt/GPUDrawable.h
@@ -26,9 +26,11 @@
#pragma clang diagnostic pop
#include "pag/pag.h"
-namespace pag {
+namespace tgfx {
class QGLWindow;
+}
+namespace pag {
class GPUDrawable : public Drawable {
public:
static std::shared_ptr MakeFrom(QQuickItem* quickItem,
@@ -44,11 +46,11 @@ class GPUDrawable : public Drawable {
void updateSize() override;
- std::shared_ptr getDevice() override;
+ std::shared_ptr getDevice() override;
- std::shared_ptr createSurface(Context* context) override;
+ std::shared_ptr createSurface(tgfx::Context* context) override;
- void present(Context* context) override;
+ void present(tgfx::Context* context) override;
void moveToThread(QThread* targetThread);
@@ -58,8 +60,8 @@ class GPUDrawable : public Drawable {
int _width = 0;
int _height = 0;
QQuickItem* quickItem = nullptr;
- std::shared_ptr window = nullptr;
+ std::shared_ptr window = nullptr;
- GPUDrawable(QQuickItem* quickItem, std::shared_ptr window);
+ GPUDrawable(QQuickItem* quickItem, std::shared_ptr window);
};
} // namespace pag
diff --git a/src/platform/swiftshader/NativePlatform.cpp b/src/platform/swiftshader/NativePlatform.cpp
index c05220e986..f517ca8e0f 100644
--- a/src/platform/swiftshader/NativePlatform.cpp
+++ b/src/platform/swiftshader/NativePlatform.cpp
@@ -37,7 +37,7 @@ void NativePlatform::setNALUType(NALUType type) const {
defaultType = type;
}
-void NativePlatform::traceImage(const ImageInfo& info, const void* pixels,
+void NativePlatform::traceImage(const tgfx::ImageInfo& info, const void* pixels,
const std::string& tag) const {
std::string path = tag;
if (path.empty()) {
@@ -45,7 +45,7 @@ void NativePlatform::traceImage(const ImageInfo& info, const void* pixels,
} else if (path.rfind(".png") != path.size() - 4 && path.rfind(".PNG") != path.size() - 4) {
path += ".png";
}
- auto bytes = Bitmap(info, pixels).encode(EncodedFormat::PNG, 100);
+ auto bytes = tgfx::Bitmap(info, pixels).encode(tgfx::EncodedFormat::PNG, 100);
if (bytes) {
std::ofstream out(path);
out.write(reinterpret_cast(bytes->data()), bytes->size());
diff --git a/src/platform/swiftshader/NativePlatform.h b/src/platform/swiftshader/NativePlatform.h
index 9c99b65692..66ac42b7d3 100644
--- a/src/platform/swiftshader/NativePlatform.h
+++ b/src/platform/swiftshader/NativePlatform.h
@@ -27,6 +27,7 @@ class NativePlatform : public Platform {
void setNALUType(NALUType type) const;
- void traceImage(const ImageInfo& info, const void* pixels, const std::string& tag) const override;
+ void traceImage(const tgfx::ImageInfo& info, const void* pixels,
+ const std::string& tag) const override;
};
} // namespace pag
diff --git a/src/platform/web/GPUDrawable.cpp b/src/platform/web/GPUDrawable.cpp
index 7b94b92867..eeacd540a1 100644
--- a/src/platform/web/GPUDrawable.cpp
+++ b/src/platform/web/GPUDrawable.cpp
@@ -40,17 +40,17 @@ void GPUDrawable::updateSize() {
}
}
-std::shared_ptr GPUDrawable::getDevice() {
+std::shared_ptr GPUDrawable::getDevice() {
if (_width <= 0 || _height <= 0) {
return nullptr;
}
if (window == nullptr) {
- window = WebGLWindow::MakeFrom(canvasID);
+ window = tgfx::WebGLWindow::MakeFrom(canvasID);
}
return window->getDevice();
}
-std::shared_ptr GPUDrawable::createSurface(Context* context) {
+std::shared_ptr GPUDrawable::createSurface(tgfx::Context* context) {
return window ? window->createSurface(context) : nullptr;
}
} // namespace pag
diff --git a/src/platform/web/GPUDrawable.h b/src/platform/web/GPUDrawable.h
index a5738282d5..cece968c7f 100644
--- a/src/platform/web/GPUDrawable.h
+++ b/src/platform/web/GPUDrawable.h
@@ -18,7 +18,7 @@
#pragma once
-#include "gpu/opengl/webgl//WebGLWindow.h"
+#include "gpu/opengl/webgl/WebGLWindow.h"
#include "pag/pag.h"
namespace pag {
@@ -36,11 +36,11 @@ class GPUDrawable : public Drawable {
void updateSize() override;
- std::shared_ptr getDevice() override;
+ std::shared_ptr getDevice() override;
- std::shared_ptr createSurface(Context* context) override;
+ std::shared_ptr createSurface(tgfx::Context* context) override;
- void present(Context*) override {
+ void present(tgfx::Context*) override {
}
private:
@@ -49,6 +49,6 @@ class GPUDrawable : public Drawable {
std::string canvasID;
int _width = 0;
int _height = 0;
- std::shared_ptr window = nullptr;
+ std::shared_ptr window = nullptr;
};
} // namespace pag
diff --git a/src/platform/web/NativePlatform.cpp b/src/platform/web/NativePlatform.cpp
index 8015fcef01..3a1ef9cafa 100644
--- a/src/platform/web/NativePlatform.cpp
+++ b/src/platform/web/NativePlatform.cpp
@@ -27,7 +27,7 @@ const Platform* Platform::Current() {
return &platform;
}
-void NativePlatform::traceImage(const ImageInfo& info, const void* pixels,
+void NativePlatform::traceImage(const tgfx::ImageInfo& info, const void* pixels,
const std::string& tag) const {
auto traceImage = val::module_property("traceImage");
auto bytes = val(typed_memory_view(info.byteSize(), static_cast(pixels)));
diff --git a/src/platform/web/NativePlatform.h b/src/platform/web/NativePlatform.h
index f8b1227f77..2ae7fe5e5a 100644
--- a/src/platform/web/NativePlatform.h
+++ b/src/platform/web/NativePlatform.h
@@ -23,6 +23,7 @@
namespace pag {
class NativePlatform : public Platform {
public:
- void traceImage(const ImageInfo& info, const void* pixels, const std::string& tag) const override;
+ void traceImage(const tgfx::ImageInfo& info, const void* pixels,
+ const std::string& tag) const override;
};
} // namespace pag
diff --git a/src/platform/web/VideoSequenceReader.cpp b/src/platform/web/VideoSequenceReader.cpp
index 1b9deddabd..d1d7d02ac1 100644
--- a/src/platform/web/VideoSequenceReader.cpp
+++ b/src/platform/web/VideoSequenceReader.cpp
@@ -73,18 +73,19 @@ void VideoSequenceReader::prepareAsync(Frame targetFrame) {
}
}
-std::shared_ptr VideoSequenceReader::readTexture(Frame targetFrame, RenderCache* cache) {
+std::shared_ptr VideoSequenceReader::readTexture(Frame targetFrame,
+ RenderCache* cache) {
if (!videoReader.as()) {
return nullptr;
}
if (targetFrame == lastFrame) {
return texture;
}
- GLStateGuard stateGuard(cache->getContext());
+ tgfx::GLStateGuard stateGuard(cache->getContext());
if (texture == nullptr) {
- texture = GLTexture::MakeRGBA(cache->getContext(), width, height);
+ texture = tgfx::GLTexture::MakeRGBA(cache->getContext(), width, height);
}
- auto& glInfo = std::static_pointer_cast(texture)->getGLInfo();
+ auto& glInfo = std::static_pointer_cast(texture)->getGLInfo();
videoReader.call("renderToTexture", val::module_property("GL"), glInfo.id);
lastFrame = targetFrame;
return texture;
diff --git a/src/platform/web/VideoSequenceReader.h b/src/platform/web/VideoSequenceReader.h
index d48f976a7a..a70b65035b 100644
--- a/src/platform/web/VideoSequenceReader.h
+++ b/src/platform/web/VideoSequenceReader.h
@@ -30,12 +30,12 @@ class VideoSequenceReader : public SequenceReader {
void prepareAsync(Frame targetFrame) override;
- std::shared_ptr readTexture(Frame targetFrame, RenderCache* cache) override;
+ std::shared_ptr readTexture(Frame targetFrame, RenderCache* cache) override;
private:
Frame lastFrame = -1;
emscripten::val videoReader = emscripten::val::null();
- std::shared_ptr texture = nullptr;
+ std::shared_ptr texture = nullptr;
int32_t width = 0;
int32_t height = 0;
};
diff --git a/src/platform/win/GPUDrawable.cpp b/src/platform/win/GPUDrawable.cpp
index a329b6ddaf..040cb03c41 100644
--- a/src/platform/win/GPUDrawable.cpp
+++ b/src/platform/win/GPUDrawable.cpp
@@ -48,22 +48,22 @@ void GPUDrawable::updateSize() {
}
}
-std::shared_ptr GPUDrawable::getDevice() {
+std::shared_ptr GPUDrawable::getDevice() {
if (_width <= 0 || _height <= 0) {
return nullptr;
}
if (window == nullptr) {
- window =
- EGLWindow::MakeFrom(reinterpret_cast(nativeWindow), sharedContext);
+ window = tgfx::EGLWindow::MakeFrom(reinterpret_cast(nativeWindow),
+ sharedContext);
}
return window ? window->getDevice() : nullptr;
}
-std::shared_ptr GPUDrawable::createSurface(Context* context) {
+std::shared_ptr GPUDrawable::createSurface(tgfx::Context* context) {
return window ? window->createSurface(context) : nullptr;
}
-void GPUDrawable::present(Context* context) {
+void GPUDrawable::present(tgfx::Context* context) {
window->present(context);
}
} // namespace pag
diff --git a/src/platform/win/GPUDrawable.h b/src/platform/win/GPUDrawable.h
index 489f7a6e7b..7504898ca3 100644
--- a/src/platform/win/GPUDrawable.h
+++ b/src/platform/win/GPUDrawable.h
@@ -20,9 +20,11 @@
#include "pag/pag.h"
-namespace pag {
+namespace tgfx {
class EGLWindow;
+}
+namespace pag {
class GPUDrawable : public Drawable {
public:
static std::shared_ptr FromWindow(void* nativeWindow, void* sharedContext = nullptr);
@@ -37,16 +39,16 @@ class GPUDrawable : public Drawable {
void updateSize() override;
- std::shared_ptr getDevice() override;
+ std::shared_ptr getDevice() override;
- std::shared_ptr createSurface(Context* context) override;
+ std::shared_ptr createSurface(tgfx::Context* context) override;
- void present(Context* context) override;
+ void present(tgfx::Context* context) override;
private:
int _width = 0;
int _height = 0;
- std::shared_ptr window = nullptr;
+ std::shared_ptr window = nullptr;
void* nativeWindow = nullptr;
void* sharedContext = nullptr;
diff --git a/src/rendering/Drawable.cpp b/src/rendering/Drawable.cpp
index 3be4787de0..0b899de9d0 100644
--- a/src/rendering/Drawable.cpp
+++ b/src/rendering/Drawable.cpp
@@ -17,32 +17,33 @@
/////////////////////////////////////////////////////////////////////////////////////////////////
#include "Drawable.h"
+#include "base/utils/TGFXCast.h"
namespace pag {
-RenderTargetDrawable::RenderTargetDrawable(std::shared_ptr device,
- const BackendRenderTarget& renderTarget,
- ImageOrigin origin)
+RenderTargetDrawable::RenderTargetDrawable(std::shared_ptr device,
+ const tgfx::BackendRenderTarget& renderTarget,
+ tgfx::ImageOrigin origin)
: device(std::move(device)), renderTarget(renderTarget), origin(origin) {
}
-std::shared_ptr RenderTargetDrawable::createSurface(Context* context) {
- return Surface::MakeFrom(context, renderTarget, origin);
+std::shared_ptr RenderTargetDrawable::createSurface(tgfx::Context* context) {
+ return tgfx::Surface::MakeFrom(context, renderTarget, origin);
}
-TextureDrawable::TextureDrawable(std::shared_ptr device, const BackendTexture& texture,
- ImageOrigin origin)
+TextureDrawable::TextureDrawable(std::shared_ptr device,
+ const tgfx::BackendTexture& texture, tgfx::ImageOrigin origin)
: device(std::move(device)), texture(texture), origin(origin) {
}
-std::shared_ptr TextureDrawable::createSurface(Context* context) {
- return Surface::MakeFrom(context, texture, origin);
+std::shared_ptr TextureDrawable::createSurface(tgfx::Context* context) {
+ return tgfx::Surface::MakeFrom(context, texture, origin);
}
-OffscreenDrawable::OffscreenDrawable(int width, int height, std::shared_ptr device)
+OffscreenDrawable::OffscreenDrawable(int width, int height, std::shared_ptr device)
: _width(width), _height(height), device(std::move(device)) {
}
-std::shared_ptr OffscreenDrawable::createSurface(Context* context) {
- return Surface::Make(context, _width, _height);
+std::shared_ptr OffscreenDrawable::createSurface(tgfx::Context* context) {
+ return tgfx::Surface::Make(context, _width, _height);
}
} // namespace pag
\ No newline at end of file
diff --git a/src/rendering/Drawable.h b/src/rendering/Drawable.h
index 27dcfad125..b29bd5ffeb 100644
--- a/src/rendering/Drawable.h
+++ b/src/rendering/Drawable.h
@@ -24,8 +24,8 @@
namespace pag {
class RenderTargetDrawable : public Drawable {
public:
- RenderTargetDrawable(std::shared_ptr device, const BackendRenderTarget& renderTarget,
- ImageOrigin origin);
+ RenderTargetDrawable(std::shared_ptr device,
+ const tgfx::BackendRenderTarget& renderTarget, tgfx::ImageOrigin origin);
int width() const override {
return renderTarget.width();
@@ -38,25 +38,25 @@ class RenderTargetDrawable : public Drawable {
void updateSize() override {
}
- std::shared_ptr getDevice() override {
+ std::shared_ptr getDevice() override {
return device;
}
- std::shared_ptr createSurface(Context* context) override;
+ std::shared_ptr createSurface(tgfx::Context* context) override;
- void present(Context*) override {
+ void present(tgfx::Context*) override {
}
private:
- std::shared_ptr device = nullptr;
- BackendRenderTarget renderTarget = {};
- ImageOrigin origin = ImageOrigin::TopLeft;
+ std::shared_ptr device = nullptr;
+ tgfx::BackendRenderTarget renderTarget = {};
+ tgfx::ImageOrigin origin = tgfx::ImageOrigin::TopLeft;
};
class TextureDrawable : public Drawable {
public:
- TextureDrawable(std::shared_ptr device, const BackendTexture& texture,
- ImageOrigin origin);
+ TextureDrawable(std::shared_ptr device, const tgfx::BackendTexture& texture,
+ tgfx::ImageOrigin origin);
int width() const override {
return texture.width();
@@ -69,24 +69,24 @@ class TextureDrawable : public Drawable {
void updateSize() override {
}
- std::shared_ptr getDevice() override {
+ std::shared_ptr getDevice() override {
return device;
}
- std::shared_ptr createSurface(Context* context) override;
+ std::shared_ptr createSurface(tgfx::Context* context) override;
- void present(Context*) override {
+ void present(tgfx::Context*) override {
}
private:
- std::shared_ptr device = nullptr;
- BackendTexture texture = {};
- ImageOrigin origin = ImageOrigin::TopLeft;
+ std::shared_ptr device = nullptr;
+ tgfx::BackendTexture texture = {};
+ tgfx::ImageOrigin origin = tgfx::ImageOrigin::TopLeft;
};
class OffscreenDrawable : public Drawable {
public:
- OffscreenDrawable(int width, int height, std::shared_ptr device);
+ OffscreenDrawable(int width, int height, std::shared_ptr device);
int width() const override {
return _width;
@@ -99,18 +99,18 @@ class OffscreenDrawable : public Drawable {
void updateSize() override {
}
- std::shared_ptr getDevice() override {
+ std::shared_ptr getDevice() override {
return device;
}
- std::shared_ptr createSurface(Context* context) override;
+ std::shared_ptr createSurface(tgfx::Context* context) override;
- void present(Context*) override {
+ void present(tgfx::Context*) override {
}
private:
int _width = 0;
int _height = 0;
- std::shared_ptr device = nullptr;
+ std::shared_ptr device = nullptr;
};
} // namespace pag
diff --git a/src/rendering/FontManager.cpp b/src/rendering/FontManager.cpp
index 0b7f73d734..6d7ea82cc9 100644
--- a/src/rendering/FontManager.cpp
+++ b/src/rendering/FontManager.cpp
@@ -38,12 +38,12 @@ std::shared_ptr TypefaceHolder::MakeFromFile(const std::string&
return std::shared_ptr(holder);
}
-std::shared_ptr TypefaceHolder::getTypeface() {
+std::shared_ptr TypefaceHolder::getTypeface() {
if (typeface == nullptr) {
if (!fontPath.empty()) {
- typeface = Typeface::MakeFromPath(fontPath, ttcIndex);
+ typeface = tgfx::Typeface::MakeFromPath(fontPath, ttcIndex);
} else {
- typeface = Typeface::MakeFromName(fontFamily, fontStyle);
+ typeface = tgfx::Typeface::MakeFromName(fontFamily, fontStyle);
}
}
return typeface;
@@ -62,14 +62,14 @@ bool FontManager::hasFallbackFonts() {
PAGFont FontManager::registerFont(const std::string& fontPath, int ttcIndex,
const std::string& fontFamily, const std::string& fontStyle) {
std::lock_guard autoLock(locker);
- auto typeface = Typeface::MakeFromPath(fontPath, ttcIndex);
+ auto typeface = tgfx::Typeface::MakeFromPath(fontPath, ttcIndex);
return registerFont(typeface, fontFamily, fontStyle);
}
PAGFont FontManager::registerFont(const void* data, size_t length, int ttcIndex,
const std::string& fontFamily, const std::string& fontStyle) {
std::lock_guard autoLock(locker);
- auto typeface = Typeface::MakeFromBytes(data, length, ttcIndex);
+ auto typeface = tgfx::Typeface::MakeFromBytes(data, length, ttcIndex);
return registerFont(typeface, fontFamily, fontStyle);
}
@@ -77,8 +77,8 @@ static std::string PAGFontRegisterKey(const std::string& fontFamily, const std::
return fontFamily + "|" + fontStyle;
}
-PAGFont FontManager::registerFont(std::shared_ptr typeface, const std::string& fontFamily,
- const std::string& fontStyle) {
+PAGFont FontManager::registerFont(std::shared_ptr typeface,
+ const std::string& fontFamily, const std::string& fontStyle) {
if (typeface == nullptr) {
return {"", ""};
}
@@ -105,9 +105,9 @@ void FontManager::unregisterFont(const PAGFont& font) {
registeredFontMap.erase(iter);
}
-static std::shared_ptr MakeTypefaceWithName(const std::string& fontFamily,
- const std::string& fontStyle) {
- auto typeface = Typeface::MakeFromName(fontFamily, fontStyle);
+static std::shared_ptr MakeTypefaceWithName(const std::string& fontFamily,
+ const std::string& fontStyle) {
+ auto typeface = tgfx::Typeface::MakeFromName(fontFamily, fontStyle);
if (typeface != nullptr) {
if (fontFamily != typeface->fontFamily()) {
typeface = nullptr;
@@ -116,9 +116,9 @@ static std::shared_ptr MakeTypefaceWithName(const std::string& fontFam
return typeface;
}
-std::shared_ptr FontManager::getTypefaceWithoutFallback(const std::string& fontFamily,
- const std::string& fontStyle) {
- std::shared_ptr typeface = getTypefaceFromCache(fontFamily, fontStyle);
+std::shared_ptr FontManager::getTypefaceWithoutFallback(
+ const std::string& fontFamily, const std::string& fontStyle) {
+ std::shared_ptr typeface = getTypefaceFromCache(fontFamily, fontStyle);
if (typeface == nullptr) {
typeface = MakeTypefaceWithName(fontFamily, fontStyle);
}
@@ -133,8 +133,8 @@ std::shared_ptr FontManager::getTypefaceWithoutFallback(const std::str
return typeface;
}
-std::shared_ptr FontManager::getFallbackTypeface(const std::string& name,
- GlyphID* glyphID) {
+std::shared_ptr FontManager::getFallbackTypeface(const std::string& name,
+ tgfx::GlyphID* glyphID) {
std::lock_guard autoLock(locker);
for (auto& holder : fallbackFontList) {
auto typeface = holder->getTypeface();
@@ -145,7 +145,7 @@ std::shared_ptr FontManager::getFallbackTypeface(const std::string& na
}
}
}
- return Typeface::MakeDefault();
+ return tgfx::Typeface::MakeDefault();
}
void FontManager::setFallbackFontNames(const std::vector& fontNames) {
@@ -169,8 +169,8 @@ void FontManager::setFallbackFontPaths(const std::vector& fontPaths
}
}
-std::shared_ptr FontManager::getTypefaceFromCache(const std::string& fontFamily,
- const std::string& fontStyle) {
+std::shared_ptr FontManager::getTypefaceFromCache(const std::string& fontFamily,
+ const std::string& fontStyle) {
std::lock_guard autoLock(locker);
auto result = registeredFontMap.find(PAGFontRegisterKey(fontFamily, fontStyle));
if (result != registeredFontMap.end()) {
@@ -181,8 +181,8 @@ std::shared_ptr FontManager::getTypefaceFromCache(const std::string& f
static FontManager fontManager = {};
-std::shared_ptr FontManager::GetTypefaceWithoutFallback(const std::string& fontFamily,
- const std::string& fontStyle) {
+std::shared_ptr FontManager::GetTypefaceWithoutFallback(
+ const std::string& fontFamily, const std::string& fontStyle) {
return fontManager.getTypefaceWithoutFallback(fontFamily, fontStyle);
}
@@ -193,8 +193,8 @@ static bool RegisterFallbackFonts() {
return Platform::Current()->registerFallbackFonts();
}
-std::shared_ptr FontManager::GetFallbackTypeface(const std::string& name,
- GlyphID* glyphID) {
+std::shared_ptr FontManager::GetFallbackTypeface(const std::string& name,
+ tgfx::GlyphID* glyphID) {
static auto registered = RegisterFallbackFonts();
USE(registered);
return fontManager.getFallbackTypeface(name, glyphID);
diff --git a/src/rendering/FontManager.h b/src/rendering/FontManager.h
index 9e74c2c140..a17d5eb8dd 100644
--- a/src/rendering/FontManager.h
+++ b/src/rendering/FontManager.h
@@ -23,7 +23,6 @@
#include "pag/pag.h"
namespace pag {
-
class TypefaceHolder {
public:
static std::shared_ptr MakeFromName(const std::string& fontFamily,
@@ -32,21 +31,22 @@ class TypefaceHolder {
static std::shared_ptr MakeFromFile(const std::string& fontPath,
int ttcIndex = 0);
- std::shared_ptr getTypeface();
+ std::shared_ptr getTypeface();
private:
std::string fontFamily;
std::string fontStyle;
std::string fontPath;
int ttcIndex = 0;
- std::shared_ptr typeface = nullptr;
+ std::shared_ptr typeface = nullptr;
};
class FontManager {
public:
- static std::shared_ptr GetTypefaceWithoutFallback(const std::string& fontFamily,
- const std::string& fontStyle);
- static std::shared_ptr GetFallbackTypeface(const std::string& name, GlyphID* glyphID);
+ static std::shared_ptr GetTypefaceWithoutFallback(const std::string& fontFamily,
+ const std::string& fontStyle);
+ static std::shared_ptr GetFallbackTypeface(const std::string& name,
+ tgfx::GlyphID* glyphID);
static PAGFont RegisterFont(const std::string& fontPath, int ttcIndex,
const std::string& fontFamily, const std::string& fontStyle);
@@ -72,27 +72,28 @@ class FontManager {
PAGFont registerFont(const void* data, size_t length, int ttcIndex = 0,
const std::string& fontFamily = "", const std::string& fontStyle = "");
- PAGFont registerFont(std::shared_ptr typeface, const std::string& fontFamily = "",
+ PAGFont registerFont(std::shared_ptr typeface, const std::string& fontFamily = "",
const std::string& fontStyle = "");
void unregisterFont(const PAGFont& font);
- std::shared_ptr getTypefaceWithoutFallback(const std::string& fontFamily,
- const std::string& fontStyle);
+ std::shared_ptr getTypefaceWithoutFallback(const std::string& fontFamily,
+ const std::string& fontStyle);
- std::shared_ptr getFallbackTypeface(const std::string& name, GlyphID* glyphID);
+ std::shared_ptr getFallbackTypeface(const std::string& name,
+ tgfx::GlyphID* glyphID);
void setFallbackFontNames(const std::vector& fontNames);
void setFallbackFontPaths(const std::vector