Flutter Engine
The Flutter Engine
filter.h
Go to the documentation of this file.
1// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2// for details. All rights reserved. Use of this source code is governed by a
3// BSD-style license that can be found in the LICENSE file.
4
5#ifndef RUNTIME_BIN_FILTER_H_
6#define RUNTIME_BIN_FILTER_H_
7
8#include "bin/builtin.h"
9#include "bin/utils.h"
10
11#include "zlib/zlib.h"
12
13namespace dart {
14namespace bin {
15
16class Filter {
17 public:
18 virtual ~Filter() {}
19
20 virtual bool Init() = 0;
21
22 /**
23 * On a successful call to Process, Process will take ownership of data. On
24 * successive calls to either Processed or ~Filter, data will be freed with
25 * a delete[] call.
26 */
27 virtual bool Process(uint8_t* data, intptr_t length) = 0;
28 virtual intptr_t Processed(uint8_t* buffer,
29 intptr_t length,
30 bool finish,
31 bool end) = 0;
32
34 Filter* filter_pointer,
35 intptr_t filter_size);
37 Filter** filter_pointer);
38
39 bool initialized() const { return initialized_; }
40 void set_initialized(bool value) { initialized_ = value; }
41 uint8_t* processed_buffer() { return processed_buffer_; }
42 intptr_t processed_buffer_size() const { return kFilterBufferSize; }
43
44 protected:
45 Filter() : initialized_(false) {}
46
47 private:
48 static constexpr intptr_t kFilterBufferSize = 64 * KB;
49 uint8_t processed_buffer_[kFilterBufferSize];
50 bool initialized_;
51
52 DISALLOW_COPY_AND_ASSIGN(Filter);
53};
54
55class ZLibDeflateFilter : public Filter {
56 public:
58 int32_t level,
59 int32_t window_bits,
60 int32_t mem_level,
61 int32_t strategy,
62 uint8_t* dictionary,
63 intptr_t dictionary_length,
64 bool raw)
65 : gzip_(gzip),
66 level_(level),
67 window_bits_(window_bits),
68 mem_level_(mem_level),
69 strategy_(strategy),
70 dictionary_(dictionary),
71 dictionary_length_(dictionary_length),
72 raw_(raw),
73 current_buffer_(nullptr) {}
74 virtual ~ZLibDeflateFilter();
75
76 virtual bool Init();
77 virtual bool Process(uint8_t* data, intptr_t length);
78 virtual intptr_t Processed(uint8_t* buffer,
79 intptr_t length,
80 bool finish,
81 bool end);
82
83 private:
84 const bool gzip_;
85 const int32_t level_;
86 const int32_t window_bits_;
87 const int32_t mem_level_;
88 const int32_t strategy_;
89 uint8_t* dictionary_;
90 const intptr_t dictionary_length_;
91 const bool raw_;
92 uint8_t* current_buffer_;
93 z_stream stream_;
94
95 DISALLOW_COPY_AND_ASSIGN(ZLibDeflateFilter);
96};
97
98class ZLibInflateFilter : public Filter {
99 public:
100 ZLibInflateFilter(int32_t window_bits,
101 uint8_t* dictionary,
102 intptr_t dictionary_length,
103 bool raw)
104 : window_bits_(window_bits),
105 dictionary_(dictionary),
106 dictionary_length_(dictionary_length),
107 raw_(raw),
108 current_buffer_(nullptr) {}
109 virtual ~ZLibInflateFilter();
110
111 virtual bool Init();
112 virtual bool Process(uint8_t* data, intptr_t length);
113 virtual intptr_t Processed(uint8_t* buffer,
114 intptr_t length,
115 bool finish,
116 bool end);
117
118 private:
119 const int32_t window_bits_;
120 uint8_t* dictionary_;
121 const intptr_t dictionary_length_;
122 const bool raw_;
123 uint8_t* current_buffer_;
124 z_stream stream_;
125
126 DISALLOW_COPY_AND_ASSIGN(ZLibInflateFilter);
127};
128
129} // namespace bin
130} // namespace dart
131
132#endif // RUNTIME_BIN_FILTER_H_
virtual intptr_t Processed(uint8_t *buffer, intptr_t length, bool finish, bool end)=0
static Dart_Handle SetFilterAndCreateFinalizer(Dart_Handle filter, Filter *filter_pointer, intptr_t filter_size)
Definition: filter.cc:264
virtual bool Process(uint8_t *data, intptr_t length)=0
intptr_t processed_buffer_size() const
Definition: filter.h:42
virtual ~Filter()
Definition: filter.h:18
bool initialized() const
Definition: filter.h:39
uint8_t * processed_buffer()
Definition: filter.h:41
static Dart_Handle GetFilterNativeField(Dart_Handle filter, Filter **filter_pointer)
Definition: filter.cc:278
virtual bool Init()=0
void set_initialized(bool value)
Definition: filter.h:40
virtual bool Process(uint8_t *data, intptr_t length)
Definition: filter.cc:331
virtual intptr_t Processed(uint8_t *buffer, intptr_t length, bool finish, bool end)
Definition: filter.cc:340
ZLibDeflateFilter(bool gzip, int32_t level, int32_t window_bits, int32_t mem_level, int32_t strategy, uint8_t *dictionary, intptr_t dictionary_length, bool raw)
Definition: filter.h:57
virtual intptr_t Processed(uint8_t *buffer, intptr_t length, bool finish, bool end)
Definition: filter.cc:405
virtual bool Process(uint8_t *data, intptr_t length)
Definition: filter.cc:396
ZLibInflateFilter(int32_t window_bits, uint8_t *dictionary, intptr_t dictionary_length, bool raw)
Definition: filter.h:100
struct _Dart_Handle * Dart_Handle
Definition: dart_api.h:258
uint8_t value
size_t length
Definition: dart_vm.cc:33
constexpr intptr_t KB
Definition: globals.h:528
static int8_t data[kExtLength]
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace buffer
Definition: switches.h:126