Skip to content

Commit c57aff1

Browse files
authored
Use the GrDirectContext factories instead of deprecated GrContext ones (flutter#19962)
This is part of a larger effort to expose the difference between GrDirectContext, which runs on the GPU thread and can directly perform operations like uploading textures, and GrRecordingContext, which can only queue up work to be delivered to the GrDirectContext later.
1 parent 2d8a00e commit c57aff1

File tree

116 files changed

+307
-283
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

116 files changed

+307
-283
lines changed

flow/compositor_context.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ void CompositorContext::EndFrame(ScopedFrame& frame,
3131
}
3232

3333
std::unique_ptr<CompositorContext::ScopedFrame> CompositorContext::AcquireFrame(
34-
GrContext* gr_context,
34+
GrDirectContext* gr_context,
3535
SkCanvas* canvas,
3636
ExternalViewEmbedder* view_embedder,
3737
const SkMatrix& root_surface_transformation,
@@ -45,7 +45,7 @@ std::unique_ptr<CompositorContext::ScopedFrame> CompositorContext::AcquireFrame(
4545

4646
CompositorContext::ScopedFrame::ScopedFrame(
4747
CompositorContext& context,
48-
GrContext* gr_context,
48+
GrDirectContext* gr_context,
4949
SkCanvas* canvas,
5050
ExternalViewEmbedder* view_embedder,
5151
const SkMatrix& root_surface_transformation,

flow/compositor_context.h

+5-5
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#include "flutter/fml/macros.h"
1616
#include "flutter/fml/raster_thread_merger.h"
1717
#include "third_party/skia/include/core/SkCanvas.h"
18-
#include "third_party/skia/include/gpu/GrContext.h"
18+
#include "third_party/skia/include/gpu/GrDirectContext.h"
1919

2020
namespace flutter {
2121

@@ -40,7 +40,7 @@ class CompositorContext {
4040
class ScopedFrame {
4141
public:
4242
ScopedFrame(CompositorContext& context,
43-
GrContext* gr_context,
43+
GrDirectContext* gr_context,
4444
SkCanvas* canvas,
4545
ExternalViewEmbedder* view_embedder,
4646
const SkMatrix& root_surface_transformation,
@@ -62,14 +62,14 @@ class CompositorContext {
6262

6363
bool surface_supports_readback() { return surface_supports_readback_; }
6464

65-
GrContext* gr_context() const { return gr_context_; }
65+
GrDirectContext* gr_context() const { return gr_context_; }
6666

6767
virtual RasterStatus Raster(LayerTree& layer_tree,
6868
bool ignore_raster_cache);
6969

7070
private:
7171
CompositorContext& context_;
72-
GrContext* gr_context_;
72+
GrDirectContext* gr_context_;
7373
SkCanvas* canvas_;
7474
ExternalViewEmbedder* view_embedder_;
7575
const SkMatrix& root_surface_transformation_;
@@ -85,7 +85,7 @@ class CompositorContext {
8585
virtual ~CompositorContext();
8686

8787
virtual std::unique_ptr<ScopedFrame> AcquireFrame(
88-
GrContext* gr_context,
88+
GrDirectContext* gr_context,
8989
SkCanvas* canvas,
9090
ExternalViewEmbedder* view_embedder,
9191
const SkMatrix& root_surface_transformation,

flow/embedded_views.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
namespace flutter {
88

9-
void ExternalViewEmbedder::SubmitFrame(GrContext* context,
9+
void ExternalViewEmbedder::SubmitFrame(GrDirectContext* context,
1010
std::unique_ptr<SurfaceFrame> frame) {
1111
frame->Submit();
1212
};

flow/embedded_views.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ class ExternalViewEmbedder {
268268

269269
virtual void BeginFrame(
270270
SkISize frame_size,
271-
GrContext* context,
271+
GrDirectContext* context,
272272
double device_pixel_ratio,
273273
fml::RefPtr<fml::RasterThreadMerger> raster_thread_merger) = 0;
274274

@@ -295,7 +295,7 @@ class ExternalViewEmbedder {
295295
// This method can mutate the root Skia canvas before submitting the frame.
296296
//
297297
// It can also allocate frames for overlay surfaces to compose hybrid views.
298-
virtual void SubmitFrame(GrContext* context,
298+
virtual void SubmitFrame(GrDirectContext* context,
299299
std::unique_ptr<SurfaceFrame> frame);
300300

301301
// This method provides the embedder a way to do additional tasks after

flow/layers/layer.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ enum Clip { none, hardEdge, antiAlias, antiAliasWithSaveLayer };
4444

4545
struct PrerollContext {
4646
RasterCache* raster_cache;
47-
GrContext* gr_context;
47+
GrDirectContext* gr_context;
4848
ExternalViewEmbedder* view_embedder;
4949
MutatorsStack& mutators_stack;
5050
SkColorSpace* dst_color_space;
@@ -121,7 +121,7 @@ class Layer {
121121
// layers.
122122
SkCanvas* internal_nodes_canvas;
123123
SkCanvas* leaf_nodes_canvas;
124-
GrContext* gr_context;
124+
GrDirectContext* gr_context;
125125
ExternalViewEmbedder* view_embedder;
126126
const Stopwatch& raster_time;
127127
const Stopwatch& ui_time;

flow/raster_cache.cc

+4-4
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#include "third_party/skia/include/core/SkImage.h"
1616
#include "third_party/skia/include/core/SkPicture.h"
1717
#include "third_party/skia/include/core/SkSurface.h"
18-
#include "third_party/skia/include/gpu/GrContext.h"
18+
#include "third_party/skia/include/gpu/GrDirectContext.h"
1919

2020
namespace flutter {
2121

@@ -89,7 +89,7 @@ static bool IsPictureWorthRasterizing(SkPicture* picture,
8989

9090
/// @note Procedure doesn't copy all closures.
9191
static std::unique_ptr<RasterCacheResult> Rasterize(
92-
GrContext* context,
92+
GrDirectContext* context,
9393
const SkMatrix& ctm,
9494
SkColorSpace* dst_color_space,
9595
bool checkerboard,
@@ -126,7 +126,7 @@ static std::unique_ptr<RasterCacheResult> Rasterize(
126126

127127
std::unique_ptr<RasterCacheResult> RasterCache::RasterizePicture(
128128
SkPicture* picture,
129-
GrContext* context,
129+
GrDirectContext* context,
130130
const SkMatrix& ctm,
131131
SkColorSpace* dst_color_space,
132132
bool checkerboard) const {
@@ -177,7 +177,7 @@ std::unique_ptr<RasterCacheResult> RasterCache::RasterizeLayer(
177177
});
178178
}
179179

180-
bool RasterCache::Prepare(GrContext* context,
180+
bool RasterCache::Prepare(GrDirectContext* context,
181181
SkPicture* picture,
182182
const SkMatrix& transformation_matrix,
183183
SkColorSpace* dst_color_space,

flow/raster_cache.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ class RasterCache {
7272
*/
7373
virtual std::unique_ptr<RasterCacheResult> RasterizePicture(
7474
SkPicture* picture,
75-
GrContext* context,
75+
GrDirectContext* context,
7676
const SkMatrix& ctm,
7777
SkColorSpace* dst_color_space,
7878
bool checkerboard) const;
@@ -134,7 +134,7 @@ class RasterCache {
134134
// 3. The picture is accessed too few times
135135
// 4. There are too many pictures to be cached in the current frame.
136136
// (See also kDefaultPictureCacheLimitPerFrame.)
137-
bool Prepare(GrContext* context,
137+
bool Prepare(GrDirectContext* context,
138138
SkPicture* picture,
139139
const SkMatrix& transformation_matrix,
140140
SkColorSpace* dst_color_space,

flow/scene_update_context.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ class SceneUpdateContext : public flutter::ExternalViewEmbedder {
214214
// |ExternalViewEmbedder|
215215
void BeginFrame(
216216
SkISize frame_size,
217-
GrContext* context,
217+
GrDirectContext* context,
218218
double device_pixel_ratio,
219219
fml::RefPtr<fml::RasterThreadMerger> raster_thread_merger) override {}
220220

flow/skia_gpu_object.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#include "flutter/fml/memory/weak_ptr.h"
1313
#include "flutter/fml/task_runner.h"
1414
#include "third_party/skia/include/core/SkRefCnt.h"
15-
#include "third_party/skia/include/gpu/GrContext.h"
15+
#include "third_party/skia/include/gpu/GrDirectContext.h"
1616

1717
namespace flutter {
1818

@@ -37,7 +37,7 @@ class SkiaUnrefQueue : public fml::RefCountedThreadSafe<SkiaUnrefQueue> {
3737
bool drain_pending_;
3838
fml::WeakPtr<GrContext> context_;
3939

40-
// The `GrContext* context` is only used for signaling Skia to
40+
// The `GrDirectContext* context` is only used for signaling Skia to
4141
// performDeferredCleanup. It can be nullptr when such signaling is not needed
4242
// (e.g., in unit tests).
4343
SkiaUnrefQueue(fml::RefPtr<fml::TaskRunner> task_runner,

flow/surface.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class Surface {
2727

2828
virtual SkMatrix GetRootTransformation() const = 0;
2929

30-
virtual GrContext* GetContext() = 0;
30+
virtual GrDirectContext* GetContext() = 0;
3131

3232
virtual flutter::ExternalViewEmbedder* GetExternalViewEmbedder();
3333

flow/testing/mock_raster_cache.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ MockRasterCacheResult::MockRasterCacheResult(SkIRect device_rect)
1515

1616
std::unique_ptr<RasterCacheResult> MockRasterCache::RasterizePicture(
1717
SkPicture* picture,
18-
GrContext* context,
18+
GrDirectContext* context,
1919
const SkMatrix& ctm,
2020
SkColorSpace* dst_color_space,
2121
bool checkerboard) const {

flow/testing/mock_raster_cache.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class MockRasterCache : public RasterCache {
4646
public:
4747
std::unique_ptr<RasterCacheResult> RasterizePicture(
4848
SkPicture* picture,
49-
GrContext* context,
49+
GrDirectContext* context,
5050
const SkMatrix& ctm,
5151
SkColorSpace* dst_color_space,
5252
bool checkerboard) const override;

flow/testing/mock_texture.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ MockTexture::MockTexture(int64_t textureId) : Texture(textureId) {}
1212
void MockTexture::Paint(SkCanvas& canvas,
1313
const SkRect& bounds,
1414
bool freeze,
15-
GrContext* context,
15+
GrDirectContext* context,
1616
SkFilterQuality filter_quality) {
1717
paint_calls_.emplace_back(
1818
PaintCall{canvas, bounds, freeze, context, filter_quality});

flow/testing/mock_texture.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class MockTexture : public Texture {
2020
SkCanvas& canvas;
2121
SkRect bounds;
2222
bool freeze;
23-
GrContext* context;
23+
GrDirectContext* context;
2424
SkFilterQuality filter_quality;
2525
};
2626

@@ -30,7 +30,7 @@ class MockTexture : public Texture {
3030
void Paint(SkCanvas& canvas,
3131
const SkRect& bounds,
3232
bool freeze,
33-
GrContext* context,
33+
GrDirectContext* context,
3434
SkFilterQuality filter_quality) override;
3535

3636
void OnGrContextCreated() override { gr_context_created_ = true; }

flow/texture.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
#include "flutter/fml/synchronization/waitable_event.h"
1212
#include "third_party/skia/include/core/SkCanvas.h"
1313

14+
class GrDirectContext;
15+
1416
namespace flutter {
1517

1618
class Texture {
@@ -22,7 +24,7 @@ class Texture {
2224
virtual void Paint(SkCanvas& canvas,
2325
const SkRect& bounds,
2426
bool freeze,
25-
GrContext* context,
27+
GrDirectContext* context,
2628
SkFilterQuality quality) = 0;
2729

2830
// Called from raster thread.

lib/ui/io_manager.h

+5-5
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,19 @@
88
#include "flutter/flow/skia_gpu_object.h"
99
#include "flutter/fml/memory/weak_ptr.h"
1010
#include "flutter/fml/synchronization/sync_switch.h"
11-
#include "third_party/skia/include/gpu/GrContext.h"
11+
#include "third_party/skia/include/gpu/GrDirectContext.h"
1212

1313
namespace flutter {
14-
// Interface for methods that manage access to the resource GrContext and Skia
15-
// unref queue. Meant to be implemented by the owner of the resource GrContext,
16-
// i.e. the shell's IOManager.
14+
// Interface for methods that manage access to the resource GrDirectContext and
15+
// Skia unref queue. Meant to be implemented by the owner of the resource
16+
// GrDirectContext, i.e. the shell's IOManager.
1717
class IOManager {
1818
public:
1919
virtual ~IOManager() = default;
2020

2121
virtual fml::WeakPtr<IOManager> GetWeakIOManager() const = 0;
2222

23-
virtual fml::WeakPtr<GrContext> GetResourceContext() const = 0;
23+
virtual fml::WeakPtr<GrDirectContext> GetResourceContext() const = 0;
2424

2525
virtual fml::RefPtr<flutter::SkiaUnrefQueue> GetSkiaUnrefQueue() const = 0;
2626

lib/ui/painting/image_decoder_unittests.cc

+9-7
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,10 @@ class TestIOManager final : public IOManager {
2828
: gl_surface_(SkISize::Make(1, 1)),
2929
gl_context_(has_gpu_context ? gl_surface_.CreateGrContext() : nullptr),
3030
weak_gl_context_factory_(
31-
has_gpu_context ? std::make_unique<fml::WeakPtrFactory<GrContext>>(
32-
gl_context_.get())
33-
: nullptr),
31+
has_gpu_context
32+
? std::make_unique<fml::WeakPtrFactory<GrDirectContext>>(
33+
gl_context_.get())
34+
: nullptr),
3435
unref_queue_(fml::MakeRefCounted<SkiaUnrefQueue>(
3536
task_runner,
3637
fml::TimeDelta::FromNanoseconds(0))),
@@ -59,9 +60,9 @@ class TestIOManager final : public IOManager {
5960
}
6061

6162
// |IOManager|
62-
fml::WeakPtr<GrContext> GetResourceContext() const override {
63+
fml::WeakPtr<GrDirectContext> GetResourceContext() const override {
6364
return weak_gl_context_factory_ ? weak_gl_context_factory_->GetWeakPtr()
64-
: fml::WeakPtr<GrContext>{};
65+
: fml::WeakPtr<GrDirectContext>{};
6566
}
6667

6768
// |IOManager|
@@ -79,8 +80,9 @@ class TestIOManager final : public IOManager {
7980

8081
private:
8182
TestGLSurface gl_surface_;
82-
sk_sp<GrContext> gl_context_;
83-
std::unique_ptr<fml::WeakPtrFactory<GrContext>> weak_gl_context_factory_;
83+
sk_sp<GrDirectContext> gl_context_;
84+
std::unique_ptr<fml::WeakPtrFactory<GrDirectContext>>
85+
weak_gl_context_factory_;
8486
fml::RefPtr<SkiaUnrefQueue> unref_queue_;
8587
fml::WeakPtr<TestIOManager> weak_prototype_;
8688
fml::RefPtr<fml::TaskRunner> runner_;

lib/ui/painting/image_encoding.cc

+3-3
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ void InvokeDataCallback(std::unique_ptr<DartPersistentValue> callback,
5454

5555
sk_sp<SkImage> ConvertToRasterUsingResourceContext(
5656
sk_sp<SkImage> image,
57-
GrContext* resource_context) {
57+
GrDirectContext* resource_context) {
5858
sk_sp<SkSurface> surface;
5959
SkImageInfo surface_info = SkImageInfo::MakeN32Premul(image->dimensions());
6060
if (resource_context) {
@@ -86,7 +86,7 @@ void ConvertImageToRaster(sk_sp<SkImage> image,
8686
std::function<void(sk_sp<SkImage>)> encode_task,
8787
fml::RefPtr<fml::TaskRunner> raster_task_runner,
8888
fml::RefPtr<fml::TaskRunner> io_task_runner,
89-
GrContext* resource_context,
89+
GrDirectContext* resource_context,
9090
fml::WeakPtr<SnapshotDelegate> snapshot_delegate) {
9191
// Check validity of the image.
9292
if (image == nullptr) {
@@ -213,7 +213,7 @@ void EncodeImageAndInvokeDataCallback(
213213
fml::RefPtr<fml::TaskRunner> ui_task_runner,
214214
fml::RefPtr<fml::TaskRunner> raster_task_runner,
215215
fml::RefPtr<fml::TaskRunner> io_task_runner,
216-
GrContext* resource_context,
216+
GrDirectContext* resource_context,
217217
fml::WeakPtr<SnapshotDelegate> snapshot_delegate) {
218218
auto callback_task = fml::MakeCopyable(
219219
[callback = std::move(callback)](sk_sp<SkData> encoded) mutable {

lib/ui/ui_dart_state.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#include "flutter/lib/ui/painting/image_decoder.h"
2121
#include "flutter/lib/ui/snapshot_delegate.h"
2222
#include "third_party/dart/runtime/include/dart_api.h"
23-
#include "third_party/skia/include/gpu/GrContext.h"
23+
#include "third_party/skia/include/gpu/GrDirectContext.h"
2424
#include "third_party/tonic/dart_microtask_queue.h"
2525
#include "third_party/tonic/dart_persistent_value.h"
2626
#include "third_party/tonic/dart_state.h"

lib/ui/window/window.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#include "flutter/lib/ui/window/platform_message.h"
1515
#include "flutter/lib/ui/window/pointer_data_packet.h"
1616
#include "flutter/lib/ui/window/viewport_metrics.h"
17-
#include "third_party/skia/include/gpu/GrContext.h"
17+
#include "third_party/skia/include/gpu/GrDirectContext.h"
1818
#include "third_party/tonic/dart_persistent_value.h"
1919

2020
namespace tonic {

shell/common/platform_view.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ void PlatformView::NotifyDestroyed() {
8282
delegate_.OnPlatformViewDestroyed();
8383
}
8484

85-
sk_sp<GrContext> PlatformView::CreateResourceContext() const {
85+
sk_sp<GrDirectContext> PlatformView::CreateResourceContext() const {
8686
FML_DLOG(WARNING) << "This platform does not setup the resource "
8787
"context on the IO thread for async texture uploads.";
8888
return nullptr;

shell/common/platform_view.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#include "flutter/shell/common/pointer_data_dispatcher.h"
2222
#include "flutter/shell/common/vsync_waiter.h"
2323
#include "third_party/skia/include/core/SkSize.h"
24-
#include "third_party/skia/include/gpu/GrContext.h"
24+
#include "third_party/skia/include/gpu/GrDirectContext.h"
2525

2626
namespace flutter {
2727

@@ -427,7 +427,7 @@ class PlatformView {
427427
/// main render thread GPU context. May be `nullptr` in case such
428428
/// a context cannot be created.
429429
///
430-
virtual sk_sp<GrContext> CreateResourceContext() const;
430+
virtual sk_sp<GrDirectContext> CreateResourceContext() const;
431431

432432
//----------------------------------------------------------------------------
433433
/// @brief Used by the shell to notify the embedder that the resource

0 commit comments

Comments
 (0)