Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions ci/licenses_golden/licenses_flutter
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,8 @@ FILE: ../../../flutter/shell/common/animator_unittests.cc
FILE: ../../../flutter/shell/common/canvas_spy.cc
FILE: ../../../flutter/shell/common/canvas_spy.h
FILE: ../../../flutter/shell/common/canvas_spy_unittests.cc
FILE: ../../../flutter/shell/common/context_options.cc
FILE: ../../../flutter/shell/common/context_options.h
FILE: ../../../flutter/shell/common/display.h
FILE: ../../../flutter/shell/common/display_manager.cc
FILE: ../../../flutter/shell/common/display_manager.h
Expand Down
2 changes: 2 additions & 0 deletions shell/common/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ source_set("common") {
"animator.h",
"canvas_spy.cc",
"canvas_spy.h",
"context_options.cc",
"context_options.h",
"display.h",
"display_manager.cc",
"display_manager.h",
Expand Down
39 changes: 39 additions & 0 deletions shell/common/context_options.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "flutter/shell/common/context_options.h"

#include "flutter/common/graphics/persistent_cache.h"

namespace flutter {

GrContextOptions MakeDefaultContextOptions(ContextType type,
std::optional<GrBackendApi> api) {
GrContextOptions options;

if (PersistentCache::cache_sksl()) {
options.fShaderCacheStrategy = GrContextOptions::ShaderCacheStrategy::kSkSL;
}
PersistentCache::MarkStrategySet();
options.fPersistentCache = PersistentCache::GetCacheForProcess();

if (api.has_value() && api.value() == GrBackendApi::kOpenGL) {
options.fAvoidStencilBuffers = true;

// To get video playback on the widest range of devices, we limit Skia to
// ES2 shading language when the ES3 external image extension is missing.
options.fPreferExternalImagesOverES3 = true;
}

// TODO(goderbauer): remove option when skbug.com/7523 is fixed.
options.fDisableGpuYUVConversion = true;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While moving this, I followed up on the linked bug. It has been marked as closed. I believe we can remove this option and resolve the TODO. I didn't do it here because I wanted to keep the contents of the patch on topic.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just came across this too and think we should remove it, but do we have a test case to show that it's safe now?


options.fReduceOpsTaskSplitting = GrContextOptions::Enable::kNo;

options.fReducedShaderVariations = true;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Guessing this might be the cause of the failure in EmbedderTest.CanRenderGradientWithCompositor and others?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I updated the test fixture. I could observe no noticeable differences in the results.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, I did verify that its just because of the shader variations. That is, it was not a side effect of me moving the context option setup into a common translation unit. The test pass if I disable reduced shaders variants.


return options;
};

} // namespace flutter
43 changes: 43 additions & 0 deletions shell/common/context_options.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef FLUTTER_SHELL_COMMON_CONTEXT_OPTIONS_H_
#define FLUTTER_SHELL_COMMON_CONTEXT_OPTIONS_H_

#include <optional>

#include "flutter/fml/macros.h"
#include "third_party/skia/include/gpu/GrContextOptions.h"

namespace flutter {

enum class ContextType {
/// The context is used to render to a texture or renderbuffer.
kRender,
/// The context will only be used to transfer resources to and from device
/// memory. No rendering will be performed using this context.
kResource,
};

//------------------------------------------------------------------------------
/// @brief Initializes GrContextOptions with values suitable for Flutter.
/// The options can be further tweaked before a GrContext is created
/// from these options.
///
/// @param[in] type The type of context that will be created using these
/// options.
/// @param[in] type The client rendering API that will be wrapped using a
/// context with these options. This argument is only required
/// if the context is going to be used with a particular
/// client rendering API.
///
/// @return The default graphics context options.
///
GrContextOptions MakeDefaultContextOptions(
ContextType type,
std::optional<GrBackendApi> api = std::nullopt);

} // namespace flutter

#endif // FLUTTER_SHELL_COMMON_CONTEXT_OPTIONS_H_
1 change: 0 additions & 1 deletion shell/common/platform_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include "flutter/shell/common/rasterizer.h"
#include "flutter/shell/common/shell.h"
#include "flutter/shell/common/vsync_waiter_fallback.h"
#include "third_party/skia/include/gpu/GrContextOptions.h"
#include "third_party/skia/include/gpu/gl/GrGLInterface.h"

namespace flutter {
Expand Down
26 changes: 2 additions & 24 deletions shell/common/shell_io_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "flutter/common/graphics/persistent_cache.h"
#include "flutter/fml/build_config.h"
#include "flutter/fml/message_loop.h"
#include "flutter/shell/common/context_options.h"
#include "third_party/skia/include/gpu/gl/GrGLInterface.h"

namespace flutter {
Expand All @@ -18,30 +19,7 @@ sk_sp<GrDirectContext> ShellIOManager::CreateCompatibleResourceLoadingContext(
return nullptr;
}

GrContextOptions options = {};

if (PersistentCache::cache_sksl()) {
FML_LOG(INFO) << "Cache SkSL";
options.fShaderCacheStrategy = GrContextOptions::ShaderCacheStrategy::kSkSL;
}
PersistentCache::MarkStrategySet();

options.fPersistentCache = PersistentCache::GetCacheForProcess();

// There is currently a bug with doing GPU YUV to RGB conversions on the IO
// thread. The necessary work isn't being flushed or synchronized with the
// other threads correctly, so the textures end up blank. For now, suppress
// that feature, which will cause texture uploads to do CPU YUV conversion.
// A similar work-around is also used in shell/gpu/gpu_surface_gl.cc.
options.fDisableGpuYUVConversion = true;

// To get video playback on the widest range of devices, we limit Skia to
// ES2 shading language when the ES3 external image extension is missing.
options.fPreferExternalImagesOverES3 = true;

// Enabling this flag can increase VRAM consumption. Turn it off until
// further notice.
options.fReduceOpsTaskSplitting = GrContextOptions::Enable::kNo;
const auto options = MakeDefaultContextOptions(ContextType::kResource);

#if !OS_FUCHSIA
if (auto context = GrDirectContext::MakeGL(gl_interface, options)) {
Expand Down
10 changes: 3 additions & 7 deletions shell/common/shell_test_platform_view_vulkan.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "flutter/shell/common/shell_test_platform_view_vulkan.h"

#include "flutter/common/graphics/persistent_cache.h"
#include "flutter/shell/common/context_options.h"
#include "flutter/vulkan/vulkan_utilities.h"

namespace flutter {
Expand Down Expand Up @@ -113,13 +114,8 @@ bool ShellTestPlatformViewVulkan::OffScreenSurface::CreateSkiaGrContext() {
return false;
}

GrContextOptions options;
if (PersistentCache::cache_sksl()) {
options.fShaderCacheStrategy = GrContextOptions::ShaderCacheStrategy::kSkSL;
}
PersistentCache::MarkStrategySet();
options.fPersistentCache = PersistentCache::GetCacheForProcess();
options.fReduceOpsTaskSplitting = GrContextOptions::Enable::kNo;
const auto options =
MakeDefaultContextOptions(ContextType::kRender, GrBackendApi::kVulkan);

sk_sp<GrDirectContext> context =
GrDirectContext::MakeVulkan(backend_context, options);
Expand Down
23 changes: 3 additions & 20 deletions shell/gpu/gpu_surface_gl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "flutter/fml/logging.h"
#include "flutter/fml/size.h"
#include "flutter/fml/trace_event.h"
#include "flutter/shell/common/context_options.h"
#include "third_party/skia/include/core/SkColorFilter.h"
#include "third_party/skia/include/core/SkSurface.h"
#include "third_party/skia/include/gpu/GrBackendSurface.h"
Expand Down Expand Up @@ -43,26 +44,8 @@ sk_sp<GrDirectContext> GPUSurfaceGL::MakeGLContext(
return nullptr;
}

GrContextOptions options;

if (PersistentCache::cache_sksl()) {
FML_LOG(INFO) << "Cache SkSL";
options.fShaderCacheStrategy = GrContextOptions::ShaderCacheStrategy::kSkSL;
}
PersistentCache::MarkStrategySet();
options.fPersistentCache = PersistentCache::GetCacheForProcess();

options.fAvoidStencilBuffers = true;

// To get video playback on the widest range of devices, we limit Skia to
// ES2 shading language when the ES3 external image extension is missing.
options.fPreferExternalImagesOverES3 = true;

// TODO(goderbauer): remove option when skbug.com/7523 is fixed.
// A similar work-around is also used in shell/common/io_manager.cc.
options.fDisableGpuYUVConversion = true;

options.fReduceOpsTaskSplitting = GrContextOptions::Enable::kNo;
const auto options =
MakeDefaultContextOptions(ContextType::kRender, GrBackendApi::kOpenGL);

auto context = GrDirectContext::MakeGL(delegate->GetGLInterface(), options);

Expand Down
1 change: 1 addition & 0 deletions shell/platform/darwin/graphics/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ source_set("graphics") {
deps = [
"//flutter/common/graphics",
"//flutter/fml",
"//flutter/shell/common",
"//flutter/shell/platform/darwin/common:framework_shared",
]

Expand Down
19 changes: 5 additions & 14 deletions shell/platform/darwin/graphics/FlutterDarwinContextMetal.mm
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,10 @@
#include "flutter/common/graphics/persistent_cache.h"
#include "flutter/fml/logging.h"
#import "flutter/shell/platform/darwin/common/framework/Headers/FlutterMacros.h"
#include "third_party/skia/include/gpu/GrContextOptions.h"
#include "shell/common/context_options.h"

FLUTTER_ASSERT_ARC

static GrContextOptions CreateMetalGrContextOptions() {
GrContextOptions options = {};
if (flutter::PersistentCache::cache_sksl()) {
options.fShaderCacheStrategy = GrContextOptions::ShaderCacheStrategy::kSkSL;
}
flutter::PersistentCache::MarkStrategySet();
options.fPersistentCache = flutter::PersistentCache::GetCacheForProcess();
options.fReduceOpsTaskSplitting = GrContextOptions::Enable::kNo;
return options;
}

@implementation FlutterDarwinContextMetal

- (instancetype)initWithDefaultMTLDevice {
Expand Down Expand Up @@ -77,15 +66,17 @@ - (instancetype)initWithMTLDevice:(id<MTLDevice>)device
}

- (sk_sp<GrDirectContext>)createGrContext {
auto contextOptions = CreateMetalGrContextOptions();
const auto contextOptions =
flutter::MakeDefaultContextOptions(flutter::ContextType::kRender, GrBackendApi::kMetal);
id<MTLDevice> device = _device;
id<MTLCommandQueue> commandQueue = _commandQueue;
return [FlutterDarwinContextMetal createGrContext:device commandQueue:commandQueue];
}

+ (sk_sp<GrDirectContext>)createGrContext:(id<MTLDevice>)device
commandQueue:(id<MTLCommandQueue>)commandQueue {
auto contextOptions = CreateMetalGrContextOptions();
const auto contextOptions =
flutter::MakeDefaultContextOptions(flutter::ContextType::kRender, GrBackendApi::kMetal);
// Skia expect arguments to `MakeMetal` transfer ownership of the reference in for release later
// when the GrDirectContext is collected.
return GrDirectContext::MakeMetal((__bridge_retained void*)device,
Expand Down
Binary file modified shell/platform/embedder/fixtures/gradient.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified shell/platform/embedder/fixtures/gradient_xform.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 4 additions & 2 deletions shell/platform/fuchsia/flutter/platform_view_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "flutter/flow/embedded_views.h"
#include "flutter/lib/ui/window/platform_message.h"
#include "flutter/lib/ui/window/viewport_metrics.h"
#include "flutter/shell/common/context_options.h"
#include "flutter/shell/platform/fuchsia/flutter/platform_view.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
Expand Down Expand Up @@ -347,8 +348,9 @@ TEST_F(PlatformViewTests, CreateSurfaceTest) {
);

// Test create surface callback function.
sk_sp<GrDirectContext> gr_context =
GrDirectContext::MakeMock(nullptr, GrContextOptions());
sk_sp<GrDirectContext> gr_context = GrDirectContext::MakeMock(
nullptr,
flutter::MakeDefaultContextOptions(flutter::ContextType::kRender));
std::shared_ptr<MockExternalViewEmbedder> view_embedder =
std::make_shared<MockExternalViewEmbedder>();
auto CreateSurfaceCallback = [&view_embedder, gr_context]() {
Expand Down
6 changes: 3 additions & 3 deletions shell/platform/fuchsia/flutter/vulkan_surface_producer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <vector>

#include "flutter/fml/trace_event.h"
#include "flutter/shell/common/context_options.h"
#include "third_party/skia/include/gpu/GrBackendSemaphore.h"
#include "third_party/skia/include/gpu/GrBackendSurface.h"
#include "third_party/skia/include/gpu/GrDirectContext.h"
Expand Down Expand Up @@ -137,9 +138,8 @@ bool VulkanSurfaceProducer::Initialize(scenic::Session* scenic_session) {
backend_context.fPhysicalDevice, 0, nullptr,
countof(device_extensions), device_extensions);
backend_context.fVkExtensions = &vk_extensions;
GrContextOptions options;
options.fReduceOpsTaskSplitting = GrContextOptions::Enable::kNo;

const auto options = flutter::MakeDefaultContextOptions(
flutter::ContextType::kRender, GrBackendApi::kVulkan);
context_ = GrDirectContext::MakeVulkan(backend_context, options);

if (context_ == nullptr) {
Expand Down