Skip to content

Commit

Permalink
Merge GLFragmentProcessor into FragmentProcessor.
Browse files Browse the repository at this point in the history
  • Loading branch information
domchen committed Oct 6, 2023
1 parent b48dec2 commit 0b04e16
Show file tree
Hide file tree
Showing 92 changed files with 835 additions and 1,083 deletions.
9 changes: 0 additions & 9 deletions tgfx/src/gpu/AARectEffect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,9 @@
/////////////////////////////////////////////////////////////////////////////////////////////////

#include "AARectEffect.h"
#include "opengl/GLAARectEffect.h"

namespace tgfx {
std::unique_ptr<AARectEffect> AARectEffect::Make(const Rect& rect) {
return std::unique_ptr<AARectEffect>(new AARectEffect(rect));
}

bool AARectEffect::onIsEqual(const FragmentProcessor& processor) const {
return rect == static_cast<const AARectEffect&>(processor).rect;
}

std::unique_ptr<GLFragmentProcessor> AARectEffect::onCreateGLInstance() const {
return std::make_unique<GLAARectEffect>();
}
} // namespace tgfx
6 changes: 1 addition & 5 deletions tgfx/src/gpu/AARectEffect.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,14 @@ class AARectEffect : public FragmentProcessor {
return "AARectEffect";
}

private:
protected:
DEFINE_PROCESSOR_CLASS_ID

explicit AARectEffect(const Rect& rect) : FragmentProcessor(ClassID()), rect(rect) {
}

bool onIsEqual(const FragmentProcessor& processor) const override;

std::unique_ptr<GLFragmentProcessor> onCreateGLInstance() const override;

Rect rect = Rect::MakeEmpty();

friend class GLAARectEffect;
};
} // namespace tgfx
10 changes: 0 additions & 10 deletions tgfx/src/gpu/ColorMatrixFragmentProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,9 @@
/////////////////////////////////////////////////////////////////////////////////////////////////

#include "gpu/ColorMatrixFragmentProcessor.h"
#include "opengl/GLColorMatrixFragmentProcessor.h"

namespace tgfx {
std::unique_ptr<ColorMatrixFragmentProcessor> ColorMatrixFragmentProcessor::Make(
const std::array<float, 20>& matrix) {
return std::unique_ptr<ColorMatrixFragmentProcessor>(new ColorMatrixFragmentProcessor(matrix));
}

bool ColorMatrixFragmentProcessor::onIsEqual(const FragmentProcessor& processor) const {
return matrix == static_cast<const ColorMatrixFragmentProcessor&>(processor).matrix;
}

std::unique_ptr<GLFragmentProcessor> ColorMatrixFragmentProcessor::onCreateGLInstance() const {
return std::make_unique<GLColorMatrixFragmentProcessor>();
}
} // namespace tgfx
6 changes: 1 addition & 5 deletions tgfx/src/gpu/ColorMatrixFragmentProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ class ColorMatrixFragmentProcessor : public FragmentProcessor {
return "ColorMatrixFragmentProcessor";
}

std::unique_ptr<GLFragmentProcessor> onCreateGLInstance() const override;

private:
protected:
DEFINE_PROCESSOR_CLASS_ID

explicit ColorMatrixFragmentProcessor(const std::array<float, 20>& matrix)
Expand All @@ -42,7 +40,5 @@ class ColorMatrixFragmentProcessor : public FragmentProcessor {
bool onIsEqual(const FragmentProcessor& processor) const override;

std::array<float, 20> matrix;

friend class GLColorMatrixFragmentProcessor;
};
} // namespace tgfx
9 changes: 0 additions & 9 deletions tgfx/src/gpu/ConstColorProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,8 @@
/////////////////////////////////////////////////////////////////////////////////////////////////

#include "gpu/ConstColorProcessor.h"
#include "opengl/GLConstColorProcessor.h"

namespace tgfx {
std::unique_ptr<ConstColorProcessor> ConstColorProcessor::Make(Color color, InputMode mode) {
return std::unique_ptr<ConstColorProcessor>(new ConstColorProcessor(color, mode));
}

void ConstColorProcessor::onComputeProcessorKey(BytesKey* bytesKey) const {
bytesKey->write(static_cast<uint32_t>(inputMode));
}
Expand All @@ -32,8 +27,4 @@ bool ConstColorProcessor::onIsEqual(const FragmentProcessor& processor) const {
const auto& that = static_cast<const ConstColorProcessor&>(processor);
return inputMode == that.inputMode && color == that.color;
}

std::unique_ptr<GLFragmentProcessor> ConstColorProcessor::onCreateGLInstance() const {
return std::make_unique<GLConstColorProcessor>();
}
} // namespace tgfx
6 changes: 1 addition & 5 deletions tgfx/src/gpu/ConstColorProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ class ConstColorProcessor : public FragmentProcessor {

void onComputeProcessorKey(BytesKey* bytesKey) const override;

std::unique_ptr<GLFragmentProcessor> onCreateGLInstance() const override;

private:
protected:
DEFINE_PROCESSOR_CLASS_ID

ConstColorProcessor(Color color, InputMode mode)
Expand All @@ -47,7 +45,5 @@ class ConstColorProcessor : public FragmentProcessor {

Color color;
InputMode inputMode;

friend class GLConstColorProcessor;
};
} // namespace tgfx
14 changes: 0 additions & 14 deletions tgfx/src/gpu/DeviceSpaceTextureEffect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,8 @@
/////////////////////////////////////////////////////////////////////////////////////////////////

#include "DeviceSpaceTextureEffect.h"
#include "opengl/GLDeviceSpaceTextureEffect.h"

namespace tgfx {
std::unique_ptr<DeviceSpaceTextureEffect> DeviceSpaceTextureEffect::Make(
std::shared_ptr<Texture> texture, ImageOrigin deviceOrigin) {
if (texture == nullptr) {
return nullptr;
}
return std::unique_ptr<DeviceSpaceTextureEffect>(
new DeviceSpaceTextureEffect(std::move(texture), deviceOrigin));
}

DeviceSpaceTextureEffect::DeviceSpaceTextureEffect(std::shared_ptr<Texture> texture,
ImageOrigin deviceOrigin)
: FragmentProcessor(ClassID()), texture(std::move(texture)) {
Expand All @@ -46,8 +36,4 @@ bool DeviceSpaceTextureEffect::onIsEqual(const FragmentProcessor& processor) con
const auto& that = static_cast<const DeviceSpaceTextureEffect&>(processor);
return texture == that.texture && deviceCoordMatrix == that.deviceCoordMatrix;
}

std::unique_ptr<GLFragmentProcessor> DeviceSpaceTextureEffect::onCreateGLInstance() const {
return std::make_unique<GLDeviceSpaceTextureEffect>();
}
} // namespace tgfx
6 changes: 1 addition & 5 deletions tgfx/src/gpu/DeviceSpaceTextureEffect.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,18 @@ class DeviceSpaceTextureEffect : public FragmentProcessor {
return "DeviceSpaceTextureEffect";
}

private:
protected:
DEFINE_PROCESSOR_CLASS_ID

DeviceSpaceTextureEffect(std::shared_ptr<Texture> texture, ImageOrigin deviceOrigin);

bool onIsEqual(const FragmentProcessor& processor) const override;

std::unique_ptr<GLFragmentProcessor> onCreateGLInstance() const override;

const TextureSampler* onTextureSampler(size_t) const override {
return texture->getSampler();
}

std::shared_ptr<Texture> texture;
Matrix deviceCoordMatrix = Matrix::I();

friend class GLDeviceSpaceTextureEffect;
};
} // namespace tgfx
15 changes: 0 additions & 15 deletions tgfx/src/gpu/DualBlurFragmentProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,8 @@
/////////////////////////////////////////////////////////////////////////////////////////////////

#include "gpu/DualBlurFragmentProcessor.h"
#include "opengl/GLDualBlurFragmentProcessor.h"

namespace tgfx {
std::unique_ptr<DualBlurFragmentProcessor> DualBlurFragmentProcessor::Make(
DualBlurPassMode passMode, std::unique_ptr<FragmentProcessor> processor, Point blurOffset,
Point texelSize) {
if (processor == nullptr) {
return nullptr;
}
return std::unique_ptr<DualBlurFragmentProcessor>(
new DualBlurFragmentProcessor(passMode, std::move(processor), blurOffset, texelSize));
}

DualBlurFragmentProcessor::DualBlurFragmentProcessor(DualBlurPassMode passMode,
std::unique_ptr<FragmentProcessor> processor,
Point blurOffset, Point texelSize)
Expand All @@ -48,8 +37,4 @@ bool DualBlurFragmentProcessor::onIsEqual(const FragmentProcessor& processor) co
const auto& that = static_cast<const DualBlurFragmentProcessor&>(processor);
return passMode == that.passMode && blurOffset == that.blurOffset && texelSize == that.texelSize;
}

std::unique_ptr<GLFragmentProcessor> DualBlurFragmentProcessor::onCreateGLInstance() const {
return std::make_unique<GLDualBlurFragmentProcessor>();
}
} // namespace tgfx
6 changes: 1 addition & 5 deletions tgfx/src/gpu/DualBlurFragmentProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ class DualBlurFragmentProcessor : public FragmentProcessor {

void onComputeProcessorKey(BytesKey* bytesKey) const override;

std::unique_ptr<GLFragmentProcessor> onCreateGLInstance() const override;

private:
protected:
DEFINE_PROCESSOR_CLASS_ID

DualBlurFragmentProcessor(DualBlurPassMode passMode, std::unique_ptr<FragmentProcessor> processor,
Expand All @@ -48,7 +46,5 @@ class DualBlurFragmentProcessor : public FragmentProcessor {
DualBlurPassMode passMode;
Point blurOffset;
Point texelSize;

friend class GLDualBlurFragmentProcessor;
};
} // namespace tgfx
1 change: 0 additions & 1 deletion tgfx/src/gpu/EllipseGeometryProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
/////////////////////////////////////////////////////////////////////////////////////////////////

#include "EllipseGeometryProcessor.h"
#include "opengl/GLEllipseGeometryProcessor.h"

namespace tgfx {
EllipseGeometryProcessor::EllipseGeometryProcessor(int width, int height, bool stroke,
Expand Down
1 change: 0 additions & 1 deletion tgfx/src/gpu/EmptyXferProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
/////////////////////////////////////////////////////////////////////////////////////////////////

#include "EmptyXferProcessor.h"
#include "opengl/GLEmptyXferProcessor.h"

namespace tgfx {
void EmptyXferProcessor::computeProcessorKey(Context*, BytesKey* bytesKey) const {
Expand Down
78 changes: 67 additions & 11 deletions tgfx/src/gpu/FragmentProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
/////////////////////////////////////////////////////////////////////////////////////////////////

#include "gpu/FragmentProcessor.h"
#include "GLFragmentProcessor.h"
#include "Pipeline.h"
#include "SeriesFragmentProcessor.h"
#include "gpu/XfermodeFragmentProcessor.h"
Expand Down Expand Up @@ -70,14 +69,6 @@ void FragmentProcessor::computeProcessorKey(Context* context, BytesKey* bytesKey
}
}

std::unique_ptr<GLFragmentProcessor> FragmentProcessor::createGLInstance() const {
auto glFragProc = onCreateGLInstance();
for (const auto& fChildProcessor : childProcessors) {
glFragProc->childProcessors.push_back(fChildProcessor->createGLInstance());
}
return glFragProc;
}

size_t FragmentProcessor::registerChildProcessor(std::unique_ptr<FragmentProcessor> child) {
auto index = childProcessors.size();
childProcessors.push_back(std::move(child));
Expand Down Expand Up @@ -171,7 +162,72 @@ std::unique_ptr<FragmentProcessor> FragmentProcessor::instantiate() {
return nullptr;
}

std::unique_ptr<GLFragmentProcessor> FragmentProcessorProxy::onCreateGLInstance() const {
return nullptr;
void FragmentProcessor::setData(UniformBuffer* uniformBuffer) const {
onSetData(uniformBuffer);
}

void FragmentProcessor::emitChild(size_t childIndex, const std::string& inputColor,
std::string* outputColor, EmitArgs& args,
std::function<std::string(std::string_view)> coordFunc) const {
auto* fragBuilder = args.fragBuilder;
outputColor->append(fragBuilder->mangleString());
fragBuilder->codeAppendf("vec4 %s;", outputColor->c_str());
internalEmitChild(childIndex, inputColor, *outputColor, args, std::move(coordFunc));
}

void FragmentProcessor::emitChild(size_t childIndex, const std::string& inputColor,
EmitArgs& parentArgs) const {
internalEmitChild(childIndex, inputColor, parentArgs.outputColor, parentArgs);
}

void FragmentProcessor::internalEmitChild(
size_t childIndex, const std::string& inputColor, const std::string& outputColor,
EmitArgs& args, std::function<std::string(std::string_view)> coordFunc) const {
auto* fragBuilder = args.fragBuilder;
fragBuilder->onBeforeChildProcEmitCode(); // call first so mangleString is updated
// Prepare a mangled input color variable if the default is not used,
// inputName remains the empty string if no variable is needed.
std::string inputName;
if (!inputColor.empty() && inputColor != "vec4(1.0)" && inputColor != "vec4(1)") {
// The input name is based off of the current mangle string, and
// since this is called after onBeforeChildProcEmitCode(), it will be
// unique to the child processor (exactly what we want for its input).
inputName += "_childInput";
inputName += fragBuilder->mangleString();
fragBuilder->codeAppendf("vec4 %s = %s;", inputName.c_str(), inputColor.c_str());
}

const auto* childProc = childProcessor(childIndex);

// emit the code for the child in its own scope
fragBuilder->codeAppend("{\n");
fragBuilder->codeAppendf("// Child Index %d (mangle: %s): %s\n", childIndex,
fragBuilder->mangleString().c_str(), childProc->name().c_str());
TransformedCoordVars coordVars = args.transformedCoords->childInputs(childIndex);
TextureSamplers textureSamplers = args.textureSamplers->childInputs(childIndex);

EmitArgs childArgs(fragBuilder, args.uniformHandler, outputColor,
inputName.empty() ? "vec4(1.0)" : inputName, &coordVars, &textureSamplers,
std::move(coordFunc));
childProcessor(childIndex)->emitCode(childArgs);
fragBuilder->codeAppend("}\n");

fragBuilder->onAfterChildProcEmitCode();
}

template <typename T, size_t (FragmentProcessor::*COUNT)() const>
FragmentProcessor::BuilderInputProvider<T, COUNT>
FragmentProcessor::BuilderInputProvider<T, COUNT>::childInputs(size_t childIndex) const {
const FragmentProcessor* child = fragmentProcessor->childProcessor(childIndex);
FragmentProcessor::Iter iter(fragmentProcessor);
int numToSkip = 0;
while (true) {
const FragmentProcessor* processor = iter.next();
if (processor == child) {
return BuilderInputProvider(child, t + numToSkip);
}
numToSkip += (processor->*COUNT)();
}
}

} // namespace tgfx
Loading

0 comments on commit 0b04e16

Please sign in to comment.