Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 84 additions & 0 deletions fml/lightweight_string.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef FLUTTER_FML_LIGHTWEIGHT_STRING_H_
#define FLUTTER_FML_LIGHTWEIGHT_STRING_H_

#include <cstdlib>
#include <cstring>
#include <string>

#include "flutter/fml/logging.h"
#include "flutter/fml/macros.h"

namespace fml {

/// An 16 byte string that does not copy string literals.
class LightweightString {
public:
LightweightString() {
str_.c = nullptr;
is_owned_ = false;
}

LightweightString(const LightweightString& str) {
if (str.is_owned_) {
str_.c = strdup(str.str_.cc);
is_owned_ = true;
} else {
str_.cc = str.str_.cc;
is_owned_ = false;
}
}

template <size_t N>
constexpr LightweightString(const char (&s)[N]) {
str_.cc = s;
is_owned_ = false;
}

LightweightString(const std::string& str) {
str_.c = strdup(str.c_str());
is_owned_ = true;
}

~LightweightString() {
if (is_owned_) {
free(str_.c);
}
}

const char* c_str() const { return str_.cc; }

bool empty() const { return str_.cc == nullptr; }

LightweightString& operator=(const LightweightString& str) {
if (is_owned_) {
free(str_.c);
}
if (str.is_owned_) {
str_.c = strdup(str.str_.cc);
is_owned_ = true;
} else {
str_.cc = str.str_.cc;
is_owned_ = false;
}
return *this;
}

private:
typedef union {
char* c;
const char* cc;
} StrPtr;

StrPtr str_;
uint8_t is_owned_;
};

static_assert(sizeof(LightweightString) < sizeof(std::string));

} // namespace fml

#endif // FLUTTER_FML_LIGHTWEIGHT_STRING_H_
7 changes: 4 additions & 3 deletions impeller/entity/contents/texture_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,10 @@ bool TextureContents::Render(const ContentContext& renderer,
frame_info.alpha = GetOpacity();

Command cmd;
cmd.label = "Texture Fill";
if (!label_.empty()) {
cmd.label += ": " + label_;
if (label_.empty()) {
cmd.label = "Texture Fill";
} else {
cmd.label = "Texture Fill: " + label_;
}

auto pipeline_options = OptionsFromPassAndEntity(pass, entity);
Expand Down
6 changes: 5 additions & 1 deletion impeller/entity/contents/tiled_texture_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,11 @@ bool TiledTextureContents::Render(const ContentContext& renderer,
frame_info.alpha = GetOpacityFactor();

Command cmd;
cmd.label = uses_emulated_tile_mode ? "TiledTextureFill" : "TextureFill";
if (uses_emulated_tile_mode) {
cmd.label = "TiledTextureFill";
} else {
cmd.label = "TextureFill";
}
cmd.stencil_reference = entity.GetStencilDepth();

auto options = OptionsFromPassAndEntity(pass, entity);
Expand Down
2 changes: 1 addition & 1 deletion impeller/renderer/backend/gles/render_pass_gles.cc
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ struct RenderPassData {
fml::ScopedCleanupClosure pop_cmd_debug_marker(
[&gl]() { gl.PopDebugGroup(); });
if (!command.label.empty()) {
gl.PushDebugGroup(command.label);
gl.PushDebugGroup(command.label.c_str());
} else {
pop_cmd_debug_marker.Release();
}
Expand Down
11 changes: 10 additions & 1 deletion impeller/renderer/command.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <optional>
#include <string>

#include "flutter/fml/lightweight_string.h"
#include "flutter/fml/logging.h"
#include "flutter/fml/macros.h"
#include "impeller/core/buffer_view.h"
Expand Down Expand Up @@ -119,7 +120,7 @@ struct Command : public ResourceBinder {
//----------------------------------------------------------------------------
/// The debugging label to use for the command.
///
std::string label;
fml::LightweightString label;
//----------------------------------------------------------------------------
/// The reference value to use in stenciling operations. Stencil configuration
/// is part of pipeline setup and can be read from the pipelines descriptor.
Expand Down Expand Up @@ -205,4 +206,12 @@ struct Command : public ResourceBinder {
const BufferView& view);
};

// Many Commands are allocated per frame so care should be taken when increasing
// their size.
#if defined(__SIZEOF_POINTER__)
#if __SIZEOF_POINTER__ == 8
static_assert(sizeof(Command) == 432);
#endif
#endif

} // namespace impeller