Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
image_encoding_impl.h
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
5#ifndef FLUTTER_LIB_UI_PAINTING_IMAGE_ENCODING_IMPL_H_
6#define FLUTTER_LIB_UI_PAINTING_IMAGE_ENCODING_IMPL_H_
7
8#include "flutter/lib/ui/ui_dart_state.h"
14
15namespace flutter {
16
17template <typename SyncSwitch>
19 const sk_sp<SkImage>& image,
20 const fml::WeakPtr<GrDirectContext>& resource_context,
21 const std::shared_ptr<const SyncSwitch>& is_gpu_disabled_sync_switch) {
24
25 is_gpu_disabled_sync_switch->Execute(
26 typename SyncSwitch::Handlers()
27 .SetIfTrue([&surface, &surface_info] {
28 surface = SkSurfaces::Raster(surface_info);
29 })
30 .SetIfFalse([&surface, &surface_info, resource_context] {
31 if (resource_context) {
33 resource_context.get(), skgpu::Budgeted::kNo, surface_info);
34 } else {
35 surface = SkSurfaces::Raster(surface_info);
36 }
37 }));
38
39 if (surface == nullptr || surface->getCanvas() == nullptr) {
40 FML_LOG(ERROR) << "Could not create a surface to copy the texture into.";
41 return nullptr;
42 }
43
44 surface->getCanvas()->drawImage(image, 0, 0);
45 if (resource_context) {
46 resource_context->flushAndSubmit();
47 }
48
49 auto snapshot = surface->makeImageSnapshot();
50
51 if (snapshot == nullptr) {
52 FML_LOG(ERROR) << "Could not snapshot image to encode.";
53 return nullptr;
54 }
55
56 return snapshot->makeRasterImage();
57}
58
59} // namespace flutter
60
61#endif // FLUTTER_LIB_UI_PAINTING_IMAGE_ENCODING_IMPL_H_
SkISize dimensions() const
Definition SkImage.h:297
T * get() const
Definition weak_ptr.h:87
VkSurfaceKHR surface
Definition main.cc:49
sk_sp< SkImage > image
Definition examples.cpp:29
#define FML_LOG(severity)
Definition logging.h:82
SK_API sk_sp< SkSurface > Raster(const SkImageInfo &imageInfo, size_t rowBytes, const SkSurfaceProps *surfaceProps)
SK_API sk_sp< SkSurface > RenderTarget(GrRecordingContext *context, skgpu::Budgeted budgeted, const SkImageInfo &imageInfo, int sampleCount, GrSurfaceOrigin surfaceOrigin, const SkSurfaceProps *surfaceProps, bool shouldCreateWithMips=false, bool isProtected=false)
sk_sp< SkImage > ConvertToRasterUsingResourceContext(const sk_sp< SkImage > &image, const fml::WeakPtr< GrDirectContext > &resource_context, const std::shared_ptr< const SyncSwitch > &is_gpu_disabled_sync_switch)
static SkImageInfo MakeN32Premul(int width, int height)
#define ERROR(message)