Flutter Impeller
lazy_drawable_holder.mm
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
6 
7 #include <QuartzCore/CAMetalLayer.h>
8 #include <future>
9 #include <memory>
10 
11 #include "flutter/fml/trace_event.h"
13 
14 namespace impeller {
15 
16 #pragma GCC diagnostic push
17 // Disable the diagnostic for iOS Simulators. Metal without emulation isn't
18 // available prior to iOS 13 and that's what the simulator headers say when
19 // support for CAMetalLayer begins. CAMetalLayer is available on iOS 8.0 and
20 // above which is well below Flutters support level.
21 #pragma GCC diagnostic ignored "-Wunguarded-availability-new"
22 
23 std::shared_future<id<CAMetalDrawable>> GetDrawableDeferred(
24  CAMetalLayer* layer) {
25  auto future =
26  std::async(std::launch::deferred, [layer]() -> id<CAMetalDrawable> {
27  id<CAMetalDrawable> current_drawable = nil;
28  {
29  TRACE_EVENT0("impeller", "WaitForNextDrawable");
30  current_drawable = [layer nextDrawable];
31  }
32  if (!current_drawable) {
33  VALIDATION_LOG << "Could not acquire current drawable.";
34  return nullptr;
35  }
36  return current_drawable;
37  });
38  return std::shared_future<id<CAMetalDrawable>>(std::move(future));
39 }
40 
41 std::shared_ptr<TextureMTL> CreateTextureFromDrawableFuture(
42  TextureDescriptor desc,
43  const std::shared_future<id<CAMetalDrawable>>& drawble_future) {
44  return std::make_shared<TextureMTL>(
45  desc, [drawble_future]() { return drawble_future.get().texture; },
46  /*wrapped=*/false, /*drawable=*/true);
47 }
48 
49 #pragma GCC diagnostic pop
50 
51 } // namespace impeller
impeller::CreateTextureFromDrawableFuture
std::shared_ptr< TextureMTL > CreateTextureFromDrawableFuture(TextureDescriptor desc, const std::shared_future< id< CAMetalDrawable >> &drawble_future)
Create a TextureMTL from a deferred drawable.
Definition: lazy_drawable_holder.mm:41
validation.h
impeller::GetDrawableDeferred
std::shared_future< id< CAMetalDrawable > > GetDrawableDeferred(CAMetalLayer *layer)
Create a deferred drawable from a CAMetalLayer.
Definition: lazy_drawable_holder.mm:23
lazy_drawable_holder.h
VALIDATION_LOG
#define VALIDATION_LOG
Definition: validation.h:73
impeller::TextureDescriptor
A lightweight object that describes the attributes of a texture that can then used an allocator to cr...
Definition: texture_descriptor.h:37
impeller
Definition: aiks_blur_unittests.cc:20