Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
image_decoder_no_gl_unittests.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_DECODER_NO_GL_UNITTESTS_H_
6#define FLUTTER_LIB_UI_PAINTING_IMAGE_DECODER_NO_GL_UNITTESTS_H_
7
8#include <stdint.h>
9
10#include "flutter/impeller/core/allocator.h"
11#include "flutter/impeller/core/device_buffer.h"
12#include "flutter/impeller/core/formats.h"
13#include "flutter/impeller/geometry/size.h"
14#include "flutter/lib/ui/painting/image_decoder.h"
15#include "flutter/lib/ui/painting/image_decoder_impeller.h"
16#include "flutter/testing/testing.h"
17
18namespace impeller {
19
21 public:
23
24 void SetLabel(std::string_view label) override {}
25 bool IsValid() const override { return true; }
26 ISize GetSize() const { return GetTextureDescriptor().size; }
27
28 bool OnSetContents(const uint8_t* contents, size_t length, size_t slice) {
29 return true;
30 }
31 bool OnSetContents(std::shared_ptr<const fml::Mapping> mapping,
32 size_t slice) {
33 return true;
34 }
35};
36
38 public:
40 : DeviceBuffer(desc) {
41 bytes_ = static_cast<uint8_t*>(malloc(desc.size));
42 }
43
44 ~TestImpellerDeviceBuffer() { free(bytes_); }
45
46 private:
47 std::shared_ptr<Texture> AsTexture(Allocator& allocator,
48 const TextureDescriptor& descriptor,
49 uint16_t row_bytes) const override {
50 return nullptr;
51 }
52
53 bool SetLabel(const std::string& label) override { return true; }
54
55 bool SetLabel(const std::string& label, Range range) override { return true; }
56
57 uint8_t* OnGetContents() const override { return bytes_; }
58
59 bool OnCopyHostBuffer(const uint8_t* source,
60 Range source_range,
61 size_t offset) override {
62 for (auto i = source_range.offset; i < source_range.length; i++, offset++) {
63 bytes_[offset] = source[i];
64 }
65 return true;
66 }
67
68 uint8_t* bytes_;
69};
70
72 public:
74
76
77 private:
78 uint16_t MinimumBytesPerRow(PixelFormat format) const override { return 0; }
79
81 return ISize{2048, 2048};
82 }
83
84 std::shared_ptr<DeviceBuffer> OnCreateBuffer(
85 const DeviceBufferDescriptor& desc) override {
86 return std::make_shared<TestImpellerDeviceBuffer>(desc);
87 }
88
89 std::shared_ptr<Texture> OnCreateTexture(
90 const TextureDescriptor& desc) override {
91 return std::make_shared<TestImpellerTexture>(desc);
92 }
93};
94
95} // namespace impeller
96
97namespace flutter {
98namespace testing {
99
100float HalfToFloat(uint16_t half);
101float DecodeBGR10(uint32_t x);
102
103} // namespace testing
104} // namespace flutter
105
106#endif // FLUTTER_LIB_UI_PAINTING_IMAGE_DECODER_NO_GL_UNITTESTS_H_
An object that allocates device memory.
Definition allocator.h:22
std::shared_ptr< Texture > OnCreateTexture(const TextureDescriptor &desc) override
uint16_t MinimumBytesPerRow(PixelFormat format) const override
Minimum value for row_bytes on a Texture. The row bytes parameter of that method must be aligned to t...
std::shared_ptr< DeviceBuffer > OnCreateBuffer(const DeviceBufferDescriptor &desc) override
TestImpellerDeviceBuffer(DeviceBufferDescriptor desc)
std::shared_ptr< Texture > AsTexture(Allocator &allocator, const TextureDescriptor &descriptor, uint16_t row_bytes) const override
bool SetLabel(const std::string &label, Range range) override
bool SetLabel(const std::string &label) override
bool OnCopyHostBuffer(const uint8_t *source, Range source_range, size_t offset) override
bool OnSetContents(const uint8_t *contents, size_t length, size_t slice)
bool OnSetContents(std::shared_ptr< const fml::Mapping > mapping, size_t slice)
void SetLabel(std::string_view label) override
const TextureDescriptor & GetTextureDescriptor() const
Definition texture.cc:57
SkBitmap source
Definition examples.cpp:28
uint32_t uint32_t * format
size_t length
double x
float HalfToFloat(uint16_t half)
PixelFormat
The Pixel formats supported by Impeller. The naming convention denotes the usage of the component,...
Definition formats.h:100
Point offset
size_t length
Definition range.h:16
size_t offset
Definition range.h:15
A lightweight object that describes the attributes of a texture that can then used an allocator to cr...