Skip to content

Commit

Permalink
Revert "Reland "Take GrContext private, GrDDLContext inherit from GrR…
Browse files Browse the repository at this point in the history
…ecordingContext""

This reverts commit ff13ffb.

Reason for revert: Blink in g3

Original change's description:
> Reland "Take GrContext private, GrDDLContext inherit from GrRecordingContext"
>
> This reverts commit 89bdc90.
>
> Reason for revert: Fix metal
>
> Original change's description:
> > Revert "Take GrContext private, GrDDLContext inherit from GrRecordingContext"
> >
> > This reverts commit d2daa94.
> >
> > Reason for revert: Metaru
> >
> > Original change's description:
> > > Take GrContext private, GrDDLContext inherit from GrRecordingContext
> > >
> > > Woo!
> > >
> > > Change-Id: I8d201b709343dc18cad31ea740575285dd035f35
> > > Docs-Preview: https://skia.org/?cl=317436
> > > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/317436
> > > Reviewed-by: Robert Phillips <robertphillips@google.com>
> > > Reviewed-by: Brian Salomon <bsalomon@google.com>
> > > Commit-Queue: Adlai Holler <adlai@google.com>
> >
> > TBR=bsalomon@google.com,robertphillips@google.com,adlai@google.com
> >
> > Change-Id: I9b58dee285fbdc49ebc8e76df5da0fe224cf9787
> > No-Presubmit: true
> > No-Tree-Checks: true
> > No-Try: true
> > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/318758
> > Reviewed-by: Adlai Holler <adlai@google.com>
> > Commit-Queue: Adlai Holler <adlai@google.com>
>
> TBR=bsalomon@google.com,robertphillips@google.com,adlai@google.com
>
>
> Change-Id: Id4b10795193a904cd4ed8c36e60e74abe3b6702a
> Docs-Preview: https://skia.org/?cl=318759
> Cq-Include-Trybots: luci.skia.skia.primary:Build-Mac10.15.5-Clang-arm64-Debug-iOS_Metal,Build-Mac-Clang-x86_64-Debug-Metal
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/318759
> Commit-Queue: Adlai Holler <adlai@google.com>
> Reviewed-by: Adlai Holler <adlai@google.com>

TBR=bsalomon@google.com,robertphillips@google.com,adlai@google.com

Change-Id: Ib20fe933120d56b72efaec73a0bedec60bc28def
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/319184
Commit-Queue: Adlai Holler <adlai@google.com>
Reviewed-by: Adlai Holler <adlai@google.com>
  • Loading branch information
Adlai-Holler authored and Skia Commit-Bot committed Sep 24, 2020
1 parent 96d9b52 commit cf43fc6
Show file tree
Hide file tree
Showing 11 changed files with 201 additions and 36 deletions.
7 changes: 3 additions & 4 deletions experimental/skottiekit/skottiekit_bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#ifdef SK_GL
#include "include/core/SkImageInfo.h"
#include "include/gpu/GrBackendSurface.h"
#include "include/gpu/GrDirectContext.h"
#include "include/gpu/GrContext.h"
#include "include/gpu/gl/GrGLInterface.h"
#include "include/gpu/gl/GrGLTypes.h"

Expand Down Expand Up @@ -214,18 +214,17 @@ SkImageInfo toSkImageInfo(const SimpleImageInfo& sii) {
}

#ifdef SK_GL
// TODO: Migrate this to GrDirectContext.
sk_sp<GrContext> MakeGrContext(EMSCRIPTEN_WEBGL_CONTEXT_HANDLE context)
{
EMSCRIPTEN_RESULT r = emscripten_webgl_make_context_current(context);
if (r < 0) {
printf("failed to make webgl context current %d\n", r);
return nullptr;
}
// setup GrDirectContext
// setup GrContext
auto interface = GrGLMakeNativeInterface();
// setup contexts
sk_sp<GrContext> grContext(GrDirectContext::MakeGL(interface));
sk_sp<GrContext> grContext(GrContext::MakeGL(interface));
return grContext;
}

Expand Down
4 changes: 2 additions & 2 deletions experimental/wasm-skp-debugger/debugger_bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

#ifdef SK_GL
#include "include/gpu/GrBackendSurface.h"
#include "include/gpu/GrDirectContext.h"
#include "include/gpu/GrContext.h"
#include "include/gpu/gl/GrGLInterface.h"
#include "include/gpu/gl/GrGLTypes.h"

Expand Down Expand Up @@ -436,7 +436,7 @@ sk_sp<GrContext> MakeGrContext(EMSCRIPTEN_WEBGL_CONTEXT_HANDLE context)
return nullptr;
}
// setup contexts
sk_sp<GrContext> grContext(GrDirectContext::MakeGL(interface));
sk_sp<GrContext> grContext(GrContext::MakeGL(interface));
return grContext;
}

Expand Down
2 changes: 1 addition & 1 deletion gn/gpu.gni
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ skia_gpu_sources = [
"$_include/gpu/GrBackendSurface.h",
"$_include/gpu/GrBackendSurfaceMutableState.h",
"$_include/gpu/GrConfig.h",
"$_include/gpu/GrContext.h",
"$_include/gpu/GrContextOptions.h",
"$_include/gpu/GrContextThreadSafeProxy.h",
"$_include/gpu/GrDirectContext.h",
Expand All @@ -21,7 +22,6 @@ skia_gpu_sources = [
"$_include/gpu/GrTypes.h",

# Private includes
"$_include/private/GrContext.h",
"$_include/private/GrContext_Base.h",
"$_include/private/GrGLTypesPriv.h",
"$_include/private/GrImageContext.h",
Expand Down
56 changes: 56 additions & 0 deletions include/private/GrContext.h → include/gpu/GrContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,62 @@ class SkTraceMemoryDump;

class SK_API GrContext : public GrRecordingContext {
public:
#ifndef SK_DISABLE_LEGACY_CONTEXT_FACTORIES

#ifdef SK_GL
/**
* Creates a GrContext for a backend context. If no GrGLInterface is provided then the result of
* GrGLMakeNativeInterface() is used if it succeeds.
*/
static sk_sp<GrContext> MakeGL(sk_sp<const GrGLInterface>, const GrContextOptions&);
static sk_sp<GrContext> MakeGL(sk_sp<const GrGLInterface>);
static sk_sp<GrContext> MakeGL(const GrContextOptions&);
static sk_sp<GrContext> MakeGL();
#endif

#ifdef SK_VULKAN
/**
* The Vulkan context (VkQueue, VkDevice, VkInstance) must be kept alive until the returned
* GrContext is destroyed. This also means that any objects created with this GrContext (e.g.
* SkSurfaces, SkImages, etc.) must also be released as they may hold refs on the GrContext.
* Once all these objects and the GrContext are released, then it is safe to delete the vulkan
* objects.
*/
static sk_sp<GrContext> MakeVulkan(const GrVkBackendContext&, const GrContextOptions&);
static sk_sp<GrContext> MakeVulkan(const GrVkBackendContext&);
#endif

#ifdef SK_METAL
/**
* Makes a GrContext which uses Metal as the backend. The device parameter is an MTLDevice
* and queue is an MTLCommandQueue which should be used by the backend. These objects must
* have a ref on them which can be transferred to Ganesh which will release the ref when the
* GrContext is destroyed.
*/
static sk_sp<GrContext> MakeMetal(void* device, void* queue, const GrContextOptions& options);
static sk_sp<GrContext> MakeMetal(void* device, void* queue);
#endif

#ifdef SK_DIRECT3D
/**
* Makes a GrContext which uses Direct3D as the backend. The Direct3D context
* must be kept alive until the returned GrContext is first destroyed or abandoned.
*/
static sk_sp<GrContext> MakeDirect3D(const GrD3DBackendContext&,
const GrContextOptions& options);
static sk_sp<GrContext> MakeDirect3D(const GrD3DBackendContext&);
#endif

#ifdef SK_DAWN
static sk_sp<GrContext> MakeDawn(const wgpu::Device& device, const GrContextOptions& options);
static sk_sp<GrContext> MakeDawn(const wgpu::Device& device);
#endif

static sk_sp<GrContext> MakeMock(const GrMockOptions*, const GrContextOptions&);
static sk_sp<GrContext> MakeMock(const GrMockOptions*);

#endif // SK_DISABLE_LEGACY_CONTEXT_FACTORIES

~GrContext() override;

// TODO: Remove this from public after migrating Chrome.
Expand Down
2 changes: 1 addition & 1 deletion include/gpu/GrDirectContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#ifndef GrDirectContext_DEFINED
#define GrDirectContext_DEFINED

#include "include/private/GrContext.h"
#include "include/gpu/GrContext.h"

class GrAtlasManager;
class GrSmallPathAtlasMgr;
Expand Down
42 changes: 19 additions & 23 deletions modules/canvaskit/canvaskit_bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,29 +150,29 @@ struct ColorSettings {
GrGLenum pixFormat;
};

sk_sp<GrDirectContext> MakeGrContext(EMSCRIPTEN_WEBGL_CONTEXT_HANDLE context)
sk_sp<GrContext> MakeGrContext(EMSCRIPTEN_WEBGL_CONTEXT_HANDLE context)
{
EMSCRIPTEN_RESULT r = emscripten_webgl_make_context_current(context);
if (r < 0) {
printf("failed to make webgl context current %d\n", r);
return nullptr;
}
// setup GrDirectContext
// setup GrContext
auto interface = GrGLMakeNativeInterface();
// setup contexts
sk_sp<GrDirectContext> dContext(GrDirectContext::MakeGL(interface));
return dContext;
sk_sp<GrContext> grContext(GrContext::MakeGL(interface));
return grContext;
}

sk_sp<SkSurface> MakeOnScreenGLSurface(sk_sp<GrDirectContext> dContext, int width, int height,
sk_sp<SkSurface> MakeOnScreenGLSurface(sk_sp<GrContext> grContext, int width, int height,
sk_sp<SkColorSpace> colorSpace) {
// WebGL should already be clearing the color and stencil buffers, but do it again here to
// ensure Skia receives them in the expected state.
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glClearColor(0, 0, 0, 0);
glClearStencil(0);
glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
dContext->resetContext(kRenderTarget_GrGLBackendState | kMisc_GrGLBackendState);
grContext->resetContext(kRenderTarget_GrGLBackendState | kMisc_GrGLBackendState);

// The on-screen canvas is FBO 0. Wrap it in a Skia render target so Skia can render to it.
GrGLFramebufferInfo info;
Expand All @@ -187,24 +187,24 @@ sk_sp<SkSurface> MakeOnScreenGLSurface(sk_sp<GrDirectContext> dContext, int widt
const auto colorSettings = ColorSettings(colorSpace);
info.fFormat = colorSettings.pixFormat;
GrBackendRenderTarget target(width, height, sampleCnt, stencil, info);
sk_sp<SkSurface> surface(SkSurface::MakeFromBackendRenderTarget(dContext.get(), target,
sk_sp<SkSurface> surface(SkSurface::MakeFromBackendRenderTarget(grContext.get(), target,
kBottomLeft_GrSurfaceOrigin, colorSettings.colorType, colorSpace, nullptr));
return surface;
}

sk_sp<SkSurface> MakeRenderTarget(sk_sp<GrDirectContext> dContext, int width, int height) {
sk_sp<SkSurface> MakeRenderTarget(sk_sp<GrContext> grContext, int width, int height) {
SkImageInfo info = SkImageInfo::MakeN32(width, height, SkAlphaType::kPremul_SkAlphaType);

sk_sp<SkSurface> surface(SkSurface::MakeRenderTarget(dContext.get(),
sk_sp<SkSurface> surface(SkSurface::MakeRenderTarget(grContext.get(),
SkBudgeted::kYes,
info, 0,
kBottomLeft_GrSurfaceOrigin,
nullptr, true));
return surface;
}

sk_sp<SkSurface> MakeRenderTarget(sk_sp<GrDirectContext> dContext, SimpleImageInfo sii) {
sk_sp<SkSurface> surface(SkSurface::MakeRenderTarget(dContext.get(),
sk_sp<SkSurface> MakeRenderTarget(sk_sp<GrContext> grContext, SimpleImageInfo sii) {
sk_sp<SkSurface> surface(SkSurface::MakeRenderTarget(grContext.get(),
SkBudgeted::kYes,
toSkImageInfo(sii), 0,
kBottomLeft_GrSurfaceOrigin,
Expand Down Expand Up @@ -736,8 +736,8 @@ EMSCRIPTEN_BINDINGS(Skia) {
function("setCurrentContext", &emscripten_webgl_make_context_current);
function("MakeGrContext", &MakeGrContext);
function("MakeOnScreenGLSurface", &MakeOnScreenGLSurface);
function("MakeRenderTarget", select_overload<sk_sp<SkSurface>(sk_sp<GrDirectContext>, int, int)>(&MakeRenderTarget));
function("MakeRenderTarget", select_overload<sk_sp<SkSurface>(sk_sp<GrDirectContext>, SimpleImageInfo)>(&MakeRenderTarget));
function("MakeRenderTarget", select_overload<sk_sp<SkSurface>(sk_sp<GrContext>, int, int)>(&MakeRenderTarget));
function("MakeRenderTarget", select_overload<sk_sp<SkSurface>(sk_sp<GrContext>, SimpleImageInfo)>(&MakeRenderTarget));

constant("gpu", true);
#endif
Expand Down Expand Up @@ -908,26 +908,22 @@ EMSCRIPTEN_BINDINGS(Skia) {
}), allow_raw_pointers());

#ifdef SK_GL
class_<GrDirectContext>("GrDirectContext")
.smart_ptr<sk_sp<GrDirectContext>>("sk_sp<GrDirectContext>")
.function("getResourceCacheLimitBytes",
optional_override([](GrDirectContext& self)->size_t {
class_<GrContext>("GrContext")
.smart_ptr<sk_sp<GrContext>>("sk_sp<GrContext>")
.function("getResourceCacheLimitBytes", optional_override([](GrContext& self)->size_t {
int maxResources = 0;// ignored
size_t currMax = 0;
self.getResourceCacheLimits(&maxResources, &currMax);
return currMax;
}))
.function("getResourceCacheUsageBytes",
optional_override([](GrDirectContext& self)->size_t {
.function("getResourceCacheUsageBytes", optional_override([](GrContext& self)->size_t {
int usedResources = 0;// ignored
size_t currUsage = 0;
self.getResourceCacheUsage(&usedResources, &currUsage);
return currUsage;
}))
.function("releaseResourcesAndAbandonContext",
&GrDirectContext::releaseResourcesAndAbandonContext)
.function("setResourceCacheLimitBytes",
optional_override([](GrDirectContext& self, size_t maxResourceBytes)->void {
.function("releaseResourcesAndAbandonContext", &GrContext::releaseResourcesAndAbandonContext)
.function("setResourceCacheLimitBytes", optional_override([](GrContext& self, size_t maxResourceBytes)->void {
int maxResources = 0;
size_t currMax = 0; // ignored
self.getResourceCacheLimits(&maxResources, &currMax);
Expand Down
1 change: 1 addition & 0 deletions modules/canvaskit/viewer_bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <emscripten/bind.h>
#include "include/core/SkCanvas.h"
#include "include/core/SkSurface.h"
#include "include/gpu/GrContext.h"
#include "tools/skui/InputState.h"
#include "tools/skui/ModifierKey.h"
#include "tools/viewer/SKPSlide.h"
Expand Down
2 changes: 1 addition & 1 deletion site/user/api/skcanvas_creation.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ has been made current to the current thread when Skia calls are made.

<!--?prettify lang=cc?-->

#include "GrDirectContext.h"
#include "GrContext.h"
#include "gl/GrGLInterface.h"
#include "SkData.h"
#include "SkImage.h"
Expand Down
30 changes: 27 additions & 3 deletions src/gpu/GrDDLContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* found in the LICENSE file.
*/

#include "include/gpu/GrRecordingContext.h"
#include "include/gpu/GrContext.h"
#include "src/core/SkLRUCache.h"
#include "src/gpu/GrCaps.h"
#include "src/gpu/GrContextThreadSafeProxyPriv.h"
Expand All @@ -18,7 +18,7 @@
* The DDL Context is the one in effect during DDL Recording. It isn't backed by a GrGPU and
* cannot allocate any GPU resources.
*/
class GrDDLContext final : public GrRecordingContext {
class GrDDLContext final : public GrContext {
public:
GrDDLContext(sk_sp<GrContextThreadSafeProxy> proxy)
: INHERITED(std::move(proxy)) {
Expand All @@ -31,7 +31,21 @@ class GrDDLContext final : public GrRecordingContext {
INHERITED::abandonContext();
}

void releaseResourcesAndAbandonContext() override {
SkASSERT(0); // abandoning in a DDL Recorder doesn't make a whole lot of sense
INHERITED::releaseResourcesAndAbandonContext();
}

void freeGpuResources() override {
// freeing resources in a DDL Recorder doesn't make a whole lot of sense but some of
// our tests do it anyways
}

private:
// TODO: Here we're pretending this isn't derived from GrContext. Switch this to be derived from
// GrRecordingContext!
GrDirectContext* asDirectContext() override { return nullptr; }

bool init() override {
if (!INHERITED::init()) {
return false;
Expand All @@ -44,6 +58,16 @@ class GrDDLContext final : public GrRecordingContext {
return true;
}

GrAtlasManager* onGetAtlasManager() override {
SkASSERT(0); // the DDL Recorders should never invoke this
return nullptr;
}

GrSmallPathAtlasMgr* onGetSmallPathAtlasMgr() override {
SkASSERT(0); // DDL recorders should never invoke this
return nullptr;
}

// Add to the set of unique program infos required by this DDL
void recordProgramInfo(const GrProgramInfo* programInfo) final {
if (!programInfo) {
Expand Down Expand Up @@ -125,7 +149,7 @@ class GrDDLContext final : public GrRecordingContext {

ProgramInfoMap fProgramInfoMap;

using INHERITED = GrRecordingContext;
using INHERITED = GrContext;
};

sk_sp<GrRecordingContext> GrRecordingContextPriv::MakeDDL(sk_sp<GrContextThreadSafeProxy> proxy) {
Expand Down
Loading

0 comments on commit cf43fc6

Please sign in to comment.