Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit f123f06

Browse files
rphilliSkia Commit-Bot
authored and
Skia Commit-Bot
committed
Expose GrRecordingContext accessor on SkCanvas and SkSurface
We'll need this if we're ever to get rid of GrContext. It is pulled out of: https://skia-review.googlesource.com/c/skia/+/296704 (Downgrade GpuGMs to only receiving a GrRecordingContext) Bug: skia:10441 Change-Id: I964b5caf3e947afbfc7d441a8e17ad298961d8f3 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/299295 Commit-Queue: Robert Phillips <[email protected]> Reviewed-by: Brian Salomon <[email protected]>
1 parent 1ca54d4 commit f123f06

File tree

9 files changed

+32
-0
lines changed

9 files changed

+32
-0
lines changed

include/core/SkCanvas.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include <vector>
3434

3535
class GrContext;
36+
class GrRecordingContext;
3637
class GrRenderTargetContext;
3738
class SkBaseDevice;
3839
class SkBitmap;
@@ -289,6 +290,11 @@ class SK_API SkCanvas {
289290
*/
290291
virtual GrContext* getGrContext();
291292

293+
/**
294+
* Experimental. SkCanvases can actually only guarantee a GrRecordingContext.
295+
*/
296+
virtual GrRecordingContext* recordingContext();
297+
292298
/** Sometimes a canvas is owned by a surface. If it is, getSurface() will return a bare
293299
* pointer to that surface, else this will return nullptr.
294300
*/

include/core/SkSurface.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,11 @@ class SK_API SkSurface : public SkRefCnt {
531531
*/
532532
GrContext* getContext();
533533

534+
/**
535+
* Experimental. SkSurfaces can actually only guarantee a GrRecordingContext.
536+
*/
537+
GrRecordingContext* recordingContext();
538+
534539
enum BackendHandleAccess {
535540
kFlushRead_BackendHandleAccess, //!< back-end object is readable
536541
kFlushWrite_BackendHandleAccess, //!< back-end object is writable

src/core/SkCanvas.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1865,6 +1865,11 @@ GrContext* SkCanvas::getGrContext() {
18651865
return device ? device->context() : nullptr;
18661866
}
18671867

1868+
GrRecordingContext* SkCanvas::recordingContext() {
1869+
SkBaseDevice* device = this->getTopDevice();
1870+
return device ? device->recordingContext() : nullptr;
1871+
}
1872+
18681873
void SkCanvas::drawDRRect(const SkRRect& outer, const SkRRect& inner,
18691874
const SkPaint& paint) {
18701875
TRACE_EVENT0("skia", TRACE_FUNC);

src/core/SkDevice.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,7 @@ class SkBaseDevice : public SkRefCnt, public SkMatrixProvider {
317317
///////////////////////////////////////////////////////////////////////////
318318

319319
virtual GrContext* context() const { return nullptr; }
320+
virtual GrRecordingContext* recordingContext() const { return nullptr; }
320321

321322
virtual sk_sp<SkSurface> makeSurface(const SkImageInfo&, const SkSurfaceProps&);
322323
virtual bool onPeekPixels(SkPixmap*) { return false; }

src/gpu/SkGpuDevice.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ class SkGpuDevice : public SkClipStackDevice {
6262
~SkGpuDevice() override {}
6363

6464
GrContext* context() const override { return fContext.get(); }
65+
GrRecordingContext* recordingContext() const override { return fContext.get(); }
6566

6667
// set all pixels to 0
6768
void clearAll();

src/image/SkSurface.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ GrContext* SkSurface_Base::onGetContext() {
7676
return nullptr;
7777
}
7878

79+
GrRecordingContext* SkSurface_Base::onGetRecordingContext() {
80+
return nullptr;
81+
}
82+
7983
GrBackendTexture SkSurface_Base::onGetBackendTexture(BackendHandleAccess) {
8084
return GrBackendTexture(); // invalid
8185
}
@@ -332,6 +336,10 @@ GrContext* SkSurface::getContext() {
332336
return asSB(this)->onGetContext();
333337
}
334338

339+
GrRecordingContext* SkSurface::recordingContext() {
340+
return asSB(this)->onGetRecordingContext();
341+
}
342+
335343
GrBackendTexture SkSurface::getBackendTexture(BackendHandleAccess access) {
336344
return asSB(this)->onGetBackendTexture(access);
337345
}

src/image/SkSurface_Base.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class SkSurface_Base : public SkSurface {
2121
virtual ~SkSurface_Base();
2222

2323
virtual GrContext* onGetContext();
24+
virtual GrRecordingContext* onGetRecordingContext();
2425

2526
virtual GrBackendTexture onGetBackendTexture(BackendHandleAccess);
2627
virtual GrBackendRenderTarget onGetBackendRenderTarget(BackendHandleAccess);

src/image/SkSurface_Gpu.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ GrContext* SkSurface_Gpu::onGetContext() {
4343
return fDevice->context();
4444
}
4545

46+
GrRecordingContext* SkSurface_Gpu::onGetRecordingContext() {
47+
return fDevice->recordingContext();
48+
}
49+
4650
static GrRenderTarget* prepare_rt_for_external_access(SkSurface_Gpu* surface,
4751
SkSurface::BackendHandleAccess access) {
4852
switch (access) {

src/image/SkSurface_Gpu.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class SkSurface_Gpu : public SkSurface_Base {
2626
std::unique_ptr<GrRenderTargetContext>);
2727

2828
GrContext* onGetContext() override;
29+
GrRecordingContext* onGetRecordingContext() override;
2930

3031
GrBackendTexture onGetBackendTexture(BackendHandleAccess) override;
3132
GrBackendRenderTarget onGetBackendRenderTarget(BackendHandleAccess) override;

0 commit comments

Comments
 (0)