Skip to content

Commit 0ce2c54

Browse files
Adlai-HollerSkia Commit-Bot
authored andcommitted
Reland "Reland "Take GrContext private, GrDDLContext inherit from GrRecordingContext""
This reverts commit cf43fc6. Reason for revert: Fixed g3 Original change's description: > Revert "Reland "Take GrContext private, GrDDLContext inherit from GrRecordingContext"" > > 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> TBR=bsalomon@google.com,robertphillips@google.com,adlai@google.com Change-Id: I4f01291f4b3bfbb8fd7dd8cf2bf8415430c3392e Docs-Preview: https://skia.org/?cl=322437 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/322437 Reviewed-by: Adlai Holler <adlai@google.com> Reviewed-by: Brian Salomon <bsalomon@google.com> Commit-Queue: Adlai Holler <adlai@google.com> Auto-Submit: Adlai Holler <adlai@google.com>
1 parent 88f3b68 commit 0ce2c54

File tree

13 files changed

+43
-202
lines changed

13 files changed

+43
-202
lines changed

RELEASE_NOTES.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ Milestone 88
99

1010
* <insert new release notes here>
1111

12+
* GrContext has been replaced by two separate classes: GrDirectContext which is
13+
the traditional notion of GrContext, and GrRecordingContext which is a context
14+
that is recording an SkDeferredDisplayList and therefore has reduced functionality.
15+
Unless you are using SkDeferredDisplayList, migrate directly to GrDirectContext in
16+
all cases.
17+
1218
* CPU sync bool added to SkSurface::flushAndSubmit() and GrContext::flushAndSubmit()
1319

1420
* Removed legacy variant of SkImage::MakeFromYUVAPixmaps. Use the version that

experimental/skottiekit/skottiekit_bindings.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
#ifdef SK_GL
3232
#include "include/core/SkImageInfo.h"
3333
#include "include/gpu/GrBackendSurface.h"
34-
#include "include/gpu/GrContext.h"
34+
#include "include/gpu/GrDirectContext.h"
3535
#include "include/gpu/gl/GrGLInterface.h"
3636
#include "include/gpu/gl/GrGLTypes.h"
3737

@@ -214,17 +214,18 @@ SkImageInfo toSkImageInfo(const SimpleImageInfo& sii) {
214214
}
215215

216216
#ifdef SK_GL
217+
// TODO: Migrate this to GrDirectContext.
217218
sk_sp<GrContext> MakeGrContext(EMSCRIPTEN_WEBGL_CONTEXT_HANDLE context)
218219
{
219220
EMSCRIPTEN_RESULT r = emscripten_webgl_make_context_current(context);
220221
if (r < 0) {
221222
printf("failed to make webgl context current %d\n", r);
222223
return nullptr;
223224
}
224-
// setup GrContext
225+
// setup GrDirectContext
225226
auto interface = GrGLMakeNativeInterface();
226227
// setup contexts
227-
sk_sp<GrContext> grContext(GrContext::MakeGL(interface));
228+
sk_sp<GrContext> grContext(GrDirectContext::MakeGL(interface));
228229
return grContext;
229230
}
230231

experimental/wasm-skp-debugger/debugger_bindings.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434
#ifdef SK_GL
3535
#include "include/gpu/GrBackendSurface.h"
36-
#include "include/gpu/GrContext.h"
36+
#include "include/gpu/GrDirectContext.h"
3737
#include "include/gpu/gl/GrGLInterface.h"
3838
#include "include/gpu/gl/GrGLTypes.h"
3939

@@ -436,7 +436,7 @@ sk_sp<GrContext> MakeGrContext(EMSCRIPTEN_WEBGL_CONTEXT_HANDLE context)
436436
return nullptr;
437437
}
438438
// setup contexts
439-
sk_sp<GrContext> grContext(GrContext::MakeGL(interface));
439+
sk_sp<GrContext> grContext(GrDirectContext::MakeGL(interface));
440440
return grContext;
441441
}
442442

gn/gpu.gni

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ skia_gpu_sources = [
1313
"$_include/gpu/GrBackendSurface.h",
1414
"$_include/gpu/GrBackendSurfaceMutableState.h",
1515
"$_include/gpu/GrConfig.h",
16-
"$_include/gpu/GrContext.h",
1716
"$_include/gpu/GrContextOptions.h",
1817
"$_include/gpu/GrContextThreadSafeProxy.h",
1918
"$_include/gpu/GrDirectContext.h",
@@ -22,6 +21,7 @@ skia_gpu_sources = [
2221
"$_include/gpu/GrTypes.h",
2322

2423
# Private includes
24+
"$_include/private/GrContext.h",
2525
"$_include/private/GrContext_Base.h",
2626
"$_include/private/GrGLTypesPriv.h",
2727
"$_include/private/GrImageContext.h",

include/gpu/GrDirectContext.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#ifndef GrDirectContext_DEFINED
99
#define GrDirectContext_DEFINED
1010

11-
#include "include/gpu/GrContext.h"
11+
#include "include/private/GrContext.h"
1212

1313
class GrAtlasManager;
1414
class GrSmallPathAtlasMgr;

include/gpu/GrContext.h renamed to include/private/GrContext.h

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -49,62 +49,6 @@ class SkTraceMemoryDump;
4949

5050
class SK_API GrContext : public GrRecordingContext {
5151
public:
52-
#ifndef SK_DISABLE_LEGACY_CONTEXT_FACTORIES
53-
54-
#ifdef SK_GL
55-
/**
56-
* Creates a GrContext for a backend context. If no GrGLInterface is provided then the result of
57-
* GrGLMakeNativeInterface() is used if it succeeds.
58-
*/
59-
static sk_sp<GrContext> MakeGL(sk_sp<const GrGLInterface>, const GrContextOptions&);
60-
static sk_sp<GrContext> MakeGL(sk_sp<const GrGLInterface>);
61-
static sk_sp<GrContext> MakeGL(const GrContextOptions&);
62-
static sk_sp<GrContext> MakeGL();
63-
#endif
64-
65-
#ifdef SK_VULKAN
66-
/**
67-
* The Vulkan context (VkQueue, VkDevice, VkInstance) must be kept alive until the returned
68-
* GrContext is destroyed. This also means that any objects created with this GrContext (e.g.
69-
* SkSurfaces, SkImages, etc.) must also be released as they may hold refs on the GrContext.
70-
* Once all these objects and the GrContext are released, then it is safe to delete the vulkan
71-
* objects.
72-
*/
73-
static sk_sp<GrContext> MakeVulkan(const GrVkBackendContext&, const GrContextOptions&);
74-
static sk_sp<GrContext> MakeVulkan(const GrVkBackendContext&);
75-
#endif
76-
77-
#ifdef SK_METAL
78-
/**
79-
* Makes a GrContext which uses Metal as the backend. The device parameter is an MTLDevice
80-
* and queue is an MTLCommandQueue which should be used by the backend. These objects must
81-
* have a ref on them which can be transferred to Ganesh which will release the ref when the
82-
* GrContext is destroyed.
83-
*/
84-
static sk_sp<GrContext> MakeMetal(void* device, void* queue, const GrContextOptions& options);
85-
static sk_sp<GrContext> MakeMetal(void* device, void* queue);
86-
#endif
87-
88-
#ifdef SK_DIRECT3D
89-
/**
90-
* Makes a GrContext which uses Direct3D as the backend. The Direct3D context
91-
* must be kept alive until the returned GrContext is first destroyed or abandoned.
92-
*/
93-
static sk_sp<GrContext> MakeDirect3D(const GrD3DBackendContext&,
94-
const GrContextOptions& options);
95-
static sk_sp<GrContext> MakeDirect3D(const GrD3DBackendContext&);
96-
#endif
97-
98-
#ifdef SK_DAWN
99-
static sk_sp<GrContext> MakeDawn(const wgpu::Device& device, const GrContextOptions& options);
100-
static sk_sp<GrContext> MakeDawn(const wgpu::Device& device);
101-
#endif
102-
103-
static sk_sp<GrContext> MakeMock(const GrMockOptions*, const GrContextOptions&);
104-
static sk_sp<GrContext> MakeMock(const GrMockOptions*);
105-
106-
#endif // SK_DISABLE_LEGACY_CONTEXT_FACTORIES
107-
10852
~GrContext() override;
10953

11054
// TODO: Remove this from public after migrating Chrome.

modules/canvaskit/canvaskit_bindings.cpp

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -150,29 +150,29 @@ struct ColorSettings {
150150
GrGLenum pixFormat;
151151
};
152152

153-
sk_sp<GrContext> MakeGrContext(EMSCRIPTEN_WEBGL_CONTEXT_HANDLE context)
153+
sk_sp<GrDirectContext> MakeGrContext(EMSCRIPTEN_WEBGL_CONTEXT_HANDLE context)
154154
{
155155
EMSCRIPTEN_RESULT r = emscripten_webgl_make_context_current(context);
156156
if (r < 0) {
157157
printf("failed to make webgl context current %d\n", r);
158158
return nullptr;
159159
}
160-
// setup GrContext
160+
// setup GrDirectContext
161161
auto interface = GrGLMakeNativeInterface();
162162
// setup contexts
163-
sk_sp<GrContext> grContext(GrContext::MakeGL(interface));
164-
return grContext;
163+
sk_sp<GrDirectContext> dContext(GrDirectContext::MakeGL(interface));
164+
return dContext;
165165
}
166166

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

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

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

198-
sk_sp<SkSurface> surface(SkSurface::MakeRenderTarget(grContext.get(),
198+
sk_sp<SkSurface> surface(SkSurface::MakeRenderTarget(dContext.get(),
199199
SkBudgeted::kYes,
200200
info, 0,
201201
kBottomLeft_GrSurfaceOrigin,
202202
nullptr, true));
203203
return surface;
204204
}
205205

206-
sk_sp<SkSurface> MakeRenderTarget(sk_sp<GrContext> grContext, SimpleImageInfo sii) {
207-
sk_sp<SkSurface> surface(SkSurface::MakeRenderTarget(grContext.get(),
206+
sk_sp<SkSurface> MakeRenderTarget(sk_sp<GrDirectContext> dContext, SimpleImageInfo sii) {
207+
sk_sp<SkSurface> surface(SkSurface::MakeRenderTarget(dContext.get(),
208208
SkBudgeted::kYes,
209209
toSkImageInfo(sii), 0,
210210
kBottomLeft_GrSurfaceOrigin,
@@ -737,8 +737,8 @@ EMSCRIPTEN_BINDINGS(Skia) {
737737
function("setCurrentContext", &emscripten_webgl_make_context_current);
738738
function("MakeGrContext", &MakeGrContext);
739739
function("MakeOnScreenGLSurface", &MakeOnScreenGLSurface);
740-
function("MakeRenderTarget", select_overload<sk_sp<SkSurface>(sk_sp<GrContext>, int, int)>(&MakeRenderTarget));
741-
function("MakeRenderTarget", select_overload<sk_sp<SkSurface>(sk_sp<GrContext>, SimpleImageInfo)>(&MakeRenderTarget));
740+
function("MakeRenderTarget", select_overload<sk_sp<SkSurface>(sk_sp<GrDirectContext>, int, int)>(&MakeRenderTarget));
741+
function("MakeRenderTarget", select_overload<sk_sp<SkSurface>(sk_sp<GrDirectContext>, SimpleImageInfo)>(&MakeRenderTarget));
742742

743743
constant("gpu", true);
744744
#endif
@@ -910,22 +910,26 @@ EMSCRIPTEN_BINDINGS(Skia) {
910910
}), allow_raw_pointers());
911911

912912
#ifdef SK_GL
913-
class_<GrContext>("GrContext")
914-
.smart_ptr<sk_sp<GrContext>>("sk_sp<GrContext>")
915-
.function("getResourceCacheLimitBytes", optional_override([](GrContext& self)->size_t {
913+
class_<GrDirectContext>("GrDirectContext")
914+
.smart_ptr<sk_sp<GrDirectContext>>("sk_sp<GrDirectContext>")
915+
.function("getResourceCacheLimitBytes",
916+
optional_override([](GrDirectContext& self)->size_t {
916917
int maxResources = 0;// ignored
917918
size_t currMax = 0;
918919
self.getResourceCacheLimits(&maxResources, &currMax);
919920
return currMax;
920921
}))
921-
.function("getResourceCacheUsageBytes", optional_override([](GrContext& self)->size_t {
922+
.function("getResourceCacheUsageBytes",
923+
optional_override([](GrDirectContext& self)->size_t {
922924
int usedResources = 0;// ignored
923925
size_t currUsage = 0;
924926
self.getResourceCacheUsage(&usedResources, &currUsage);
925927
return currUsage;
926928
}))
927-
.function("releaseResourcesAndAbandonContext", &GrContext::releaseResourcesAndAbandonContext)
928-
.function("setResourceCacheLimitBytes", optional_override([](GrContext& self, size_t maxResourceBytes)->void {
929+
.function("releaseResourcesAndAbandonContext",
930+
&GrDirectContext::releaseResourcesAndAbandonContext)
931+
.function("setResourceCacheLimitBytes",
932+
optional_override([](GrDirectContext& self, size_t maxResourceBytes)->void {
929933
int maxResources = 0;
930934
size_t currMax = 0; // ignored
931935
self.getResourceCacheLimits(&maxResources, &currMax);

modules/canvaskit/viewer_bindings.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#include <emscripten/bind.h>
1010
#include "include/core/SkCanvas.h"
1111
#include "include/core/SkSurface.h"
12-
#include "include/gpu/GrContext.h"
1312
#include "tools/skui/InputState.h"
1413
#include "tools/skui/ModifierKey.h"
1514
#include "tools/viewer/SKPSlide.h"

site/user/api/skcanvas_creation.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ has been made current to the current thread when Skia calls are made.
8484

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

87-
#include "GrContext.h"
87+
#include "GrDirectContext.h"
8888
#include "gl/GrGLInterface.h"
8989
#include "SkData.h"
9090
#include "SkImage.h"

src/gpu/GrDDLContext.cpp

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* found in the LICENSE file.
66
*/
77

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

34-
void releaseResourcesAndAbandonContext() override {
35-
SkASSERT(0); // abandoning in a DDL Recorder doesn't make a whole lot of sense
36-
INHERITED::releaseResourcesAndAbandonContext();
37-
}
38-
39-
void freeGpuResources() override {
40-
// freeing resources in a DDL Recorder doesn't make a whole lot of sense but some of
41-
// our tests do it anyways
42-
}
43-
4434
private:
45-
// TODO: Here we're pretending this isn't derived from GrContext. Switch this to be derived from
46-
// GrRecordingContext!
47-
GrDirectContext* asDirectContext() override { return nullptr; }
48-
4935
bool init() override {
5036
if (!INHERITED::init()) {
5137
return false;
@@ -58,16 +44,6 @@ class GrDDLContext final : public GrContext {
5844
return true;
5945
}
6046

61-
GrAtlasManager* onGetAtlasManager() override {
62-
SkASSERT(0); // the DDL Recorders should never invoke this
63-
return nullptr;
64-
}
65-
66-
GrSmallPathAtlasMgr* onGetSmallPathAtlasMgr() override {
67-
SkASSERT(0); // DDL recorders should never invoke this
68-
return nullptr;
69-
}
70-
7147
// Add to the set of unique program infos required by this DDL
7248
void recordProgramInfo(const GrProgramInfo* programInfo) final {
7349
if (!programInfo) {
@@ -149,7 +125,7 @@ class GrDDLContext final : public GrContext {
149125

150126
ProgramInfoMap fProgramInfoMap;
151127

152-
using INHERITED = GrContext;
128+
using INHERITED = GrRecordingContext;
153129
};
154130

155131
sk_sp<GrRecordingContext> GrRecordingContextPriv::MakeDDL(sk_sp<GrContextThreadSafeProxy> proxy) {

0 commit comments

Comments
 (0)