-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
210 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#pragma once | ||
|
||
typedef double NXFloat; | ||
|
||
struct NXSize { | ||
NXFloat width; | ||
NXFloat height; | ||
|
||
NXSize(); | ||
NXSize(NXFloat width, NXFloat height); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#pragma once | ||
|
||
#include <NXSize.h> | ||
|
||
#include <SDL.h> | ||
#include <memory> | ||
#include "include/core/SkSurface.h" | ||
#include <functional> | ||
|
||
bool platformRunLoop(std::function<bool()> loop); | ||
|
||
class SkiaCtx { | ||
public: | ||
virtual sk_sp<SkSurface> getBackbufferSurface() = 0; | ||
virtual sk_sp<GrDirectContext> directContext() = 0; | ||
virtual void flushAndSubmit(sk_sp<SkSurface> surface); | ||
virtual NXSize getSize() = 0; | ||
virtual float getScaleFactor() { return 1; } | ||
virtual void swapBuffers() = 0; | ||
|
||
protected: | ||
NXSize _size; | ||
}; | ||
|
||
std::unique_ptr<SkiaCtx> MakeSkiaCtx(SDL_Window* window); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#pragma once | ||
|
||
#include <SkiaCtx.h> | ||
#include <include/gpu/ganesh/GrDirectContext.h> | ||
|
||
|
||
class SkiaCtx_sdlBase: public SkiaCtx { | ||
public: | ||
SkiaCtx_sdlBase(SDL_Window* window); | ||
|
||
virtual void swapBuffers() override; | ||
virtual NXSize getSize() override; | ||
|
||
protected: | ||
SDL_Window* window = nullptr; | ||
}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#pragma once | ||
|
||
#include <SkiaCtx.h> | ||
#include <platforms/SkiaCtx_sdlBase.h> | ||
#include <include/gpu/ganesh/GrDirectContext.h> | ||
|
||
class SkiaCtx_ios: public SkiaCtx_sdlBase { | ||
public: | ||
SkiaCtx_ios(SDL_Window* window); | ||
|
||
sk_sp<SkSurface> getBackbufferSurface() override; | ||
float getScaleFactor() override; | ||
sk_sp<GrDirectContext> directContext() override { return context; } | ||
private: | ||
sk_sp<GrDirectContext> context; | ||
|
||
void initContext(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#include <NXSize.h> | ||
|
||
NXSize::NXSize(): NXSize(0, 0) {} | ||
NXSize::NXSize(NXFloat width, NXFloat height): width(width), height(height) {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#include "SkiaCtx.h" | ||
|
||
#include "include/gpu/ganesh/GrDirectContext.h" | ||
|
||
void SkiaCtx::flushAndSubmit(sk_sp<SkSurface> surface) { | ||
if (auto dContext = directContext()) { | ||
dContext->flushAndSubmit(surface.get(), GrSyncCpu::kNo); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#include <platforms/SkiaCtx_sdlBase.h> | ||
|
||
SkiaCtx_sdlBase::SkiaCtx_sdlBase(SDL_Window *window): window(window) | ||
{ } | ||
|
||
void SkiaCtx_sdlBase::swapBuffers() { | ||
SDL_GL_SwapWindow(window); | ||
} | ||
|
||
NXSize SkiaCtx_sdlBase::getSize() { | ||
int w, h; | ||
SDL_GL_GetDrawableSize(window, &w, &h); | ||
return { (NXFloat)w, (NXFloat)h }; | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#include <platforms/ios/SkiaCtx_ios.h> | ||
|
||
#include "include/core/SkColorSpace.h" | ||
#include "include/gpu/ganesh/gl/GrGLDirectContext.h" | ||
#include "include/gpu/ganesh/gl/GrGLInterface.h" | ||
#include "include/gpu/ganesh/gl/GrGLBackendSurface.h" | ||
#include "include/gpu/ganesh/gl/ios/GrGLMakeIOSInterface.h" | ||
#include "include/gpu/ganesh/SkSurfaceGanesh.h" | ||
#include "include/gpu/ganesh/GrDirectContext.h" | ||
#include "include/gpu/ganesh/GrBackendSurface.h" | ||
|
||
#include <GLES3/gl3.h> | ||
#include <UIKit/UIKit.h> | ||
|
||
SkiaCtx_ios::SkiaCtx_ios(SDL_Window* window): SkiaCtx_sdlBase(window) { | ||
initContext(); | ||
} | ||
|
||
void SkiaCtx_ios::initContext() { | ||
auto interface = GrGLInterfaces::MakeIOS(); | ||
_size = getSize(); | ||
interface->fFunctions.fViewport(0, 0, _size.width, _size.height); | ||
context = GrDirectContexts::MakeGL(interface); | ||
} | ||
|
||
float SkiaCtx_ios::getScaleFactor() { | ||
return UIApplication.sharedApplication.keyWindow.traitCollection.displayScale; | ||
} | ||
|
||
sk_sp<SkSurface> SkiaCtx_ios::getBackbufferSurface() { | ||
auto size = getSize(); | ||
if (_size.width != size.width || _size.height != size.width) | ||
initContext(); | ||
|
||
GrGLFramebufferInfo framebuffer_info; | ||
framebuffer_info.fFormat = GL_RGBA8; | ||
framebuffer_info.fFBOID = 0; | ||
auto frame = UIApplication.sharedApplication.keyWindow.frame; | ||
GrBackendRenderTarget target = GrBackendRenderTargets::MakeGL(frame.size.width, frame.size.height, 0, 8, framebuffer_info); | ||
|
||
SkSurfaceProps props; | ||
|
||
return SkSurfaces::WrapBackendRenderTarget(context.get(), target, | ||
kBottomLeft_GrSurfaceOrigin, kRGBA_8888_SkColorType, | ||
nullptr, &props); | ||
} | ||
|
||
std::unique_ptr<SkiaCtx> MakeSkiaCtx(SDL_Window* window) { | ||
return std::make_unique<SkiaCtx_ios>(window); | ||
} | ||
|
||
bool platformRunLoop(std::function<bool()> loop) { | ||
@autoreleasepool { | ||
return loop(); | ||
} | ||
} |
Oops, something went wrong.