Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit82d720a

Browse files
sfreilichcopybara-github
authored andcommitted
Add JNI for BrushCoat.isCompatibleWithMeshFormat and attribute-pruning CopyToStroke
Have `GetRequiredAttributeIds` return `absl::flat_hash_set` instead of `std::vector` because it's used entirely for membership checking.While here, replace one more use of `std::unordered_set` with `absl::flat_hash_set`.PiperOrigin-RevId: 785988429
1 parentb7cafe1 commit82d720a

File tree

11 files changed

+57
-18
lines changed

11 files changed

+57
-18
lines changed

‎ink/brush/BUILD.bazel‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ cc_library(
8484
":brush_paint",
8585
":brush_tip",
8686
"//ink/geometry:mesh_format",
87+
"@com_google_absl//absl/container:flat_hash_set",
8788
"@com_google_absl//absl/status",
88-
"@com_google_absl//absl/strings",
8989
"@com_google_absl//absl/strings:str_format",
9090
],
9191
)

‎ink/brush/brush_coat.cc‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616

1717
#include<string>
1818
#include<variant>
19-
#include<vector>
2019

20+
#include"absl/container/flat_hash_set.h"
2121
#include"absl/status/status.h"
2222
#include"absl/strings/str_format.h"
2323
#include"ink/brush/brush_behavior.h"
@@ -59,9 +59,9 @@ absl::Status ValidateBrushCoat(const BrushCoat& coat) {
5959
returnabsl::OkStatus();
6060
}
6161

62-
std::vector<MeshFormat::AttributeId>GetRequiredAttributeIds(
62+
absl::flat_hash_set<MeshFormat::AttributeId>GetRequiredAttributeIds(
6363
const BrushCoat& coat) {
64-
std::vector<MeshFormat::AttributeId> ids = {
64+
absl::flat_hash_set<MeshFormat::AttributeId> ids = {
6565
// All meshes must have a kPosition attribute.
6666
MeshFormat::AttributeId::kPosition,
6767
// The side/forward attributes are always required, in order to support
@@ -77,12 +77,12 @@ std::vector<MeshFormat::AttributeId> GetRequiredAttributeIds(
7777
};
7878

7979
if (BrushTipUsesColorShift(coat.tip)) {
80-
ids.push_back(MeshFormat::AttributeId::kColorShiftHsl);
80+
ids.insert(MeshFormat::AttributeId::kColorShiftHsl);
8181
}
8282

8383
for (const BrushPaint::TextureLayer& layer : coat.paint.texture_layers) {
8484
if (layer.mapping == BrushPaint::TextureMapping::kWinding) {
85-
ids.push_back(MeshFormat::AttributeId::kSurfaceUv);
85+
ids.insert(MeshFormat::AttributeId::kSurfaceUv);
8686
break;
8787
}
8888
}

‎ink/brush/brush_coat.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
#defineINK_STROKES_BRUSH_BRUSH_COAT_H_
1717

1818
#include<string>
19-
#include<vector>
2019

20+
#include"absl/container/flat_hash_set.h"
2121
#include"absl/status/status.h"
2222
#include"ink/brush/brush_paint.h"
2323
#include"ink/brush/brush_tip.h"
@@ -47,7 +47,7 @@ absl::Status ValidateBrushCoat(const BrushCoat& coat);
4747
// other attribute IDs (`kSideDerivative`, `kSideLabel`, `kForwardDerivative`,
4848
// `kForwardLabel`, and `kOpacityShift`), and may also include additional
4949
// attribute IDs depending on the tip and paint settings.
50-
std::vector<MeshFormat::AttributeId>GetRequiredAttributeIds(
50+
absl::flat_hash_set<MeshFormat::AttributeId>GetRequiredAttributeIds(
5151
const BrushCoat& coat);
5252

5353
std::stringToFormattedString(const BrushCoat& coat);

‎ink/brush/internal/jni/BUILD.bazel‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,11 @@ cc_library(
132132
"//ink/brush:brush_coat",
133133
"//ink/brush:brush_paint",
134134
"//ink/brush:brush_tip",
135+
"//ink/geometry:mesh_format",
136+
"//ink/geometry/internal/jni:mesh_format_jni_helper",
135137
"//ink/jni/internal:jni_defines",
136138
"@com_google_absl//absl/log:absl_check",
139+
"@com_google_absl//absl/types:span",
137140
]+select({
138141
"@platforms//os:android": [],
139142
"//conditions:default": [

‎ink/brush/internal/jni/brush_coat_jni.cc‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,24 @@
1414

1515
#include<jni.h>
1616

17+
#include<algorithm>
18+
19+
#include"absl/types/span.h"
1720
#include"ink/brush/brush_coat.h"
1821
#include"ink/brush/internal/jni/brush_jni_helper.h"
22+
#include"ink/geometry/internal/jni/mesh_format_jni_helper.h"
23+
#include"ink/geometry/mesh_format.h"
1924
#include"ink/jni/internal/jni_defines.h"
2025

2126
namespace {
2227

2328
using ::ink::BrushCoat;
29+
using ::ink::MeshFormat;
30+
using ::ink::brush_internal::GetRequiredAttributeIds;
2431
using ::ink::jni::CastToBrushCoat;
2532
using ::ink::jni::CastToBrushPaint;
2633
using ::ink::jni::CastToBrushTip;
34+
using ::ink::jni::CastToMeshFormat;
2735
using ::ink::jni::DeleteNativeBrushCoat;
2836
using ::ink::jni::NewNativeBrushCoat;
2937
using ::ink::jni::NewNativeBrushPaint;
@@ -43,6 +51,23 @@ JNI_METHOD(brush, BrushCoatNative, jlong, create)
4351
});
4452
}
4553

54+
JNI_METHOD(brush, BrushCoatNative, jboolean, isCompatibleWithMeshFormat)
55+
(JNIEnv* env, jobject obj, jlong native_pointer,
56+
jlong mesh_format_native_pointer) {
57+
absl::Span<const MeshFormat::Attribute> mesh_attributes =
58+
CastToMeshFormat(mesh_format_native_pointer).Attributes();
59+
for (const MeshFormat::AttributeId& required_attribute_id :
60+
GetRequiredAttributeIds(CastToBrushCoat(native_pointer))) {
61+
if (std::find_if(mesh_attributes.begin(), mesh_attributes.end(),
62+
[&](const MeshFormat::Attribute& attr) {
63+
return attr.id == required_attribute_id;
64+
}) == mesh_attributes.end()) {
65+
returnfalse;
66+
}
67+
}
68+
returntrue;
69+
}
70+
4671
JNI_METHOD(brush, BrushCoatNative,void, free)
4772
(JNIEnv* env, jobject thiz, jlong native_pointer) {
4873
DeleteNativeBrushCoat(native_pointer);

‎ink/geometry/internal/jni/mesh_format_jni.cc‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ JNI_METHOD(geometry, MeshFormatNative, jboolean, isUnpackedEquivalent)
4040
CastToMeshFormat(native_pointer),CastToMeshFormat(other_native_pointer));
4141
}
4242

43+
JNI_METHOD(geometry, MeshFormatNative, jint, attributeCount)
44+
(JNIEnv* env, jobject obj, jlong native_pointer) {
45+
returnCastToMeshFormat(native_pointer).Attributes().size();
46+
}
47+
4348
JNI_METHOD(geometry, MeshFormatNative,void, free)
4449
(JNIEnv* env, jobject obj, jlong native_pointer) {
4550
DeleteNativeMeshFormat(native_pointer);

‎ink/storage/BUILD.bazel‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,7 @@ cc_library(
307307
"//ink/storage/proto:brush_family_cc_proto",
308308
"//ink/storage/proto:stroke_input_batch_cc_proto",
309309
"//ink/types:duration",
310+
"@com_google_absl//absl/container:flat_hash_set",
310311
"@com_google_absl//absl/status",
311312
"@com_google_absl//absl/status:statusor",
312313
"@com_google_absl//absl/strings",

‎ink/storage/brush.cc‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@
1818
#include<map>
1919
#include<optional>
2020
#include<string>
21-
#include<unordered_set>
2221
#include<utility>
2322
#include<variant>
2423
#include<vector>
2524

25+
#include"absl/container/flat_hash_set.h"
2626
#include"absl/status/status.h"
2727
#include"absl/status/statusor.h"
2828
#include"absl/strings/str_cat.h"
@@ -1459,7 +1459,7 @@ void EncodeBrushFamilyTextureMap(
14591459
TextureBitmapProvider get_bitmap) {
14601460
texture_id_to_bitmap_out.clear();
14611461
// The set of texture ids for which we have already called get_bitmap().
1462-
std::unordered_set<std::string> seen_ids = {};
1462+
absl::flat_hash_set<std::string> seen_ids;
14631463
for (const BrushCoat& coat : family.GetCoats()) {
14641464
for (const BrushPaint::TextureLayer& layer : coat.paint.texture_layers) {
14651465
if (seen_ids.find(layer.client_texture_id) != seen_ids.end()) {

‎ink/strokes/BUILD.bazel‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,8 @@ cc_library(
117117
"//ink/strokes/internal:stroke_shape_update",
118118
"//ink/strokes/internal:stroke_vertex",
119119
"//ink/types:duration",
120-
"@com_google_absl//absl/algorithm:container",
121120
"@com_google_absl//absl/base:nullability",
121+
"@com_google_absl//absl/container:flat_hash_set",
122122
"@com_google_absl//absl/container:inlined_vector",
123123
"@com_google_absl//absl/log:absl_check",
124124
"@com_google_absl//absl/log:absl_log",

‎ink/strokes/in_progress_stroke.cc‎

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616

1717
#include<cstdint>
1818
#include<optional>
19-
#include<vector>
19+
#include<unordered_set>
2020

21-
#include"absl/algorithm/container.h"
21+
#include"absl/container/flat_hash_set.h"
2222
#include"absl/container/inlined_vector.h"
2323
#include"absl/log/absl_check.h"
2424
#include"absl/log/absl_log.h"
@@ -252,15 +252,12 @@ Stroke InProgressStroke::CopyToStroke(
252252
case RetainAttributes::kAll:
253253
break;
254254
case RetainAttributes::kUsedByThisBrush: {
255-
std::vector<MeshFormat::AttributeId> required_attributes =
255+
absl::flat_hash_set<MeshFormat::AttributeId> required_attributes =
256256
brush_internal::GetRequiredAttributeIds(
257257
brush->GetFamily().GetCoats()[coat_index]);
258258
for (MeshFormat::Attribute attribute :
259259
GetMesh(coat_index).Format().Attributes()) {
260-
if (absl::c_find_if(required_attributes,
261-
[attribute](MeshFormat::AttributeId id) {
262-
return id == attribute.id;
263-
}) == required_attributes.end()) {
260+
if (!required_attributes.contains(attribute.id)) {
264261
omit_attributes[coat_index].push_back(attribute.id);
265262
}
266263
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp