Flutter Engine
The Flutter Engine
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:
41 bytes_ = static_cast<uint8_t*>(malloc(desc.size));
42 }
43
44 ~TestImpellerDeviceBuffer() { free(bytes_); }
45
46 private:
47 bool SetLabel(const std::string& label) override { return true; }
48
49 bool SetLabel(const std::string& label, Range range) override { return true; }
50
51 uint8_t* OnGetContents() const override { return bytes_; }
52
53 bool OnCopyHostBuffer(const uint8_t* source,
54 Range source_range,
55 size_t offset) override {
56 for (auto i = source_range.offset; i < source_range.length; i++, offset++) {
57 bytes_[offset] = source[i];
58 }
59 return true;
60 }
61
62 uint8_t* bytes_;
63};
64
66 public:
68
70
71 private:
72 uint16_t MinimumBytesPerRow(PixelFormat format) const override { return 0; }
73
74 ISize GetMaxTextureSizeSupported() const override {
75 return ISize{2048, 2048};
76 }
77
78 std::shared_ptr<DeviceBuffer> OnCreateBuffer(
79 const DeviceBufferDescriptor& desc) override {
80 return std::make_shared<TestImpellerDeviceBuffer>(desc);
81 }
82
83 std::shared_ptr<Texture> OnCreateTexture(
84 const TextureDescriptor& desc) override {
85 return std::make_shared<TestImpellerTexture>(desc);
86 }
87};
88
89} // namespace impeller
90
91namespace flutter {
92namespace testing {
93
94float HalfToFloat(uint16_t half);
95float DecodeBGR10(uint32_t x);
96
97} // namespace testing
98} // namespace flutter
99
100#endif // FLUTTER_LIB_UI_PAINTING_IMAGE_DECODER_NO_GL_UNITTESTS_H_
An object that allocates device memory.
Definition: allocator.h:22
TestImpellerDeviceBuffer(DeviceBufferDescriptor desc)
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
void * malloc(size_t size)
Definition: allocation.cc:19
float HalfToFloat(uint16_t half)
PixelFormat
The Pixel formats supported by Impeller. The naming convention denotes the usage of the component,...
Definition: formats.h:99
SeparatedVector2 offset
A lightweight object that describes the attributes of a texture that can then used an allocator to cr...