Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename the namespace of the 2d rendering engine to tgfx. #114

Merged
merged 2 commits into from
Feb 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
7 changes: 6 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ endif ()

if (MSVC)
add_compile_options("/utf-8")
add_compile_options(/w44251 /w44275)
endif (MSVC)

# Sets flags
Expand Down
44 changes: 21 additions & 23 deletions include/pag/pag.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,25 @@
#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 {
public:
virtual ~Content() = default;

protected:
virtual void measureBounds(Rect* bounds) = 0;
virtual void measureBounds(tgfx::Rect* bounds) = 0;

virtual void draw(Recorder* recorder) = 0;

Expand All @@ -57,8 +63,6 @@ class Content {
friend class PAGTextLayer;
};

class Image;

/**
* A still image used to replace the image contents in a PAGFile.
*/
Expand Down Expand Up @@ -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<Image> getImage() const {
virtual std::shared_ptr<tgfx::Image> getImage() const {
return nullptr;
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -758,7 +762,7 @@ class PAG_API PAGImageLayer : public PAGLayer {
static Frame ScaleTimeRemap(AnimatableProperty<float>* 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;

Expand Down Expand Up @@ -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;
Expand All @@ -932,7 +936,7 @@ class PAG_API PAGComposition : public PAGLayer {
static void FindLayers(std::function<bool(PAGLayer* pagLayer)> filterFunc,
std::vector<std::shared_ptr<PAGLayer>>* result,
std::shared_ptr<PAGLayer> 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<std::shared_ptr<PAGLayer>>* results);
Expand Down Expand Up @@ -1093,12 +1097,6 @@ class Composition;

class PAGPlayer;

class Context;

class Surface;

class Device;

class Drawable {
public:
virtual ~Drawable() = default;
Expand All @@ -1121,18 +1119,18 @@ class Drawable {
/**
* Returns the GPU device associated with this drawable.
*/
virtual std::shared_ptr<Device> getDevice() = 0;
virtual std::shared_ptr<tgfx::Device> getDevice() = 0;

/**
* Creates a new Surface from this drawable.
*/
virtual std::shared_ptr<Surface> createSurface(Context* context) = 0;
virtual std::shared_ptr<tgfx::Surface> 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
Expand Down Expand Up @@ -1212,15 +1210,15 @@ class PAG_API PAGSurface {
PAGPlayer* pagPlayer = nullptr;
std::shared_ptr<std::mutex> rootLocker = nullptr;
std::shared_ptr<Drawable> drawable = nullptr;
std::shared_ptr<Device> device = nullptr;
std::shared_ptr<Surface> surface = nullptr;
std::shared_ptr<tgfx::Device> device = nullptr;
std::shared_ptr<tgfx::Surface> surface = nullptr;

explicit PAGSurface(std::shared_ptr<Drawable> drawable);

bool draw(RenderCache* cache, std::shared_ptr<Graphic> graphic, BackendSemaphore* signalSemaphore,
bool autoClear = true);
bool hitTest(RenderCache* cache, std::shared_ptr<Graphic> graphic, float x, float y);
Context* lockContext();
tgfx::Context* lockContext();
void unlockContext();
bool wait(const BackendSemaphore& waitSemaphore);

Expand Down
73 changes: 8 additions & 65 deletions include/pag/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
};

/***
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;
};

/**
Expand Down
2 changes: 1 addition & 1 deletion src/base/ByteData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

namespace pag {
std::unique_ptr<ByteData> ByteData::FromPath(const std::string& filePath) {
auto stream = Stream::MakeFromFile(filePath);
auto stream = tgfx::Stream::MakeFromFile(filePath);
if (stream == nullptr) {
return nullptr;
}
Expand Down
Loading