Skip to content

Commit

Permalink
Add minimal viewer build with Bazel.
Browse files Browse the repository at this point in the history
This doesn't yet support all the slide types, but does allow us
to have a GM slide (with one gm for now).

I enforced IWYU on tools/viewer/ and gm/ to help resolve all
deps. How we handle command line flags is a bit unfortunate
(as a filegroup and not a cc_library), but I think that's
pretty tough to untangle for now.

We can add more slide types and gms as we see fit in future
CLs.

Change-Id: I41876f1b115f60e72b4b297a2106441b49cd4497
Bug: skia:13983
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/676118
Reviewed-by: Ben Wagner <[email protected]>
Commit-Queue: Kevin Lubick <[email protected]>
  • Loading branch information
kjlubick authored and SkCQ committed Apr 24, 2023
1 parent ec3f86d commit 4c49170
Show file tree
Hide file tree
Showing 54 changed files with 526 additions and 70 deletions.
1 change: 1 addition & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ skia_cc_library(
local_defines = DEFAULT_LOCAL_DEFINES,
visibility = [
"//dm:__subpackages__",
"//gm:__subpackages__",
"//modules:__subpackages__",
"//tests:__subpackages__",
"//tools:__subpackages__",
Expand Down
1 change: 1 addition & 0 deletions WORKSPACE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@ load("//bazel:deps.bzl", "git_repos_from_deps")
# @freetype - //bazel/external/freetype:BUILD.bazel
# @harfbuzz - //bazel/external/harfbuzz:BUILD.bazel
# @icu - //bazel/external/icu:BUILD.bazel
# @imgui - //bazel/external/imgui:BUILD.bazel
# @libavif - //bazel/external/libavif:BUILD.bazel
# @libgav1 - //bazel/external/libgav1:BUILD.bazel
# @libjpeg_turbo - //bazel/external/libjpeg_turbo:BUILD.bazel
Expand Down
7 changes: 7 additions & 0 deletions bazel/deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,13 @@ def git_repos_from_deps(ws = "@"):
remote = "https://chromium.googlesource.com/chromium/deps/icu.git",
)

new_git_repository(
name = "imgui",
build_file = ws + "//bazel/external/imgui:BUILD.bazel",
commit = "55d35d8387c15bf0cfd71861df67af8cfbda7456",
remote = "https://skia.googlesource.com/external/github.com/ocornut/imgui.git",
)

new_git_repository(
name = "libavif",
build_file = ws + "//bazel/external/libavif:BUILD.bazel",
Expand Down
1 change: 1 addition & 0 deletions bazel/deps_parser/deps_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ var deps = map[string]depConfig{
"freetype": {needsBazelFile: true},
"harfbuzz": {needsBazelFile: true},
"icu": {needsBazelFile: true},
"imgui": {needsBazelFile: true},
"libavif": {needsBazelFile: true},
"libgav1": {needsBazelFile: true},
"libjpeg-turbo": {bazelNameOverride: "libjpeg_turbo", needsBazelFile: true},
Expand Down
24 changes: 24 additions & 0 deletions bazel/external/imgui/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# This file will be copied into //third_party/externals/imgui via the new_git_repository
# rule in //bazel/deps.bzl, so all files should be relative to that path.

cc_library(
name = "imgui",
srcs = [
"imconfig.h",
"imgui.cpp",
"imgui.h",
"imgui_demo.cpp",
"imgui_draw.cpp",
"imgui_internal.h",
"imgui_tables.cpp",
"imgui_widgets.cpp",
"imstb_rectpack.h",
"imstb_textedit.h",
"imstb_truetype.h",
"misc/cpp/imgui_stdlib.cpp",
"misc/cpp/imgui_stdlib.h",
],
hdrs = ["imgui.h"],
defines = ["IMGUI_ENABLE_OSX_DEFAULT_CLIPBOARD_FUNCTIONS"],
visibility = ["//visibility:public"],
)
28 changes: 28 additions & 0 deletions gm/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
load("//bazel:skia_rules.bzl", "exports_files_legacy", "skia_cc_library")

licenses(["notice"])

exports_files_legacy()

filegroup(
name = "gm_subset",
srcs = ["bitmaprect.cpp"],
visibility = ["//tools/viewer:__pkg__"],
)

skia_cc_library(
name = "gm",
testonly = True,
srcs = [
"gm.cpp",
"verifiers/gmverifier.cpp",
"verifiers/gmverifier.h",
],
hdrs = ["gm.h"],
visibility = ["//tools/viewer:__pkg__"],
deps = [
"//:skia_internal",
"//tools:registry",
"//tools:tool_utils",
],
)
7 changes: 6 additions & 1 deletion gm/bitmaprect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@
#include "include/core/SkBlendMode.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkColor.h"
#include "include/core/SkImage.h"
#include "include/core/SkPaint.h"
#include "include/core/SkPoint.h"
#include "include/core/SkRect.h"
#include "include/core/SkShader.h"
#include "include/core/SkRefCnt.h"
#include "include/core/SkSamplingOptions.h"
#include "include/core/SkSize.h"
#include "include/core/SkString.h"
#include "include/core/SkSurface.h"
Expand All @@ -22,6 +24,9 @@
#include "include/effects/SkGradientShader.h"
#include "tools/ToolUtils.h"

#include <cstddef>
#include <iterator>

static sk_sp<SkImage> make_image(SkCanvas* destCanvas) {
auto surf = SkSurface::MakeRasterN32Premul(64, 64);
auto tmpCanvas = surf->getCanvas();
Expand Down
2 changes: 2 additions & 0 deletions gm/fillrect_gradient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
#include "include/core/SkTileMode.h"
#include "include/effects/SkGradientShader.h"

#include <vector>

const int kCellSize = 50;
const int kNumColumns = 2;
const int kNumRows = 9;
Expand Down
16 changes: 11 additions & 5 deletions gm/gm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
*/

#include "gm/gm.h"
#include "gm/verifiers/gmverifier.h"

#include "gm/verifiers/gmverifier.h" // IWYU pragma: keep
#include "include/core/SkBitmap.h"
#include "include/core/SkBlendMode.h"
#include "include/core/SkCanvas.h"
Expand All @@ -15,15 +16,16 @@
#include "include/core/SkMatrix.h"
#include "include/core/SkPaint.h"
#include "include/core/SkRect.h"
#include "include/core/SkShader.h"
#include "include/core/SkSamplingOptions.h"
#include "include/core/SkShader.h" // IWYU pragma: keep
#include "include/core/SkTileMode.h"
#include "include/core/SkTypeface.h"
#include "include/gpu/GrRecordingContext.h"
#include "src/core/SkCanvasPriv.h"
#include "src/core/SkTraceEvent.h"
#include "tools/ToolUtils.h"

#include <stdarg.h>
#include <atomic>
#include <cstdarg>
#include <cstdint>

using namespace skiagm;

Expand Down Expand Up @@ -186,6 +188,10 @@ void GM::drawSizeBounds(SkCanvas* canvas, SkColor color) {
// need to explicitly declare this, or we get some weird infinite loop llist
template GMRegistry* GMRegistry::gHead;

std::unique_ptr<verifiers::VerifierList> GpuGM::getVerifiers() const {
return nullptr;
}

DrawResult GpuGM::onDraw(GrRecordingContext* rContext, SkCanvas* canvas, SkString* errorMsg) {
this->onDraw(rContext, canvas);
return DrawResult::kOk;
Expand Down
6 changes: 3 additions & 3 deletions gm/gm.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#ifndef skiagm_DEFINED
#define skiagm_DEFINED

#include "gm/verifiers/gmverifier.h"
#include "include/core/SkColor.h"
#include "include/core/SkScalar.h"
#include "include/core/SkSize.h"
Expand All @@ -19,12 +18,13 @@

#include <memory>

class GrDirectContext;
class GrRecordingContext;
class SkCanvas;
class SkMetaData;
struct GrContextOptions;

namespace skiagm { namespace verifiers { class VerifierList; } }

#define DEF_GM(CODE) \
static skiagm::GMRegistry SK_MACRO_APPEND_COUNTER(REG_)( \
[]() { return std::unique_ptr<skiagm::GM>([]() { CODE; }()); });
Expand Down Expand Up @@ -200,7 +200,7 @@ namespace skiagm {
// TODO(tdenniston): Currently GpuGMs don't have verifiers (because they do not render on
// CPU), but we may want to be able to verify the output images standalone, without
// requiring a gold image for comparison.
std::unique_ptr<verifiers::VerifierList> getVerifiers() const override { return nullptr; }
std::unique_ptr<verifiers::VerifierList> getVerifiers() const override;

private:
using GM::onDraw;
Expand Down
2 changes: 2 additions & 0 deletions gm/hardstop_gradients_many.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
#include "include/core/SkTileMode.h"
#include "include/effects/SkGradientShader.h"

#include <vector>

const int kWidth = 1000;
const int kHeight = 2000;
const int kNumRows = 100;
Expand Down
15 changes: 10 additions & 5 deletions gm/verifiers/gmverifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,20 @@
* found in the LICENSE file.
*/

#include "gm/gm.h"
#include "gm/verifiers/gmverifier.h"

#include "gm/gm.h"
#include "include/core/SkAlphaType.h"
#include "include/core/SkBitmap.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkColorSpace.h"
#include "include/core/SkSurface.h"
#include "include/effects/SkImageFilters.h"
#include "include/encode/SkPngEncoder.h"
#include "src/utils/SkOSPath.h"
#include "include/core/SkColorType.h"
#include "include/core/SkImage.h" // IWYU pragma: keep
#include "include/core/SkImageInfo.h"
#include "include/core/SkSize.h"
#include "include/private/base/SkAssert.h"

#include <utility>

/** Checks the given VerifierResult. If it is not ok, returns it. */
#define RETURN_NOT_OK(res) if (!(res).ok()) return (res)
Expand Down
4 changes: 2 additions & 2 deletions gm/verifiers/gmverifier.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
#ifndef gmverifier_DEFINED
#define gmverifier_DEFINED

#include "include/core/SkColor.h"
#include "include/core/SkRect.h"
#include "include/core/SkString.h"

#include <memory>
#include <vector>

class SkBitmap;
class SkColorInfo;
struct SkIRect;

namespace skiagm {

Expand Down
1 change: 1 addition & 0 deletions src/utils/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ skia_filegroup(
selects.config_setting_group(
name = "needs_json",
match_any = [
"//src/gpu:enable_gpu_test_utils_true",
"//src/sksl:enable_sksl_tracing_true",
],
)
Expand Down
1 change: 1 addition & 0 deletions toolchain/linux_trampolines/IWYU_mapping.imp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
{ include: ["<__algorithm/fill.h>", "private", "<algorithm>", "public"] },
{ include: ["<__algorithm/fill_n.h>", "private", "<algorithm>", "public"] },
{ include: ["<__algorithm/find.h>", "private", "<algorithm>", "public"] },
{ include: ["<__algorithm/find_if.h>", "private", "<algorithm>", "public"] },
{ include: ["<__algorithm/is_sorted.h>", "private", "<algorithm>", "public"] },
{ include: ["<__algorithm/lower_bound.h>", "private", "<algorithm>", "public"] },
{ include: ["<__algorithm/max.h>", "private", "<algorithm>", "public"] },
Expand Down
2 changes: 2 additions & 0 deletions toolchain/linux_trampolines/clang_trampoline_linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ if [[ "$@" != *DSKIA_ENFORCE_IWYU* || "$@" == *use-ld* ]]; then
fi

supported_files_or_dirs=(
"gm/"
"include/private/base/"
"modules/skunicode/"
"src/base/"
Expand All @@ -32,6 +33,7 @@ supported_files_or_dirs=(
"src/utils/"
"tests/"
"tools/debugger/"
"tools/viewer/"
"src/core/SkBitmap.cpp"
"src/core/SkBitmapCache.cpp"
"src/core/SkCachedData.cpp"
Expand Down
27 changes: 23 additions & 4 deletions tools/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@ skia_cc_library(
"Resources.cpp",
"ToolUtils.cpp",
"ResourceFactory.h",
"Resources.h",
"//tools/flags",
# TODO(kjlubick, bungeman): We should split out the font stuff into its own set of files
"//tools/fonts:test_font_manager_srcs",
"SkMetaData.h",
"SkMetaData.cpp",
],
hdrs = [
"DecodeFile.h",
"Resources.h",
"SkMetaData.h",
"ToolUtils.h",
],
textual_hdrs = [
Expand All @@ -34,7 +35,11 @@ skia_cc_library(
skia_cc_library(
name = "registry",
hdrs = ["Registry.h"],
visibility = ["//tests:__subpackages__"],
visibility = [
"//gm:__pkg__",
"//tests:__subpackages__",
"//tools/viewer:__pkg__",
],
deps = ["//:skia_internal"],
)

Expand Down Expand Up @@ -73,11 +78,25 @@ skia_cc_library(
deps = ["//:skia_internal"],
)

skia_cc_library(
name = "mskp_player",
srcs = ["MSKPPlayer.cpp"],
hdrs = ["MSKPPlayer.h"],
visibility = ["//tools/viewer:__pkg__"],
deps = [
":sk_sharing_proc",
"//:skia_internal",
],
)

skia_cc_library(
name = "runtime_blend_utils",
srcs = ["RuntimeBlendUtils.cpp"],
hdrs = ["RuntimeBlendUtils.h"],
visibility = ["//tests:__pkg__"],
visibility = [
"//tests:__pkg__",
"//tools/viewer:__pkg__",
],
deps = ["//:skia_internal"],
)

Expand Down
13 changes: 13 additions & 0 deletions tools/flags/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,16 @@ skia_filegroup(
"//tools:__subpackages__",
],
)

skia_filegroup(
name = "common_flags",
testonly = True,
srcs = [
"CommonFlags.h",
"CommonFlagsFontMgr.cpp",
"CommonFlagsGpu.cpp",
],
visibility = [
"//tools:__subpackages__",
],
)
1 change: 1 addition & 0 deletions tools/gpu/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ skia_cc_library(
visibility = [
"//modules/skottie:__pkg__",
"//tests:__pkg__",
"//tools/viewer:__pkg__",
],
deps = ["//:skia_internal"] + select_multi({
"//src/gpu:gl_backend": ["//tools/gpu/gl:deps"],
Expand Down
1 change: 1 addition & 0 deletions tools/gpu/GrTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "include/gpu/GrRecordingContext.h"
#include "include/private/base/SkTo.h"
#include "src/base/SkMathPriv.h"
#include "src/base/SkRandom.h"
#include "src/gpu/ganesh/GrClip.h"
#include "src/gpu/ganesh/GrDirectContextPriv.h"
#include "src/gpu/ganesh/GrDrawOpAtlas.h"
Expand Down
2 changes: 1 addition & 1 deletion tools/gpu/gl/GLTestContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ void GLTestContext::teardown() {

void GLTestContext::testAbandon() {
INHERITED::testAbandon();
#ifdef SK_GL
#if defined(SK_GL) && GR_TEST_UTILS
if (fGLInterface) {
fGLInterface->abandon();
fOriginalGLInterface->abandon();
Expand Down
2 changes: 2 additions & 0 deletions tools/sk_app/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ skia_cc_library(
"Window.cpp",
"WindowContext.cpp",
"RasterWindowContext.h",
"CommandSet.cpp",
] + select_multi(
{
"//src/gpu:dawn_backend": [
Expand All @@ -34,6 +35,7 @@ skia_cc_library(
}),
hdrs = [
"Application.h",
"CommandSet.h",
"DisplayParams.h",
"Window.h",
"WindowContext.h",
Expand Down
Loading

0 comments on commit 4c49170

Please sign in to comment.