Skip to content

Commit

Permalink
Use the GrDirectContext factories instead of deprecated GrContext ones (
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Adlai-Holler authored Jul 28, 2020
1 parent 2d8a00e commit c57aff1
Show file tree
Hide file tree
Showing 116 changed files with 307 additions and 283 deletions.
4 changes: 2 additions & 2 deletions flow/compositor_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ void CompositorContext::EndFrame(ScopedFrame& frame,
}

std::unique_ptr<CompositorContext::ScopedFrame> CompositorContext::AcquireFrame(
GrContext* gr_context,
GrDirectContext* gr_context,
SkCanvas* canvas,
ExternalViewEmbedder* view_embedder,
const SkMatrix& root_surface_transformation,
Expand All @@ -45,7 +45,7 @@ std::unique_ptr<CompositorContext::ScopedFrame> CompositorContext::AcquireFrame(

CompositorContext::ScopedFrame::ScopedFrame(
CompositorContext& context,
GrContext* gr_context,
GrDirectContext* gr_context,
SkCanvas* canvas,
ExternalViewEmbedder* view_embedder,
const SkMatrix& root_surface_transformation,
Expand Down
10 changes: 5 additions & 5 deletions flow/compositor_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include "flutter/fml/macros.h"
#include "flutter/fml/raster_thread_merger.h"
#include "third_party/skia/include/core/SkCanvas.h"
#include "third_party/skia/include/gpu/GrContext.h"
#include "third_party/skia/include/gpu/GrDirectContext.h"

namespace flutter {

Expand All @@ -40,7 +40,7 @@ class CompositorContext {
class ScopedFrame {
public:
ScopedFrame(CompositorContext& context,
GrContext* gr_context,
GrDirectContext* gr_context,
SkCanvas* canvas,
ExternalViewEmbedder* view_embedder,
const SkMatrix& root_surface_transformation,
Expand All @@ -62,14 +62,14 @@ class CompositorContext {

bool surface_supports_readback() { return surface_supports_readback_; }

GrContext* gr_context() const { return gr_context_; }
GrDirectContext* gr_context() const { return gr_context_; }

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

private:
CompositorContext& context_;
GrContext* gr_context_;
GrDirectContext* gr_context_;
SkCanvas* canvas_;
ExternalViewEmbedder* view_embedder_;
const SkMatrix& root_surface_transformation_;
Expand All @@ -85,7 +85,7 @@ class CompositorContext {
virtual ~CompositorContext();

virtual std::unique_ptr<ScopedFrame> AcquireFrame(
GrContext* gr_context,
GrDirectContext* gr_context,
SkCanvas* canvas,
ExternalViewEmbedder* view_embedder,
const SkMatrix& root_surface_transformation,
Expand Down
2 changes: 1 addition & 1 deletion flow/embedded_views.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace flutter {

void ExternalViewEmbedder::SubmitFrame(GrContext* context,
void ExternalViewEmbedder::SubmitFrame(GrDirectContext* context,
std::unique_ptr<SurfaceFrame> frame) {
frame->Submit();
};
Expand Down
4 changes: 2 additions & 2 deletions flow/embedded_views.h
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ class ExternalViewEmbedder {

virtual void BeginFrame(
SkISize frame_size,
GrContext* context,
GrDirectContext* context,
double device_pixel_ratio,
fml::RefPtr<fml::RasterThreadMerger> raster_thread_merger) = 0;

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

// This method provides the embedder a way to do additional tasks after
Expand Down
4 changes: 2 additions & 2 deletions flow/layers/layer.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ enum Clip { none, hardEdge, antiAlias, antiAliasWithSaveLayer };

struct PrerollContext {
RasterCache* raster_cache;
GrContext* gr_context;
GrDirectContext* gr_context;
ExternalViewEmbedder* view_embedder;
MutatorsStack& mutators_stack;
SkColorSpace* dst_color_space;
Expand Down Expand Up @@ -121,7 +121,7 @@ class Layer {
// layers.
SkCanvas* internal_nodes_canvas;
SkCanvas* leaf_nodes_canvas;
GrContext* gr_context;
GrDirectContext* gr_context;
ExternalViewEmbedder* view_embedder;
const Stopwatch& raster_time;
const Stopwatch& ui_time;
Expand Down
8 changes: 4 additions & 4 deletions flow/raster_cache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include "third_party/skia/include/core/SkImage.h"
#include "third_party/skia/include/core/SkPicture.h"
#include "third_party/skia/include/core/SkSurface.h"
#include "third_party/skia/include/gpu/GrContext.h"
#include "third_party/skia/include/gpu/GrDirectContext.h"

namespace flutter {

Expand Down Expand Up @@ -89,7 +89,7 @@ static bool IsPictureWorthRasterizing(SkPicture* picture,

/// @note Procedure doesn't copy all closures.
static std::unique_ptr<RasterCacheResult> Rasterize(
GrContext* context,
GrDirectContext* context,
const SkMatrix& ctm,
SkColorSpace* dst_color_space,
bool checkerboard,
Expand Down Expand Up @@ -126,7 +126,7 @@ static std::unique_ptr<RasterCacheResult> Rasterize(

std::unique_ptr<RasterCacheResult> RasterCache::RasterizePicture(
SkPicture* picture,
GrContext* context,
GrDirectContext* context,
const SkMatrix& ctm,
SkColorSpace* dst_color_space,
bool checkerboard) const {
Expand Down Expand Up @@ -177,7 +177,7 @@ std::unique_ptr<RasterCacheResult> RasterCache::RasterizeLayer(
});
}

bool RasterCache::Prepare(GrContext* context,
bool RasterCache::Prepare(GrDirectContext* context,
SkPicture* picture,
const SkMatrix& transformation_matrix,
SkColorSpace* dst_color_space,
Expand Down
4 changes: 2 additions & 2 deletions flow/raster_cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class RasterCache {
*/
virtual std::unique_ptr<RasterCacheResult> RasterizePicture(
SkPicture* picture,
GrContext* context,
GrDirectContext* context,
const SkMatrix& ctm,
SkColorSpace* dst_color_space,
bool checkerboard) const;
Expand Down Expand Up @@ -134,7 +134,7 @@ class RasterCache {
// 3. The picture is accessed too few times
// 4. There are too many pictures to be cached in the current frame.
// (See also kDefaultPictureCacheLimitPerFrame.)
bool Prepare(GrContext* context,
bool Prepare(GrDirectContext* context,
SkPicture* picture,
const SkMatrix& transformation_matrix,
SkColorSpace* dst_color_space,
Expand Down
2 changes: 1 addition & 1 deletion flow/scene_update_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ class SceneUpdateContext : public flutter::ExternalViewEmbedder {
// |ExternalViewEmbedder|
void BeginFrame(
SkISize frame_size,
GrContext* context,
GrDirectContext* context,
double device_pixel_ratio,
fml::RefPtr<fml::RasterThreadMerger> raster_thread_merger) override {}

Expand Down
4 changes: 2 additions & 2 deletions flow/skia_gpu_object.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include "flutter/fml/memory/weak_ptr.h"
#include "flutter/fml/task_runner.h"
#include "third_party/skia/include/core/SkRefCnt.h"
#include "third_party/skia/include/gpu/GrContext.h"
#include "third_party/skia/include/gpu/GrDirectContext.h"

namespace flutter {

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

// The `GrContext* context` is only used for signaling Skia to
// The `GrDirectContext* context` is only used for signaling Skia to
// performDeferredCleanup. It can be nullptr when such signaling is not needed
// (e.g., in unit tests).
SkiaUnrefQueue(fml::RefPtr<fml::TaskRunner> task_runner,
Expand Down
2 changes: 1 addition & 1 deletion flow/surface.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class Surface {

virtual SkMatrix GetRootTransformation() const = 0;

virtual GrContext* GetContext() = 0;
virtual GrDirectContext* GetContext() = 0;

virtual flutter::ExternalViewEmbedder* GetExternalViewEmbedder();

Expand Down
2 changes: 1 addition & 1 deletion flow/testing/mock_raster_cache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ MockRasterCacheResult::MockRasterCacheResult(SkIRect device_rect)

std::unique_ptr<RasterCacheResult> MockRasterCache::RasterizePicture(
SkPicture* picture,
GrContext* context,
GrDirectContext* context,
const SkMatrix& ctm,
SkColorSpace* dst_color_space,
bool checkerboard) const {
Expand Down
2 changes: 1 addition & 1 deletion flow/testing/mock_raster_cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class MockRasterCache : public RasterCache {
public:
std::unique_ptr<RasterCacheResult> RasterizePicture(
SkPicture* picture,
GrContext* context,
GrDirectContext* context,
const SkMatrix& ctm,
SkColorSpace* dst_color_space,
bool checkerboard) const override;
Expand Down
2 changes: 1 addition & 1 deletion flow/testing/mock_texture.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ MockTexture::MockTexture(int64_t textureId) : Texture(textureId) {}
void MockTexture::Paint(SkCanvas& canvas,
const SkRect& bounds,
bool freeze,
GrContext* context,
GrDirectContext* context,
SkFilterQuality filter_quality) {
paint_calls_.emplace_back(
PaintCall{canvas, bounds, freeze, context, filter_quality});
Expand Down
4 changes: 2 additions & 2 deletions flow/testing/mock_texture.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class MockTexture : public Texture {
SkCanvas& canvas;
SkRect bounds;
bool freeze;
GrContext* context;
GrDirectContext* context;
SkFilterQuality filter_quality;
};

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

void OnGrContextCreated() override { gr_context_created_ = true; }
Expand Down
4 changes: 3 additions & 1 deletion flow/texture.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#include "flutter/fml/synchronization/waitable_event.h"
#include "third_party/skia/include/core/SkCanvas.h"

class GrDirectContext;

namespace flutter {

class Texture {
Expand All @@ -22,7 +24,7 @@ class Texture {
virtual void Paint(SkCanvas& canvas,
const SkRect& bounds,
bool freeze,
GrContext* context,
GrDirectContext* context,
SkFilterQuality quality) = 0;

// Called from raster thread.
Expand Down
10 changes: 5 additions & 5 deletions lib/ui/io_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@
#include "flutter/flow/skia_gpu_object.h"
#include "flutter/fml/memory/weak_ptr.h"
#include "flutter/fml/synchronization/sync_switch.h"
#include "third_party/skia/include/gpu/GrContext.h"
#include "third_party/skia/include/gpu/GrDirectContext.h"

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

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

virtual fml::WeakPtr<GrContext> GetResourceContext() const = 0;
virtual fml::WeakPtr<GrDirectContext> GetResourceContext() const = 0;

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

Expand Down
16 changes: 9 additions & 7 deletions lib/ui/painting/image_decoder_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@ class TestIOManager final : public IOManager {
: gl_surface_(SkISize::Make(1, 1)),
gl_context_(has_gpu_context ? gl_surface_.CreateGrContext() : nullptr),
weak_gl_context_factory_(
has_gpu_context ? std::make_unique<fml::WeakPtrFactory<GrContext>>(
gl_context_.get())
: nullptr),
has_gpu_context
? std::make_unique<fml::WeakPtrFactory<GrDirectContext>>(
gl_context_.get())
: nullptr),
unref_queue_(fml::MakeRefCounted<SkiaUnrefQueue>(
task_runner,
fml::TimeDelta::FromNanoseconds(0))),
Expand Down Expand Up @@ -59,9 +60,9 @@ class TestIOManager final : public IOManager {
}

// |IOManager|
fml::WeakPtr<GrContext> GetResourceContext() const override {
fml::WeakPtr<GrDirectContext> GetResourceContext() const override {
return weak_gl_context_factory_ ? weak_gl_context_factory_->GetWeakPtr()
: fml::WeakPtr<GrContext>{};
: fml::WeakPtr<GrDirectContext>{};
}

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

private:
TestGLSurface gl_surface_;
sk_sp<GrContext> gl_context_;
std::unique_ptr<fml::WeakPtrFactory<GrContext>> weak_gl_context_factory_;
sk_sp<GrDirectContext> gl_context_;
std::unique_ptr<fml::WeakPtrFactory<GrDirectContext>>
weak_gl_context_factory_;
fml::RefPtr<SkiaUnrefQueue> unref_queue_;
fml::WeakPtr<TestIOManager> weak_prototype_;
fml::RefPtr<fml::TaskRunner> runner_;
Expand Down
6 changes: 3 additions & 3 deletions lib/ui/painting/image_encoding.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ void InvokeDataCallback(std::unique_ptr<DartPersistentValue> callback,

sk_sp<SkImage> ConvertToRasterUsingResourceContext(
sk_sp<SkImage> image,
GrContext* resource_context) {
GrDirectContext* resource_context) {
sk_sp<SkSurface> surface;
SkImageInfo surface_info = SkImageInfo::MakeN32Premul(image->dimensions());
if (resource_context) {
Expand Down Expand Up @@ -86,7 +86,7 @@ void ConvertImageToRaster(sk_sp<SkImage> image,
std::function<void(sk_sp<SkImage>)> encode_task,
fml::RefPtr<fml::TaskRunner> raster_task_runner,
fml::RefPtr<fml::TaskRunner> io_task_runner,
GrContext* resource_context,
GrDirectContext* resource_context,
fml::WeakPtr<SnapshotDelegate> snapshot_delegate) {
// Check validity of the image.
if (image == nullptr) {
Expand Down Expand Up @@ -213,7 +213,7 @@ void EncodeImageAndInvokeDataCallback(
fml::RefPtr<fml::TaskRunner> ui_task_runner,
fml::RefPtr<fml::TaskRunner> raster_task_runner,
fml::RefPtr<fml::TaskRunner> io_task_runner,
GrContext* resource_context,
GrDirectContext* resource_context,
fml::WeakPtr<SnapshotDelegate> snapshot_delegate) {
auto callback_task = fml::MakeCopyable(
[callback = std::move(callback)](sk_sp<SkData> encoded) mutable {
Expand Down
2 changes: 1 addition & 1 deletion lib/ui/ui_dart_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include "flutter/lib/ui/painting/image_decoder.h"
#include "flutter/lib/ui/snapshot_delegate.h"
#include "third_party/dart/runtime/include/dart_api.h"
#include "third_party/skia/include/gpu/GrContext.h"
#include "third_party/skia/include/gpu/GrDirectContext.h"
#include "third_party/tonic/dart_microtask_queue.h"
#include "third_party/tonic/dart_persistent_value.h"
#include "third_party/tonic/dart_state.h"
Expand Down
2 changes: 1 addition & 1 deletion lib/ui/window/window.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include "flutter/lib/ui/window/platform_message.h"
#include "flutter/lib/ui/window/pointer_data_packet.h"
#include "flutter/lib/ui/window/viewport_metrics.h"
#include "third_party/skia/include/gpu/GrContext.h"
#include "third_party/skia/include/gpu/GrDirectContext.h"
#include "third_party/tonic/dart_persistent_value.h"

namespace tonic {
Expand Down
2 changes: 1 addition & 1 deletion shell/common/platform_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ void PlatformView::NotifyDestroyed() {
delegate_.OnPlatformViewDestroyed();
}

sk_sp<GrContext> PlatformView::CreateResourceContext() const {
sk_sp<GrDirectContext> PlatformView::CreateResourceContext() const {
FML_DLOG(WARNING) << "This platform does not setup the resource "
"context on the IO thread for async texture uploads.";
return nullptr;
Expand Down
4 changes: 2 additions & 2 deletions shell/common/platform_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include "flutter/shell/common/pointer_data_dispatcher.h"
#include "flutter/shell/common/vsync_waiter.h"
#include "third_party/skia/include/core/SkSize.h"
#include "third_party/skia/include/gpu/GrContext.h"
#include "third_party/skia/include/gpu/GrDirectContext.h"

namespace flutter {

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

//----------------------------------------------------------------------------
/// @brief Used by the shell to notify the embedder that the resource
Expand Down
Loading

0 comments on commit c57aff1

Please sign in to comment.