Skip to content

Commit

Permalink
Document GN rules and make targets that cannot be built on the platfo…
Browse files Browse the repository at this point in the history
…rm be no-ops. (flutter#70)
  • Loading branch information
chinmaygarde authored Mar 10, 2022
1 parent ae818a6 commit 6763e96
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 34 deletions.
4 changes: 3 additions & 1 deletion impeller/compiler/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ impeller_component("compiler_lib") {
]
}

executable("impellerc") {
impeller_component("impellerc") {
target_type = "executable"

sources = [ "impellerc_main.cc" ]

deps = [ ":compiler_lib" ]
Expand Down
12 changes: 1 addition & 11 deletions impeller/display_list/display_list_dispatcher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -539,17 +539,7 @@ void DisplayListDispatcher::drawDisplayList(
void DisplayListDispatcher::drawTextBlob(const sk_sp<SkTextBlob> blob,
SkScalar x,
SkScalar y) {
if (!blob) {
return;
}

auto bounds = blob->bounds();
bounds.fLeft += x;
bounds.fTop += y;

impeller::Paint paint;
paint.color = impeller::Color::Random().WithAlpha(0.2);
canvas_.DrawRect(ToRect(bounds), paint);
UNIMPLEMENTED;
}

// |flutter::Dispatcher|
Expand Down
7 changes: 6 additions & 1 deletion impeller/renderer/backend/metal/render_pass_mtl.mm
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,6 @@ static bool Bind(PassBindingsCache& pass,
fml::closure pop_debug_marker = [encoder]() { [encoder popDebugGroup]; };
for (const auto& command : commands_) {
if (command.index_count == 0u) {
VALIDATION_LOG << "Zero index count in render pass command.";
continue;
}

Expand Down Expand Up @@ -505,6 +504,12 @@ static bool Bind(PassBindingsCache& pass,
}
}

if (command.index_count == 0u) {
// Essentially a no-op. Don't record the command but this is not necessary
// an error either.
return true;
}

commands_.emplace_back(std::move(command));
return true;
}
Expand Down
2 changes: 0 additions & 2 deletions impeller/renderer/renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

#pragma once

#include <dispatch/dispatch.h>

#include <functional>
#include <memory>

Expand Down
103 changes: 84 additions & 19 deletions impeller/tools/impeller.gni
Original file line number Diff line number Diff line change
Expand Up @@ -8,38 +8,69 @@ import("//flutter/common/config.gni")
declare_args() {
# Whether playgrounds are enabled for unit tests.
impeller_enable_playground = false

# Whether Impeller is supported on the platform.
impeller_supports_platform = is_mac || is_ios
}

# ------------------------------------------------------------------------------
# @brief Define an Impeller component. Components are different
# Impeller subsystems part of the umbrella framework.
#
# @param[optional] target_type The type of the component. This can be any of
# the target types supported by GN. Defaults to
# source_set. If Impeller is not supported on the
# target platform, this target is a no-op.
#
template("impeller_component") {
source_set(target_name) {
forward_variables_from(invoker, "*")

if (!defined(invoker.public_configs)) {
public_configs = []
if (impeller_supports_platform) {
target_type = "source_set"
if (defined(invoker.target_type)) {
target_type = invoker.target_type
}
target(target_type, target_name) {
forward_variables_from(invoker, "*")

if (!defined(invoker.cflags_objc)) {
cflags_objc = []
}
if (!defined(invoker.public_configs)) {
public_configs = []
}

if (!defined(invoker.cflags_objcc)) {
cflags_objcc = []
}
public_configs += [ "//flutter/impeller:impeller_public_config" ]

if (!defined(invoker.deps)) {
deps = []
}
if (!defined(invoker.cflags_objc)) {
cflags_objc = []
}

objc_warning_flags = [ "-Wno-unused-private-field" ]
if (is_ios || is_mac) {
cflags_objc += flutter_cflags_objc_arc
}

cflags_objc += flutter_cflags_objc_arc + objc_warning_flags
cflags_objcc += flutter_cflags_objcc_arc + objc_warning_flags
if (!defined(invoker.cflags_objcc)) {
cflags_objcc = []
}

public_configs += [ "//flutter/impeller:impeller_public_config" ]
if (is_ios || is_mac) {
cflags_objcc += flutter_cflags_objcc_arc
}
}
} else {
group(target_name) {
not_needed(invoker, "*")
}
}
}

# ------------------------------------------------------------------------------
# @brief Build a Metal Library. The output is a single file. Use
# get_target_outputs to get its location on build.
#
# @param[required] name The name of the Metal library.
#
# @param[required] sources The GLSL (4.60) sources to compiled into the Metal
# library.
#
template("metal_library") {
assert(is_ios || is_mac)
assert(defined(invoker.name), "Metal library name must be specified.")
assert(defined(invoker.sources), "Metal source files must be specified.")

Expand Down Expand Up @@ -94,7 +125,17 @@ template("metal_library") {
}
}

template("impeller_shaders") {
# ------------------------------------------------------------------------------
# @brief Build and reflect shader information. Reflected shader
# information will be added to a generated source set along
# with the shader contents.
#
# @param[required] name The name of the shader library.
#
# @param[required] sources The GLSL (4.60) sources to compiled into the shader
# library.
#
template("impeller_shaders_real") {
assert(defined(invoker.shaders), "Impeller shaders must be specified.")
assert(defined(invoker.name), "Name of the shader library must be specified.")

Expand Down Expand Up @@ -229,3 +270,27 @@ template("impeller_shaders") {
]
}
}

# ------------------------------------------------------------------------------
# @brief Builds the shader library from shader sources, generates
# reflected shader information as source set, and, generates a
# translation unit added as a source set that allows embedding
# shaders into the final binary. On platforms where Impeller is
# not supported, this is a no-op.
#
# @note For additional information about parameters, see
# `impeller_shaders_real`
#
# @see impeller_shaders_real
#
template("impeller_shaders") {
if (impeller_supports_platform) {
impeller_shaders_real(target_name) {
forward_variables_from(invoker, "*")
}
} else {
group(target_name) {
not_needed(invoker, "*")
}
}
}

0 comments on commit 6763e96

Please sign in to comment.