diff --git a/engine/src/flutter/impeller/host/BUILD.gn b/engine/src/flutter/impeller/host/BUILD.gn index 4161a8f818f..3864069888d 100644 --- a/engine/src/flutter/impeller/host/BUILD.gn +++ b/engine/src/flutter/impeller/host/BUILD.gn @@ -4,12 +4,17 @@ import("//flutter/common/config.gni") import("//flutter/impeller/tools/metal/metal_library.gni") +import("//flutter/testing/testing.gni") metal_library("impeller_host_shaders") { name = "impeller_host" sources = [ "shaders.metal" ] } +test_fixtures("impeller_host_fixtures") { + fixtures = [ "assets/ColorMap.png" ] +} + executable("host") { cflags_objc = flutter_cflags_objc_arc cflags_objcc = flutter_cflags_objcc_arc @@ -20,6 +25,8 @@ executable("host") { sources = [ "ShaderTypes.h", + "assets_location.cc", + "assets_location.h", "impeller_host_view_controller.h", "impeller_host_view_controller.mm", "impeller_renderer.h", @@ -38,6 +45,7 @@ executable("host") { ] deps = [ + ":impeller_host_fixtures", ":impeller_host_shaders", "//flutter/fml", "//flutter/impeller/impeller", diff --git a/engine/src/flutter/impeller/host/assets/ColorMap.png b/engine/src/flutter/impeller/host/assets/ColorMap.png new file mode 100644 index 00000000000..ddf9519d461 Binary files /dev/null and b/engine/src/flutter/impeller/host/assets/ColorMap.png differ diff --git a/engine/src/flutter/impeller/host/assets_location.cc b/engine/src/flutter/impeller/host/assets_location.cc new file mode 100644 index 00000000000..369e3cd3707 --- /dev/null +++ b/engine/src/flutter/impeller/host/assets_location.cc @@ -0,0 +1,31 @@ +// 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/impeller/host/assets_location.h" + +#include "flutter/fml/paths.h" + +namespace flutter::testing { + +//------------------------------------------------------------------------------ +/// @brief Returns the directory containing the test fixture for the target +/// if this target has fixtures configured. If there are no +/// fixtures, this is a link error. If you see a linker error on +/// this symbol, the unit-test target needs to depend on a +/// `test_fixtures` target. +/// +/// @return The fixtures path. +/// +const char* GetFixturesPath(); + +} // namespace flutter::testing + +namespace impeller { + +std::string GetAssetLocation(const char* asset_path) { + return fml::paths::JoinPaths( + {flutter::testing::GetFixturesPath(), std::string{asset_path}}); +} + +} // namespace impeller diff --git a/engine/src/flutter/impeller/host/assets_location.h b/engine/src/flutter/impeller/host/assets_location.h new file mode 100644 index 00000000000..ea139a5a6d6 --- /dev/null +++ b/engine/src/flutter/impeller/host/assets_location.h @@ -0,0 +1,11 @@ +// 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 + +namespace impeller { + +std::string GetAssetLocation(const char* asset_path); + +} // namespace impeller diff --git a/engine/src/flutter/impeller/host/impeller_renderer.mm b/engine/src/flutter/impeller/host/impeller_renderer.mm index 0111eaa8f04..f54f7ae82d2 100644 --- a/engine/src/flutter/impeller/host/impeller_renderer.mm +++ b/engine/src/flutter/impeller/host/impeller_renderer.mm @@ -5,6 +5,7 @@ #import #import +#import "assets_location.h" #include "flutter/fml/logging.h" #import "impeller_renderer.h" #import "shaders_location.h" @@ -178,9 +179,11 @@ static const size_t kAlignedUniformsSize = (sizeof(Uniforms) & ~0xFF) + 0x100; MTKTextureLoaderOptionTextureStorageMode : @(MTLStorageModePrivate) }; - _colorMap = [textureLoader newTextureWithName:@"ColorMap" - scaleFactor:1.0 - bundle:nil + auto color_map_data = [NSData + dataWithContentsOfFile:@(impeller::GetAssetLocation("ColorMap.png") + .c_str())]; + + _colorMap = [textureLoader newTextureWithData:color_map_data options:textureLoaderOptions error:&error];