Switch from char to uint8_t to represent memory (flutter/engine#3147)
Previously we had a mix of the two.
This commit is contained in:
@@ -16,7 +16,7 @@ namespace glue {
|
||||
|
||||
class DrainDataPipeJob {
|
||||
public:
|
||||
using ResultCallback = std::function<void(std::vector<char>)>;
|
||||
using ResultCallback = std::function<void(std::vector<uint8_t>)>;
|
||||
|
||||
DrainDataPipeJob(mojo::ScopedDataPipeConsumerHandle handle,
|
||||
const ResultCallback& callback);
|
||||
|
||||
@@ -21,13 +21,13 @@ class DrainDataPipeJob::JobImpl : public DataPipeDrainer::Client {
|
||||
private:
|
||||
// mojo::common::DataPipeDrainer::Client
|
||||
void OnDataAvailable(const void* data, size_t num_bytes) override {
|
||||
const char* bytes = static_cast<const char*>(data);
|
||||
const uint8_t* bytes = static_cast<const uint8_t*>(data);
|
||||
buffer_.insert(buffer_.end(), bytes, bytes + num_bytes);
|
||||
}
|
||||
|
||||
void OnDataComplete() override { callback_(std::move(buffer_)); }
|
||||
|
||||
std::vector<char> buffer_;
|
||||
std::vector<uint8_t> buffer_;
|
||||
ResultCallback callback_;
|
||||
DataPipeDrainer drainer_;
|
||||
|
||||
|
||||
@@ -23,13 +23,13 @@ class DrainDataPipeJob::JobImpl : public DataPipeDrainer::Client {
|
||||
private:
|
||||
// mojo::common::DataPipeDrainer::Client
|
||||
void OnDataAvailable(const void* data, size_t num_bytes) override {
|
||||
const char* bytes = static_cast<const char*>(data);
|
||||
const uint8_t* bytes = static_cast<const uint8_t*>(data);
|
||||
buffer_.insert(buffer_.end(), bytes, bytes + num_bytes);
|
||||
}
|
||||
|
||||
void OnDataComplete() override { callback_(std::move(buffer_)); }
|
||||
|
||||
std::vector<char> buffer_;
|
||||
std::vector<uint8_t> buffer_;
|
||||
ResultCallback callback_;
|
||||
DataPipeDrainer drainer_;
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ using tonic::ToDart;
|
||||
namespace blink {
|
||||
namespace {
|
||||
|
||||
sk_sp<SkImage> DecodeImage(std::vector<char> buffer) {
|
||||
sk_sp<SkImage> DecodeImage(std::vector<uint8_t> buffer) {
|
||||
TRACE_EVENT0("blink", "DecodeImage");
|
||||
|
||||
if (buffer.empty())
|
||||
@@ -70,7 +70,7 @@ void InvokeImageCallback(sk_sp<SkImage> image,
|
||||
|
||||
void DecodeImageAndInvokeImageCallback(
|
||||
glue::MovableWrapper<std::unique_ptr<DartPersistentValue>> callback,
|
||||
std::vector<char> buffer) {
|
||||
std::vector<uint8_t> buffer) {
|
||||
sk_sp<SkImage> image = DecodeImage(std::move(buffer));
|
||||
Threads::UI()->PostTask([callback, image]() mutable {
|
||||
InvokeImageCallback(image, callback.Unwrap());
|
||||
@@ -100,7 +100,7 @@ void DecodeImageFromDataPipe(Dart_NativeArguments args) {
|
||||
Threads::IO()->PostTask([callback, consumer]() mutable {
|
||||
glue::DrainDataPipeJob* job = nullptr;
|
||||
job = new glue::DrainDataPipeJob(
|
||||
consumer.Unwrap(), [callback, job](std::vector<char> buffer) {
|
||||
consumer.Unwrap(), [callback, job](std::vector<uint8_t> buffer) {
|
||||
delete job;
|
||||
DecodeImageAndInvokeImageCallback(callback, std::move(buffer));
|
||||
});
|
||||
@@ -126,12 +126,11 @@ void DecodeImageFromList(Dart_NativeArguments args) {
|
||||
auto callback = glue::WrapMovable(std::unique_ptr<DartPersistentValue>(
|
||||
new DartPersistentValue(tonic::DartState::Current(), callback_handle)));
|
||||
|
||||
const char* bytes = reinterpret_cast<const char*>(list.data());
|
||||
auto buffer = glue::WrapMovable(std::unique_ptr<std::vector<char>>(
|
||||
new std::vector<char>(bytes, bytes + list.num_elements())));
|
||||
const uint8_t* bytes = reinterpret_cast<const uint8_t*>(list.data());
|
||||
std::vector<uint8_t> buffer(bytes, bytes + list.num_elements());
|
||||
|
||||
Threads::IO()->PostTask([callback, buffer]() mutable {
|
||||
DecodeImageAndInvokeImageCallback(callback, std::move(*buffer.Unwrap()));
|
||||
Threads::IO()->PostTask([ callback, buffer = std::move(buffer) ]() mutable {
|
||||
DecodeImageAndInvokeImageCallback(callback, std::move(buffer));
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
namespace blink {
|
||||
|
||||
PlatformMessage::PlatformMessage(std::string name,
|
||||
std::vector<char> data,
|
||||
std::vector<uint8_t> data,
|
||||
ftl::RefPtr<PlatformMessageResponse> response)
|
||||
: name_(std::move(name)),
|
||||
data_(std::move(data)),
|
||||
|
||||
@@ -20,7 +20,7 @@ class PlatformMessage : public ftl::RefCountedThreadSafe<PlatformMessage> {
|
||||
|
||||
public:
|
||||
const std::string& name() const { return name_; }
|
||||
const std::vector<char>& data() const { return data_; }
|
||||
const std::vector<uint8_t>& data() const { return data_; }
|
||||
|
||||
const ftl::RefPtr<PlatformMessageResponse>& response() const {
|
||||
return response_;
|
||||
@@ -28,12 +28,12 @@ class PlatformMessage : public ftl::RefCountedThreadSafe<PlatformMessage> {
|
||||
|
||||
private:
|
||||
PlatformMessage(std::string name,
|
||||
std::vector<char> data,
|
||||
std::vector<uint8_t> data,
|
||||
ftl::RefPtr<PlatformMessageResponse> response);
|
||||
~PlatformMessage();
|
||||
|
||||
std::string name_;
|
||||
std::vector<char> data_;
|
||||
std::vector<uint8_t> data_;
|
||||
ftl::RefPtr<PlatformMessageResponse> response_;
|
||||
};
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ class PlatformMessageResponse
|
||||
|
||||
public:
|
||||
// Callable on any thread.
|
||||
virtual void Complete(std::vector<char> data) = 0;
|
||||
virtual void Complete(std::vector<uint8_t> data) = 0;
|
||||
// TODO(abarth): You should be able to pass data with the error.
|
||||
virtual void CompleteWithError() = 0;
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ PlatformMessageResponseDart::~PlatformMessageResponseDart() {
|
||||
}
|
||||
}
|
||||
|
||||
void PlatformMessageResponseDart::Complete(std::vector<char> data) {
|
||||
void PlatformMessageResponseDart::Complete(std::vector<uint8_t> data) {
|
||||
if (callback_.is_empty())
|
||||
return;
|
||||
FTL_DCHECK(!is_complete_);
|
||||
@@ -63,7 +63,7 @@ void PlatformMessageResponseDart::Complete(std::vector<char> data) {
|
||||
|
||||
void PlatformMessageResponseDart::CompleteWithError() {
|
||||
// TODO(abarth): We should have a dedicated error pathway.
|
||||
Complete(std::vector<char>());
|
||||
Complete(std::vector<uint8_t>());
|
||||
}
|
||||
|
||||
} // namespace blink
|
||||
|
||||
@@ -15,7 +15,7 @@ class PlatformMessageResponseDart : public PlatformMessageResponse {
|
||||
|
||||
public:
|
||||
// Callable on any thread.
|
||||
void Complete(std::vector<char> data) override;
|
||||
void Complete(std::vector<uint8_t> data) override;
|
||||
void CompleteWithError() override;
|
||||
|
||||
protected:
|
||||
|
||||
@@ -11,7 +11,7 @@ namespace blink {
|
||||
PointerDataPacket::PointerDataPacket(size_t count)
|
||||
: data_(count * sizeof(PointerData)) {}
|
||||
|
||||
PointerDataPacket::PointerDataPacket(char* data, size_t num_bytes)
|
||||
PointerDataPacket::PointerDataPacket(uint8_t* data, size_t num_bytes)
|
||||
: data_(data, data + num_bytes) {}
|
||||
|
||||
PointerDataPacket::~PointerDataPacket() = default;
|
||||
|
||||
@@ -17,14 +17,14 @@ namespace blink {
|
||||
class PointerDataPacket {
|
||||
public:
|
||||
explicit PointerDataPacket(size_t count);
|
||||
PointerDataPacket(char* data, size_t num_bytes);
|
||||
PointerDataPacket(uint8_t* data, size_t num_bytes);
|
||||
~PointerDataPacket();
|
||||
|
||||
void SetPointerData(size_t i, const PointerData& data);
|
||||
const std::vector<char>& data() const { return data_; }
|
||||
const std::vector<uint8_t>& data() const { return data_; }
|
||||
|
||||
private:
|
||||
std::vector<char> data_;
|
||||
std::vector<uint8_t> data_;
|
||||
|
||||
FTL_DISALLOW_COPY_AND_ASSIGN(PointerDataPacket);
|
||||
};
|
||||
|
||||
@@ -21,7 +21,7 @@ using tonic::ToDart;
|
||||
namespace blink {
|
||||
namespace {
|
||||
|
||||
Dart_Handle ToByteData(const std::vector<char> buffer) {
|
||||
Dart_Handle ToByteData(const std::vector<uint8_t>& buffer) {
|
||||
if (buffer.empty())
|
||||
return Dart_Null();
|
||||
|
||||
@@ -72,7 +72,7 @@ void SendPlatformMessage(Dart_Handle window,
|
||||
Dart_Handle callback,
|
||||
const tonic::DartByteData& data) {
|
||||
UIDartState* dart_state = UIDartState::Current();
|
||||
const char* buffer = static_cast<const char*>(data.data());
|
||||
const uint8_t* buffer = static_cast<const uint8_t*>(data.data());
|
||||
|
||||
ftl::RefPtr<PlatformMessageResponse> response;
|
||||
if (!Dart_IsNull(callback)) {
|
||||
@@ -82,7 +82,7 @@ void SendPlatformMessage(Dart_Handle window,
|
||||
|
||||
UIDartState::Current()->window()->client()->HandlePlatformMessage(
|
||||
ftl::MakeRefCounted<PlatformMessage>(
|
||||
name, std::vector<char>(buffer, buffer + data.length_in_bytes()),
|
||||
name, std::vector<uint8_t>(buffer, buffer + data.length_in_bytes()),
|
||||
response));
|
||||
}
|
||||
|
||||
@@ -93,9 +93,10 @@ void _SendPlatformMessage(Dart_NativeArguments args) {
|
||||
void RespondToPlatformMessage(Dart_Handle window,
|
||||
int response_id,
|
||||
const tonic::DartByteData& data) {
|
||||
const char* buffer = static_cast<const char*>(data.data());
|
||||
const uint8_t* buffer = static_cast<const uint8_t*>(data.data());
|
||||
UIDartState::Current()->window()->CompletePlatformMessageResponse(
|
||||
response_id, std::vector<char>(buffer, buffer + data.length_in_bytes()));
|
||||
response_id,
|
||||
std::vector<uint8_t>(buffer, buffer + data.length_in_bytes()));
|
||||
}
|
||||
|
||||
void _RespondToPlatformMessage(Dart_NativeArguments args) {
|
||||
@@ -244,7 +245,7 @@ void Window::OnAppLifecycleStateChanged(sky::AppLifecycleState state) {
|
||||
}
|
||||
|
||||
void Window::CompletePlatformMessageResponse(int response_id,
|
||||
std::vector<char> data) {
|
||||
std::vector<uint8_t> data) {
|
||||
if (!response_id)
|
||||
return;
|
||||
auto it = pending_responses_.find(response_id);
|
||||
|
||||
@@ -54,7 +54,8 @@ class Window {
|
||||
|
||||
void OnAppLifecycleStateChanged(sky::AppLifecycleState state);
|
||||
|
||||
void CompletePlatformMessageResponse(int response_id, std::vector<char> data);
|
||||
void CompletePlatformMessageResponse(int response_id,
|
||||
std::vector<uint8_t> data);
|
||||
|
||||
static void RegisterNatives(tonic::DartLibraryNatives* natives);
|
||||
|
||||
|
||||
@@ -186,11 +186,11 @@ void Engine::RunFromSnapshotStream(
|
||||
TRACE_EVENT0("flutter", "Engine::RunFromSnapshotStream");
|
||||
ConfigureRuntime(script_uri);
|
||||
snapshot_drainer_.reset(new glue::DrainDataPipeJob(
|
||||
std::move(snapshot), [this](std::vector<char> snapshot) {
|
||||
std::move(snapshot), [this](std::vector<uint8_t> snapshot) {
|
||||
FTL_DCHECK(runtime_);
|
||||
FTL_DCHECK(runtime_->dart_controller());
|
||||
runtime_->dart_controller()->RunFromSnapshot(
|
||||
reinterpret_cast<uint8_t*>(snapshot.data()), snapshot.size());
|
||||
runtime_->dart_controller()->RunFromSnapshot(snapshot.data(),
|
||||
snapshot.size());
|
||||
}));
|
||||
}
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ class PlatformMessageResponseAndroid : public blink::PlatformMessageResponse {
|
||||
FRIEND_MAKE_REF_COUNTED(PlatformMessageResponseAndroid);
|
||||
|
||||
public:
|
||||
void Complete(std::vector<char> data) override {
|
||||
void Complete(std::vector<uint8_t> data) override {
|
||||
ftl::RefPtr<PlatformMessageResponseAndroid> self(this);
|
||||
blink::Threads::Platform()->PostTask(
|
||||
[ self, data = std::move(data) ]() mutable {
|
||||
@@ -48,7 +48,7 @@ class PlatformMessageResponseAndroid : public blink::PlatformMessageResponse {
|
||||
});
|
||||
}
|
||||
|
||||
void CompleteWithError() override { Complete(std::vector<char>()); }
|
||||
void CompleteWithError() override { Complete(std::vector<uint8_t>()); }
|
||||
|
||||
private:
|
||||
PlatformMessageResponseAndroid(int response_id,
|
||||
@@ -151,10 +151,10 @@ void PlatformViewAndroid::DispatchPlatformMessage(JNIEnv* env,
|
||||
response_id, GetWeakPtr());
|
||||
}
|
||||
|
||||
const uint8_t* buffer = reinterpret_cast<const uint8_t*>(data.data());
|
||||
PlatformView::DispatchPlatformMessage(
|
||||
ftl::MakeRefCounted<blink::PlatformMessage>(
|
||||
std::move(name),
|
||||
std::vector<char>(data.data(), data.data() + data.size()),
|
||||
std::move(name), std::vector<uint8_t>(buffer, buffer + data.size()),
|
||||
std::move(response)));
|
||||
}
|
||||
|
||||
@@ -162,7 +162,7 @@ void PlatformViewAndroid::DispatchPointerDataPacket(JNIEnv* env,
|
||||
jobject obj,
|
||||
jobject buffer,
|
||||
jint position) {
|
||||
char* data = static_cast<char*>(env->GetDirectBufferAddress(buffer));
|
||||
uint8_t* data = static_cast<uint8_t*>(env->GetDirectBufferAddress(buffer));
|
||||
|
||||
blink::Threads::UI()->PostTask(ftl::MakeCopyable([
|
||||
engine = engine_->GetWeakPtr(),
|
||||
@@ -190,7 +190,7 @@ void PlatformViewAndroid::InvokePlatformMessageResponseCallback(
|
||||
pending_responses_.erase(it);
|
||||
// TODO(abarth): There's an extra copy here.
|
||||
message_response->Complete(
|
||||
std::vector<char>(response.data(), response.data() + response.size()));
|
||||
std::vector<uint8_t>(response.data(), response.data() + response.size()));
|
||||
}
|
||||
|
||||
void PlatformViewAndroid::HandlePlatformMessage(
|
||||
@@ -209,7 +209,8 @@ void PlatformViewAndroid::HandlePlatformMessage(
|
||||
base::StringPiece message_name = message->name();
|
||||
|
||||
auto data = message->data();
|
||||
base::StringPiece message_data(data.data(), data.size());
|
||||
base::StringPiece message_data(reinterpret_cast<const char*>(data.data()),
|
||||
data.size());
|
||||
|
||||
auto java_message_name =
|
||||
base::android::ConvertUTF8ToJavaString(env, message_name);
|
||||
@@ -225,13 +226,14 @@ void PlatformViewAndroid::HandlePlatformMessage(
|
||||
|
||||
void PlatformViewAndroid::HandlePlatformMessageResponse(
|
||||
int response_id,
|
||||
std::vector<char> data) {
|
||||
std::vector<uint8_t> data) {
|
||||
JNIEnv* env = base::android::AttachCurrentThread();
|
||||
base::android::ScopedJavaLocalRef<jobject> view = flutter_view_.get(env);
|
||||
if (view.is_null())
|
||||
return;
|
||||
|
||||
base::StringPiece message_data(data.data(), data.size());
|
||||
base::StringPiece message_data(reinterpret_cast<const char*>(data.data()),
|
||||
data.size());
|
||||
auto java_message_data =
|
||||
base::android::ConvertUTF8ToJavaString(env, message_data);
|
||||
|
||||
@@ -281,7 +283,7 @@ void PlatformViewAndroid::UpdateSemantics(
|
||||
num_bytes += node.children.size() * kBytesPerChild;
|
||||
}
|
||||
|
||||
std::vector<char> buffer(num_bytes);
|
||||
std::vector<uint8_t> buffer(num_bytes);
|
||||
int32_t* buffer_int32 = reinterpret_cast<int32_t*>(&buffer[0]);
|
||||
float* buffer_float32 = reinterpret_cast<float*>(&buffer[0]);
|
||||
|
||||
|
||||
@@ -67,7 +67,8 @@ class PlatformViewAndroid : public PlatformView {
|
||||
void HandlePlatformMessage(
|
||||
ftl::RefPtr<blink::PlatformMessage> message) override;
|
||||
|
||||
void HandlePlatformMessageResponse(int response_id, std::vector<char> data);
|
||||
void HandlePlatformMessageResponse(int response_id,
|
||||
std::vector<uint8_t> data);
|
||||
|
||||
void RunFromSource(const std::string& main,
|
||||
const std::string& packages,
|
||||
|
||||
@@ -489,11 +489,11 @@ static inline PointerChangeMapperPhase PointerChangePhaseFromUITouchPhase(
|
||||
NSData* data = [NSJSONSerialization dataWithJSONObject:message options:0 error:nil];
|
||||
if (!data)
|
||||
return;
|
||||
const char* bytes = static_cast<const char*>(data.bytes);
|
||||
const uint8_t* bytes = static_cast<const uint8_t*>(data.bytes);
|
||||
_platformView->DispatchPlatformMessage(
|
||||
ftl::MakeRefCounted<blink::PlatformMessage>(
|
||||
messageName.UTF8String,
|
||||
std::vector<char>(bytes, bytes + data.length),
|
||||
std::vector<uint8_t>(bytes, bytes + data.length),
|
||||
nullptr));
|
||||
}
|
||||
|
||||
|
||||
@@ -11,11 +11,12 @@
|
||||
namespace shell {
|
||||
namespace {
|
||||
|
||||
std::vector<char> SysNSStringToVector(NSString* string) {
|
||||
std::vector<uint8_t> SysNSStringToVector(NSString* string) {
|
||||
if (!string.length)
|
||||
return std::vector<char>();
|
||||
const char* utf8 = string.UTF8String;
|
||||
return std::vector<char>(utf8, utf8 + strlen(utf8));
|
||||
return std::vector<uint8_t>();
|
||||
const char* chars = string.UTF8String;
|
||||
const uint8_t* bytes = reinterpret_cast<const uint8_t*>(chars);
|
||||
return std::vector<uint8_t>(bytes, bytes + strlen(chars));
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
Reference in New Issue
Block a user