Skip to content

Commit

Permalink
Use futures to images used for comparison with fixtures in embedder u…
Browse files Browse the repository at this point in the history
…nit-tests. (flutter#14465)

This earlier pattern was to use callbacks with latching.
  • Loading branch information
chinmaygarde committed Dec 12, 2019
1 parent 18c89f1 commit 181ad4e
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 141 deletions.
11 changes: 11 additions & 0 deletions shell/platform/embedder/tests/embedder_test_context.cc
Expand Up @@ -4,6 +4,7 @@

#include "flutter/shell/platform/embedder/tests/embedder_test_context.h"

#include "flutter/fml/make_copyable.h"
#include "flutter/runtime/dart_vm.h"
#include "flutter/shell/platform/embedder/tests/embedder_assertions.h"
#include "third_party/dart/runtime/bin/elf_loader.h"
Expand Down Expand Up @@ -225,6 +226,16 @@ void EmbedderTestContext::SetNextSceneCallback(
next_scene_callback_ = next_scene_callback;
}

std::future<sk_sp<SkImage>> EmbedderTestContext::GetNextSceneImage() {
std::promise<sk_sp<SkImage>> promise;
auto future = promise.get_future();
SetNextSceneCallback(
fml::MakeCopyable([promise = std::move(promise)](auto image) mutable {
promise.set_value(image);
}));
return future;
}

bool EmbedderTestContext::SofwarePresent(sk_sp<SkImage> image) {
software_surface_present_count_++;

Expand Down
8 changes: 6 additions & 2 deletions shell/platform/embedder/tests/embedder_test_context.h
Expand Up @@ -5,6 +5,7 @@
#ifndef FLUTTER_SHELL_PLATFORM_EMBEDDER_TESTS_EMBEDDER_CONTEXT_H_
#define FLUTTER_SHELL_PLATFORM_EMBEDDER_TESTS_EMBEDDER_CONTEXT_H_

#include <future>
#include <map>
#include <memory>
#include <string>
Expand Down Expand Up @@ -60,8 +61,7 @@ class EmbedderTestContext {

EmbedderTestCompositor& GetCompositor();

using NextSceneCallback = std::function<void(sk_sp<SkImage> image)>;
void SetNextSceneCallback(const NextSceneCallback& next_scene_callback);
std::future<sk_sp<SkImage>> GetNextSceneImage();

size_t GetGLSurfacePresentCount() const;

Expand All @@ -71,6 +71,8 @@ class EmbedderTestContext {
// This allows the builder to access the hooks.
friend class EmbedderConfigBuilder;

using NextSceneCallback = std::function<void(sk_sp<SkImage> image)>;

std::string assets_path_;

// Pieces of the Dart snapshot in ELF form, loaded by Dart's ELF library.
Expand Down Expand Up @@ -129,6 +131,8 @@ class EmbedderTestContext {
void FireRootSurfacePresentCallbackIfPresent(
const std::function<sk_sp<SkImage>(void)>& image_callback);

void SetNextSceneCallback(const NextSceneCallback& next_scene_callback);

FML_DISALLOW_COPY_AND_ASSIGN(EmbedderTestContext);
};

Expand Down

0 comments on commit 181ad4e

Please sign in to comment.