diff --git a/.clang-tidy b/.clang-tidy index fd85d3254f7ee..a8ad73bfd8abc 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -9,4 +9,5 @@ Checks: "google-*,\ # to prevent new warnings being introduced. # https://github.com/flutter/flutter/issues/93279 WarningsAsErrors: "clang-analyzer-osx.*,\ -google-objc-*" +google-objc-*,\ +google-explicit-constructor" diff --git a/flow/display_list.cc b/flow/display_list.cc index a2f1965bd3925..4ed97a8766ef8 100644 --- a/flow/display_list.cc +++ b/flow/display_list.cc @@ -71,7 +71,7 @@ struct DLOp { struct Set##name##Op final : DLOp { \ static const auto kType = DisplayListOpType::kSet##name; \ \ - Set##name##Op(bool value) : value(value) {} \ + explicit Set##name##Op(bool value) : value(value) {} \ \ const bool value; \ \ @@ -85,17 +85,17 @@ DEFINE_SET_BOOL_OP(InvertColors) #undef DEFINE_SET_BOOL_OP // 4 byte header + 4 byte payload packs into minimum 8 bytes -#define DEFINE_SET_ENUM_OP(name) \ - struct SetStroke##name##Op final : DLOp { \ - static const auto kType = DisplayListOpType::kSetStroke##name; \ - \ - SetStroke##name##Op(SkPaint::name value) : value(value) {} \ - \ - const SkPaint::name value; \ - \ - void dispatch(Dispatcher& dispatcher) const { \ - dispatcher.setStroke##name(value); \ - } \ +#define DEFINE_SET_ENUM_OP(name) \ + struct SetStroke##name##Op final : DLOp { \ + static const auto kType = DisplayListOpType::kSetStroke##name; \ + \ + explicit SetStroke##name##Op(SkPaint::name value) : value(value) {} \ + \ + const SkPaint::name value; \ + \ + void dispatch(Dispatcher& dispatcher) const { \ + dispatcher.setStroke##name(value); \ + } \ }; DEFINE_SET_ENUM_OP(Cap) DEFINE_SET_ENUM_OP(Join) @@ -162,26 +162,26 @@ struct SetBlendModeOp final : DLOp { // Set: 4 byte header + an sk_sp (ptr) uses 16 bytes due to the // alignment of the ptr. // (4 bytes unused) -#define DEFINE_SET_CLEAR_SKREF_OP(name, field) \ - struct Clear##name##Op final : DLOp { \ - static const auto kType = DisplayListOpType::kClear##name; \ - \ - Clear##name##Op() {} \ - \ - void dispatch(Dispatcher& dispatcher) const { \ - dispatcher.set##name(nullptr); \ - } \ - }; \ - struct Set##name##Op final : DLOp { \ - static const auto kType = DisplayListOpType::kSet##name; \ - \ - Set##name##Op(sk_sp field) : field(std::move(field)) {} \ - \ - sk_sp field; \ - \ - void dispatch(Dispatcher& dispatcher) const { \ - dispatcher.set##name(field); \ - } \ +#define DEFINE_SET_CLEAR_SKREF_OP(name, field) \ + struct Clear##name##Op final : DLOp { \ + static const auto kType = DisplayListOpType::kClear##name; \ + \ + Clear##name##Op() {} \ + \ + void dispatch(Dispatcher& dispatcher) const { \ + dispatcher.set##name(nullptr); \ + } \ + }; \ + struct Set##name##Op final : DLOp { \ + static const auto kType = DisplayListOpType::kSet##name; \ + \ + explicit Set##name##Op(sk_sp field) : field(std::move(field)) {} \ + \ + sk_sp field; \ + \ + void dispatch(Dispatcher& dispatcher) const { \ + dispatcher.set##name(field); \ + } \ }; DEFINE_SET_CLEAR_SKREF_OP(Blender, blender) DEFINE_SET_CLEAR_SKREF_OP(Shader, shader) @@ -198,7 +198,7 @@ DEFINE_SET_CLEAR_SKREF_OP(PathEffect, effect) struct SetMaskBlurFilter##name##Op final : DLOp { \ static const auto kType = DisplayListOpType::kSetMaskBlurFilter##name; \ \ - SetMaskBlurFilter##name##Op(SkScalar sigma) : sigma(sigma) {} \ + explicit SetMaskBlurFilter##name##Op(SkScalar sigma) : sigma(sigma) {} \ \ SkScalar sigma; \ \ @@ -432,17 +432,17 @@ struct DrawColorOp final : DLOp { // (4 bytes unused) // SkOval is same as SkRect // SkRRect is 52 more bytes, which packs efficiently into 56 bytes total -#define DEFINE_DRAW_1ARG_OP(op_name, arg_type, arg_name) \ - struct Draw##op_name##Op final : DLOp { \ - static const auto kType = DisplayListOpType::kDraw##op_name; \ - \ - Draw##op_name##Op(arg_type arg_name) : arg_name(arg_name) {} \ - \ - const arg_type arg_name; \ - \ - void dispatch(Dispatcher& dispatcher) const { \ - dispatcher.draw##op_name(arg_name); \ - } \ +#define DEFINE_DRAW_1ARG_OP(op_name, arg_type, arg_name) \ + struct Draw##op_name##Op final : DLOp { \ + static const auto kType = DisplayListOpType::kDraw##op_name; \ + \ + explicit Draw##op_name##Op(arg_type arg_name) : arg_name(arg_name) {} \ + \ + const arg_type arg_name; \ + \ + void dispatch(Dispatcher& dispatcher) const { \ + dispatcher.draw##op_name(arg_name); \ + } \ }; DEFINE_DRAW_1ARG_OP(Rect, SkRect, rect) DEFINE_DRAW_1ARG_OP(Oval, SkRect, oval) @@ -518,7 +518,7 @@ struct DrawArcOp final : DLOp { struct Draw##name##Op final : DLOp { \ static const auto kType = DisplayListOpType::kDraw##name; \ \ - Draw##name##Op(uint32_t count) : count(count) {} \ + explicit Draw##name##Op(uint32_t count) : count(count) {} \ \ const uint32_t count; \ \ @@ -868,7 +868,7 @@ void DisplayList::Dispatch(Dispatcher& dispatcher, uint8_t* ptr, uint8_t* end) const { while (ptr < end) { - auto op = (const DLOp*)ptr; + auto op = reinterpret_cast(ptr); ptr += op->size; FML_DCHECK(ptr <= end); switch (op->type) { @@ -890,7 +890,7 @@ void DisplayList::Dispatch(Dispatcher& dispatcher, static void DisposeOps(uint8_t* ptr, uint8_t* end) { while (ptr < end) { - auto op = (const DLOp*)ptr; + auto op = reinterpret_cast(ptr); ptr += op->size; FML_DCHECK(ptr <= end); switch (op->type) { @@ -922,8 +922,8 @@ static bool CompareOps(uint8_t* ptrA, uint8_t* bulkStartA = ptrA; uint8_t* bulkStartB = ptrB; while (ptrA < endA && ptrB < endB) { - auto opA = (const DLOp*)ptrA; - auto opB = (const DLOp*)ptrB; + auto opA = reinterpret_cast(ptrA); + auto opB = reinterpret_cast(ptrB); if (opA->type != opB->type || opA->size != opB->size) { return false; } @@ -1047,7 +1047,7 @@ void* DisplayListBuilder::Push(size_t pod, int op_inc, Args&&... args) { memset(storage_.get() + used_, 0, allocated_ - used_); } FML_DCHECK(used_ + size <= allocated_); - auto op = (T*)(storage_.get() + used_); + auto op = reinterpret_cast(storage_.get() + used_); used_ += size; new (op) T{std::forward(args)...}; op->type = T::kType; diff --git a/flow/display_list.h b/flow/display_list.h index ebaed09d8af5b..d7b439face475 100644 --- a/flow/display_list.h +++ b/flow/display_list.h @@ -559,7 +559,7 @@ class DisplayListFlags { class DisplayListFlagsBase : protected DisplayListFlags { protected: - DisplayListFlagsBase(int flags) : flags_(flags) {} + explicit DisplayListFlagsBase(int flags) : flags_(flags) {} const int flags_; @@ -594,7 +594,8 @@ class DisplayListSpecialGeometryFlags : DisplayListFlagsBase { bool may_have_acute_joins() const { return has_any(kMayHaveAcuteJoins_); } private: - DisplayListSpecialGeometryFlags(int flags) : DisplayListFlagsBase(flags) { + explicit DisplayListSpecialGeometryFlags(int flags) + : DisplayListFlagsBase(flags) { FML_DCHECK((flags & kAnySpecialGeometryMask_) == flags); } @@ -675,7 +676,7 @@ class DisplayListAttributeFlags : DisplayListFlagsBase { bool is_flood() const { return has_any(kFloodsSurface_); } private: - DisplayListAttributeFlags(int flags) + explicit DisplayListAttributeFlags(int flags) : DisplayListFlagsBase(flags), special_flags_(flags & kAnySpecialGeometryMask_) { FML_DCHECK((flags & kIsAnyGeometryMask_) == kIsNonGeometric_ || @@ -694,7 +695,7 @@ class DisplayListAttributeFlags : DisplayListFlagsBase { const DisplayListAttributeFlags without(int remove) const { FML_DCHECK(has_all(remove)); - return (flags_ & ~remove); + return DisplayListAttributeFlags(flags_ & ~remove); } const DisplayListSpecialGeometryFlags special_flags_; diff --git a/flow/display_list_canvas_unittests.cc b/flow/display_list_canvas_unittests.cc index 22716abb497f5..4352c01008ad1 100644 --- a/flow/display_list_canvas_unittests.cc +++ b/flow/display_list_canvas_unittests.cc @@ -244,7 +244,7 @@ static void EmptyDlRenderer(DisplayListBuilder&) {} class RenderSurface { public: - RenderSurface(sk_sp surface) : surface_(surface) {} + explicit RenderSurface(sk_sp surface) : surface_(surface) {} ~RenderSurface() { sk_free(addr_); } SkCanvas* canvas() { return surface_->getCanvas(); } @@ -311,7 +311,7 @@ class RenderEnvironment { const SkPixmap* ref_pixmap() const { return ref_pixmap_; } private: - RenderEnvironment(const SkImageInfo& info) + explicit RenderEnvironment(const SkImageInfo& info) : info_(info), ref_surface_(MakeSurface()) {} const SkImageInfo info_; @@ -609,7 +609,7 @@ class TestParameters { class CaseParameters { public: - CaseParameters(std::string info) + explicit CaseParameters(std::string info) : CaseParameters(info, EmptyCvRenderer, EmptyDlRenderer) {} CaseParameters(std::string info, CvSetup cv_setup, DlRenderer dl_setup) diff --git a/flow/display_list_utils.cc b/flow/display_list_utils.cc index 6cf86f16707ee..5532390cfb575 100644 --- a/flow/display_list_utils.cc +++ b/flow/display_list_utils.cc @@ -214,7 +214,7 @@ void ClipBoundsDispatchHelper::restore() { } } void ClipBoundsDispatchHelper::reset(const SkRect* cull_rect) { - if ((has_clip_ = ((bool)cull_rect)) && !cull_rect->isEmpty()) { + if ((has_clip_ = cull_rect != nullptr) && !cull_rect->isEmpty()) { bounds_ = *cull_rect; } else { bounds_.setEmpty(); diff --git a/fml/mapping_unittests.cc b/fml/mapping_unittests.cc index 7bc1c62d09aba..7dc397dbde14e 100644 --- a/fml/mapping_unittests.cc +++ b/fml/mapping_unittests.cc @@ -25,7 +25,8 @@ TEST(MallocMapping, MoveConstructor) { MallocMapping mapping(reinterpret_cast(malloc(length)), length); MallocMapping moved = std::move(mapping); - ASSERT_EQ(nullptr, mapping.GetMapping()); + ASSERT_EQ(nullptr, + mapping.GetMapping()); // NOLINT(clang-analyzer-cplusplus.Move) ASSERT_EQ(0u, mapping.GetSize()); ASSERT_NE(nullptr, moved.GetMapping()); ASSERT_EQ(length, moved.GetSize()); diff --git a/fml/platform/linux/message_loop_linux.cc b/fml/platform/linux/message_loop_linux.cc index 5ed41aef8fa4e..6e6febc2201f6 100644 --- a/fml/platform/linux/message_loop_linux.cc +++ b/fml/platform/linux/message_loop_linux.cc @@ -81,6 +81,7 @@ void MessageLoopLinux::Terminate() { // |fml::MessageLoopImpl| void MessageLoopLinux::WakeUp(fml::TimePoint time_point) { bool result = TimerRearm(timer_fd_.get(), time_point); + (void)result; FML_DCHECK(result); } diff --git a/fml/platform/linux/timerfd.cc b/fml/platform/linux/timerfd.cc index 166b861909663..39d4f8a59c68d 100644 --- a/fml/platform/linux/timerfd.cc +++ b/fml/platform/linux/timerfd.cc @@ -44,7 +44,7 @@ bool TimerRearm(int fd, fml::TimePoint time_point) { } struct itimerspec spec = {}; - spec.it_value.tv_sec = (time_t)(nano_secs / NSEC_PER_SEC); + spec.it_value.tv_sec = static_cast(nano_secs / NSEC_PER_SEC); spec.it_value.tv_nsec = nano_secs % NSEC_PER_SEC; spec.it_interval = spec.it_value; // single expiry. diff --git a/fml/synchronization/semaphore.cc b/fml/synchronization/semaphore.cc index 9dff734603aa0..548731d6700ea 100644 --- a/fml/synchronization/semaphore.cc +++ b/fml/synchronization/semaphore.cc @@ -107,6 +107,7 @@ class PlatformSemaphore { ~PlatformSemaphore() { if (valid_) { int result = ::sem_destroy(&sem_); + (void)result; // Can only be EINVAL which should not be possible since we checked for // validity. FML_DCHECK(result == 0); diff --git a/lib/ui/painting/image_filter.cc b/lib/ui/painting/image_filter.cc index 2b20b22ac5f6e..d4c2974172e9f 100644 --- a/lib/ui/painting/image_filter.cc +++ b/lib/ui/painting/image_filter.cc @@ -50,7 +50,8 @@ static const std::array filter_qualities = { SkSamplingOptions ImageFilter::SamplingFromIndex(int filterQualityIndex) { if (filterQualityIndex < 0) { return filter_qualities.front(); - } else if (((size_t)filterQualityIndex) >= filter_qualities.size()) { + } else if (static_cast(filterQualityIndex) >= + filter_qualities.size()) { return filter_qualities.back(); } else { return filter_qualities[filterQualityIndex]; diff --git a/lib/ui/painting/image_generator.cc b/lib/ui/painting/image_generator.cc index 015713dcd453d..59ee40768fe8f 100644 --- a/lib/ui/painting/image_generator.cc +++ b/lib/ui/painting/image_generator.cc @@ -102,7 +102,7 @@ unsigned int BuiltinSkiaCodecImageGenerator::GetPlayCount() const { const ImageGenerator::FrameInfo BuiltinSkiaCodecImageGenerator::GetFrameInfo( unsigned int frame_index) const { - SkCodec::FrameInfo info; + SkCodec::FrameInfo info = {}; codec_generator_->getFrameInfo(frame_index, &info); return { .required_frame = info.fRequiredFrame == SkCodec::kNoFrame diff --git a/lib/ui/painting/image_generator_registry_unittests.cc b/lib/ui/painting/image_generator_registry_unittests.cc index 8c0879848df2f..ea3fb2254c469 100644 --- a/lib/ui/painting/image_generator_registry_unittests.cc +++ b/lib/ui/painting/image_generator_registry_unittests.cc @@ -48,7 +48,7 @@ TEST_F(ShellTest, CreateCompatibleReturnsNullptrForInvalidImage) { class FakeImageGenerator : public ImageGenerator { public: - FakeImageGenerator(int identifiableFakeWidth) + explicit FakeImageGenerator(int identifiableFakeWidth) : info_(SkImageInfo::Make(identifiableFakeWidth, identifiableFakeWidth, SkColorType::kRGBA_8888_SkColorType, diff --git a/runtime/isolate_configuration.cc b/runtime/isolate_configuration.cc index dee5c781691bb..649d52e46f8c1 100644 --- a/runtime/isolate_configuration.cc +++ b/runtime/isolate_configuration.cc @@ -43,7 +43,8 @@ class AppSnapshotIsolateConfiguration final : public IsolateConfiguration { class KernelIsolateConfiguration : public IsolateConfiguration { public: - KernelIsolateConfiguration(std::unique_ptr kernel) + explicit KernelIsolateConfiguration( + std::unique_ptr kernel) : kernel_(std::move(kernel)) {} // |IsolateConfiguration| @@ -69,7 +70,7 @@ class KernelIsolateConfiguration : public IsolateConfiguration { class KernelListIsolateConfiguration final : public IsolateConfiguration { public: - KernelListIsolateConfiguration( + explicit KernelListIsolateConfiguration( std::vector>> kernel_pieces) : kernel_piece_futures_(std::move(kernel_pieces)) { diff --git a/shell/common/shell.cc b/shell/common/shell.cc index 7f212ad55ca2c..b13e55ec069d1 100644 --- a/shell/common/shell.cc +++ b/shell/common/shell.cc @@ -1367,6 +1367,7 @@ void Shell::OnFrameRasterized(const FrameTiming& timing) { } size_t old_count = unreported_timings_.size(); + (void)old_count; for (auto phase : FrameTiming::kPhases) { unreported_timings_.push_back( timing.Get(phase).ToEpochDelta().ToMicroseconds()); diff --git a/shell/common/shell_unittests.cc b/shell/common/shell_unittests.cc index 2450e4a369b64..9a77142edb3ba 100644 --- a/shell/common/shell_unittests.cc +++ b/shell/common/shell_unittests.cc @@ -1880,7 +1880,7 @@ TEST_F(ShellTest, CanConvertToAndFromMappings) { const size_t buffer_size = 2 << 20; uint8_t* buffer = static_cast(::malloc(buffer_size)); - ASSERT_NE(buffer, nullptr); + ASSERT_TRUE(buffer != nullptr); ASSERT_TRUE(MemsetPatternSetOrCheck( buffer, buffer_size, MemsetPatternOp::kMemsetPatternOpSetBuffer)); diff --git a/shell/common/switches.cc b/shell/common/switches.cc index 050452c75e862..38d4ece83a2fc 100644 --- a/shell/common/switches.cc +++ b/shell/common/switches.cc @@ -200,7 +200,7 @@ static bool GetSwitchValue(const fml::CommandLine& command_line, std::unique_ptr GetSymbolMapping(std::string symbol_prefix, std::string native_lib_path) { - const uint8_t* mapping; + const uint8_t* mapping = nullptr; intptr_t size; auto lookup_symbol = [&mapping, &size, symbol_prefix]( diff --git a/shell/gpu/gpu_surface_gl.cc b/shell/gpu/gpu_surface_gl.cc index 518764a15694e..6e81d0a0ae4f0 100644 --- a/shell/gpu/gpu_surface_gl.cc +++ b/shell/gpu/gpu_surface_gl.cc @@ -129,7 +129,7 @@ static SkColorType FirstSupportedColorType(GrDirectContext* context, static sk_sp WrapOnscreenSurface(GrDirectContext* context, const SkISize& size, intptr_t fbo) { - GrGLenum format; + GrGLenum format = kUnknown_SkColorType; const SkColorType color_type = FirstSupportedColorType(context, &format); GrGLFramebufferInfo framebuffer_info = {}; diff --git a/shell/platform/android/external_view_embedder/external_view_embedder_unittests.cc b/shell/platform/android/external_view_embedder/external_view_embedder_unittests.cc index 7d66258bb5fe3..c5a3c19701a3f 100644 --- a/shell/platform/android/external_view_embedder/external_view_embedder_unittests.cc +++ b/shell/platform/android/external_view_embedder/external_view_embedder_unittests.cc @@ -112,7 +112,7 @@ TEST(AndroidExternalViewEmbedder, GetCurrentCanvases) { ASSERT_EQ(SkISize::Make(10, 20), canvases[1]->getBaseLayerSize()); } -TEST(AndroidExternalViewEmbedder, GetCurrentCanvases__CompositeOrder) { +TEST(AndroidExternalViewEmbedder, GetCurrentCanvasesCompositeOrder) { auto jni_mock = std::make_shared(); auto android_context = AndroidContext(AndroidRenderingAPI::kSoftware); @@ -248,7 +248,7 @@ TEST(AndroidExternalViewEmbedder, PlatformViewRect) { ASSERT_EQ(SkRect::MakeXYWH(15, 30, 45, 60), embedder->GetViewRect(view_id)); } -TEST(AndroidExternalViewEmbedder, PlatformViewRect__ChangedParams) { +TEST(AndroidExternalViewEmbedder, PlatformViewRectChangedParams) { auto jni_mock = std::make_shared(); auto android_context = AndroidContext(AndroidRenderingAPI::kSoftware); @@ -488,7 +488,7 @@ TEST(AndroidExternalViewEmbedder, SubmitFrame) { } } -TEST(AndroidExternalViewEmbedder, SubmitFrame__overlayComposition) { +TEST(AndroidExternalViewEmbedder, SubmitFrameOverlayComposition) { auto jni_mock = std::make_shared(); auto android_context = std::make_shared(AndroidRenderingAPI::kSoftware); @@ -590,7 +590,7 @@ TEST(AndroidExternalViewEmbedder, SubmitFrame__overlayComposition) { embedder->EndFrame(/*should_resubmit_frame=*/false, raster_thread_merger); } -TEST(AndroidExternalViewEmbedder, SubmitFrame__platformViewWithoutAnyOverlay) { +TEST(AndroidExternalViewEmbedder, SubmitFramePlatformViewWithoutAnyOverlay) { auto jni_mock = std::make_shared(); auto android_context = std::make_shared(AndroidRenderingAPI::kSoftware); diff --git a/shell/platform/android/external_view_embedder/surface_pool_unittests.cc b/shell/platform/android/external_view_embedder/surface_pool_unittests.cc index ce37e8c81a8e7..caebb97f4fd03 100644 --- a/shell/platform/android/external_view_embedder/surface_pool_unittests.cc +++ b/shell/platform/android/external_view_embedder/surface_pool_unittests.cc @@ -36,7 +36,7 @@ class TestAndroidSurfaceFactory : public AndroidSurfaceFactory { TestSurfaceProducer surface_producer_; }; -TEST(SurfacePool, GetLayer__AllocateOneLayer) { +TEST(SurfacePool, GetLayerAllocateOneLayer) { auto pool = std::make_unique(); auto gr_context = GrDirectContext::MakeMock(nullptr); @@ -100,7 +100,7 @@ TEST(SurfacePool, GetUnusedLayers) { ASSERT_EQ(layer, pool->GetUnusedLayers()[0]); } -TEST(SurfacePool, GetLayer__Recycle) { +TEST(SurfacePool, GetLayerRecycle) { auto pool = std::make_unique(); auto gr_context_1 = GrDirectContext::MakeMock(nullptr); @@ -145,7 +145,7 @@ TEST(SurfacePool, GetLayer__Recycle) { layer_2->gr_context_key); } -TEST(SurfacePool, GetLayer__AllocateTwoLayers) { +TEST(SurfacePool, GetLayerAllocateTwoLayers) { auto pool = std::make_unique(); auto gr_context = GrDirectContext::MakeMock(nullptr); @@ -219,7 +219,7 @@ TEST(SurfacePool, DestroyLayers) { ASSERT_TRUE(pool->GetUnusedLayers().empty()); } -TEST(SurfacePool, DestroyLayers__frameSizeChanged) { +TEST(SurfacePool, DestroyLayersFrameSizeChanged) { auto pool = std::make_unique(); auto jni_mock = std::make_shared(); diff --git a/shell/platform/common/client_wrapper/standard_codec.cc b/shell/platform/common/client_wrapper/standard_codec.cc index f16a0f9792ac2..807e06816bee3 100644 --- a/shell/platform/common/client_wrapper/standard_codec.cc +++ b/shell/platform/common/client_wrapper/standard_codec.cc @@ -231,11 +231,11 @@ size_t StandardCodecSerializer::ReadSize(ByteStreamReader* stream) const { if (byte < 254) { return byte; } else if (byte == 254) { - uint16_t value; + uint16_t value = 0; stream->ReadBytes(reinterpret_cast(&value), 2); return value; } else { - uint32_t value; + uint32_t value = 0; stream->ReadBytes(reinterpret_cast(&value), 4); return value; } diff --git a/shell/platform/darwin/common/buffer_conversions.mm b/shell/platform/darwin/common/buffer_conversions.mm index 0cc86073a10c7..6ba9b1e4a53ab 100644 --- a/shell/platform/darwin/common/buffer_conversions.mm +++ b/shell/platform/darwin/common/buffer_conversions.mm @@ -10,7 +10,7 @@ namespace { class NSDataMapping : public fml::Mapping { public: - NSDataMapping(NSData* data) : data_([data retain]) {} + explicit NSDataMapping(NSData* data) : data_([data retain]) {} size_t GetSize() const override { return [data_.get() length]; } diff --git a/shell/platform/embedder/tests/embedder_a11y_unittests.cc b/shell/platform/embedder/tests/embedder_a11y_unittests.cc index b0d88bcc4f0b1..9f06542b9d578 100644 --- a/shell/platform/embedder/tests/embedder_a11y_unittests.cc +++ b/shell/platform/embedder/tests/embedder_a11y_unittests.cc @@ -187,6 +187,7 @@ TEST_F(Embedder11yTest, A11yTreeIsConsistent) { std::vector bytes({2, 1}); result = FlutterEngineDispatchSemanticsAction( engine.get(), 42, kFlutterSemanticsActionTap, &bytes[0], bytes.size()); + ASSERT_EQ(result, FlutterEngineResult::kSuccess); latch.Wait(); // Disable semantics. Wait for NotifySemanticsEnabled(false). diff --git a/shell/platform/embedder/tests/embedder_unittests.cc b/shell/platform/embedder/tests/embedder_unittests.cc index 1998ebec4359f..f8b5d92d188a3 100644 --- a/shell/platform/embedder/tests/embedder_unittests.cc +++ b/shell/platform/embedder/tests/embedder_unittests.cc @@ -1105,7 +1105,7 @@ TEST_F(EmbedderTest, CanPostTaskToAllNativeThreads) { size_t ui_threads_count = 0; size_t worker_threads_count = 0; - Captures(size_t count) : latch(count) {} + explicit Captures(size_t count) : latch(count) {} }; Captures captures(engine_threads_count); diff --git a/shell/platform/fuchsia/flutter/vulkan_surface.cc b/shell/platform/fuchsia/flutter/vulkan_surface.cc index b7be38702a0e8..4b9a1e0c29839 100644 --- a/shell/platform/fuchsia/flutter/vulkan_surface.cc +++ b/shell/platform/fuchsia/flutter/vulkan_surface.cc @@ -86,7 +86,7 @@ bool VulkanSurface::CreateVulkanImage(vulkan::VulkanProvider& vulkan_provider, return false; } - out_vulkan_image->vk_image = { + out_vulkan_image->vk_image = vulkan::VulkanHandle{ vk_image, [&vulkan_provider = vulkan_provider](VkImage image) { vulkan_provider.vk().DestroyImage(vulkan_provider.vk_device(), image, NULL); @@ -290,11 +290,12 @@ bool VulkanSurface::AllocateDeviceMemory( return false; } - collection_ = {collection, [&vulkan_provider = vulkan_provider_]( - VkBufferCollectionFUCHSIAX collection) { - vulkan_provider.vk().DestroyBufferCollectionFUCHSIAX( - vulkan_provider.vk_device(), collection, nullptr); - }}; + collection_ = vulkan::VulkanHandle{ + collection, [&vulkan_provider = vulkan_provider_]( + VkBufferCollectionFUCHSIAX collection) { + vulkan_provider.vk().DestroyBufferCollectionFUCHSIAX( + vulkan_provider.vk_device(), collection, nullptr); + }}; VulkanImage vulkan_image; LOG_AND_RETURN(!CreateVulkanImage(vulkan_provider_, size, &vulkan_image), @@ -339,11 +340,12 @@ bool VulkanSurface::AllocateDeviceMemory( return false; } - vk_memory_ = {vk_memory, - [&vulkan_provider = vulkan_provider_](VkDeviceMemory memory) { - vulkan_provider.vk().FreeMemory(vulkan_provider.vk_device(), - memory, NULL); - }}; + vk_memory_ = vulkan::VulkanHandle{ + vk_memory, + [&vulkan_provider = vulkan_provider_](VkDeviceMemory memory) { + vulkan_provider.vk().FreeMemory(vulkan_provider.vk_device(), memory, + NULL); + }}; vk_memory_info_ = allocation_info; } diff --git a/shell/platform/linux/fl_accessible_node.cc b/shell/platform/linux/fl_accessible_node.cc index 8b0905adafc30..21cdb24de985a 100644 --- a/shell/platform/linux/fl_accessible_node.cc +++ b/shell/platform/linux/fl_accessible_node.cc @@ -112,8 +112,9 @@ static gboolean has_action(FlutterSemanticsAction actions, // Gets the nth action. static ActionData* get_action(FlAccessibleNode* self, gint index) { - if (index < 0 || static_cast(index) >= self->actions->len) + if (index < 0 || static_cast(index) >= self->actions->len) { return nullptr; + } return static_cast(g_ptr_array_index(self->actions, index)); } diff --git a/shell/platform/linux/fl_dart_project_test.cc b/shell/platform/linux/fl_dart_project_test.cc index 1c1f29892c069..4cd3b2ce82b66 100644 --- a/shell/platform/linux/fl_dart_project_test.cc +++ b/shell/platform/linux/fl_dart_project_test.cc @@ -47,11 +47,11 @@ TEST(FlDartProjectTest, DartEntrypointArgs) { EXPECT_EQ(g_strv_length(retrieved_args), 0U); GPtrArray* args_array = g_ptr_array_new(); - g_ptr_array_add(args_array, (gpointer) "arg_one"); - g_ptr_array_add(args_array, (gpointer) "arg_two"); - g_ptr_array_add(args_array, (gpointer) "arg_three"); + g_ptr_array_add(args_array, const_cast("arg_one")); + g_ptr_array_add(args_array, const_cast("arg_two")); + g_ptr_array_add(args_array, const_cast("arg_three")); g_ptr_array_add(args_array, nullptr); - gchar** args = (gchar**)g_ptr_array_free(args_array, false); + gchar** args = reinterpret_cast(g_ptr_array_free(args_array, false)); fl_dart_project_set_dart_entrypoint_arguments(project, args); diff --git a/shell/platform/linux/fl_engine.cc b/shell/platform/linux/fl_engine.cc index 187fb9e68a05a..8684feae285f3 100644 --- a/shell/platform/linux/fl_engine.cc +++ b/shell/platform/linux/fl_engine.cc @@ -520,8 +520,9 @@ gboolean fl_engine_start(FlEngine* self, GError** error) { fl_settings_plugin_start(self->settings_plugin); result = self->embedder_api.UpdateSemanticsEnabled(self->engine, TRUE); - if (result != kSuccess) + if (result != kSuccess) { g_warning("Failed to enable accessibility features on Flutter engine"); + } return TRUE; } diff --git a/shell/platform/linux/fl_engine_test.cc b/shell/platform/linux/fl_engine_test.cc index 082f936ee8fe7..d2f6d408ab34c 100644 --- a/shell/platform/linux/fl_engine_test.cc +++ b/shell/platform/linux/fl_engine_test.cc @@ -285,11 +285,11 @@ TEST(FlEngineTest, DartEntrypointArgs) { g_autoptr(FlDartProject) project = fl_dart_project_new(); GPtrArray* args_array = g_ptr_array_new(); - g_ptr_array_add(args_array, (gpointer) "arg_one"); - g_ptr_array_add(args_array, (gpointer) "arg_two"); - g_ptr_array_add(args_array, (gpointer) "arg_three"); + g_ptr_array_add(args_array, const_cast("arg_one")); + g_ptr_array_add(args_array, const_cast("arg_two")); + g_ptr_array_add(args_array, const_cast("arg_three")); g_ptr_array_add(args_array, nullptr); - gchar** args = (gchar**)g_ptr_array_free(args_array, false); + gchar** args = reinterpret_cast(g_ptr_array_free(args_array, false)); fl_dart_project_set_dart_entrypoint_arguments(project, args); diff --git a/shell/platform/linux/fl_gl_area.cc b/shell/platform/linux/fl_gl_area.cc index f746a1ef01c77..7804d66d88000 100644 --- a/shell/platform/linux/fl_gl_area.cc +++ b/shell/platform/linux/fl_gl_area.cc @@ -55,8 +55,9 @@ static void fl_gl_area_unrealize(GtkWidget* widget) { g_clear_object(&self->texture); /* Make sure to unset the context if current */ - if (self->context == gdk_gl_context_get_current()) + if (self->context == gdk_gl_context_get_current()) { gdk_gl_context_clear_current(); + } GTK_WIDGET_CLASS(fl_gl_area_parent_class)->unrealize(widget); } @@ -67,10 +68,11 @@ static void fl_gl_area_size_allocate(GtkWidget* widget, gtk_widget_set_allocation(widget, allocation); if (gtk_widget_get_has_window(widget)) { - if (gtk_widget_get_realized(widget)) + if (gtk_widget_get_realized(widget)) { gdk_window_move_resize(gtk_widget_get_window(widget), allocation->x, allocation->y, allocation->width, allocation->height); + } } } diff --git a/shell/platform/linux/fl_key_channel_responder_test.cc b/shell/platform/linux/fl_key_channel_responder_test.cc index c0fefe5effae0..75dcd17b4b3b9 100644 --- a/shell/platform/linux/fl_key_channel_responder_test.cc +++ b/shell/platform/linux/fl_key_channel_responder_test.cc @@ -39,7 +39,7 @@ static char* clone_string(const char* string) { } size_t len = strlen(string); char* result = g_new(char, len + 1); - strcpy(result, string); + strncpy(result, string, len + 1); return result; } diff --git a/shell/platform/linux/fl_key_embedder_responder.cc b/shell/platform/linux/fl_key_embedder_responder.cc index cdb46b73cbc35..d41a2e3509e76 100644 --- a/shell/platform/linux/fl_key_embedder_responder.cc +++ b/shell/platform/linux/fl_key_embedder_responder.cc @@ -306,7 +306,7 @@ static uint64_t event_to_logical_key(const FlKeyEvent* event) { } static uint64_t event_to_timestamp(const FlKeyEvent* event) { - return kMicrosecondsPerMillisecond * (double)event->time; + return kMicrosecondsPerMillisecond * static_cast(event->time); } // Returns a newly accocated UTF-8 string from event->keyval that must be @@ -316,8 +316,9 @@ static char* event_to_character(const FlKeyEvent* event) { glong items_written; gchar* result = g_ucs4_to_utf8(&unicodeChar, 1, NULL, &items_written, NULL); if (items_written == 0) { - if (result != NULL) + if (result != NULL) { g_free(result); + } return nullptr; } return result; diff --git a/shell/platform/linux/fl_key_embedder_responder_test.cc b/shell/platform/linux/fl_key_embedder_responder_test.cc index 0fae15d0a1275..398bd40d7e6ac 100644 --- a/shell/platform/linux/fl_key_embedder_responder_test.cc +++ b/shell/platform/linux/fl_key_embedder_responder_test.cc @@ -88,7 +88,7 @@ static FlKeyEmbedderCallRecord* fl_key_embedder_call_record_new( if (event->character != nullptr) { size_t character_length = strlen(event->character); char* clone_character = g_new(char, character_length + 1); - strcpy(clone_character, event->character); + strncpy(clone_character, event->character, character_length + 1); clone_event->character = clone_character; } self->event = clone_event; diff --git a/shell/platform/linux/fl_key_event.cc b/shell/platform/linux/fl_key_event.cc index b823a3377ae16..2e3c010457986 100644 --- a/shell/platform/linux/fl_key_event.cc +++ b/shell/platform/linux/fl_key_event.cc @@ -15,7 +15,7 @@ static char* clone_string(const char* source) { } size_t length = strlen(source); char* result = g_new(char, length + 1); - strcpy(result, source); + strncpy(result, source, length + 1); return result; } diff --git a/shell/platform/linux/fl_keyboard_manager.cc b/shell/platform/linux/fl_keyboard_manager.cc index 9926dd44caf63..703cb7227c51b 100644 --- a/shell/platform/linux/fl_keyboard_manager.cc +++ b/shell/platform/linux/fl_keyboard_manager.cc @@ -213,8 +213,9 @@ static void fl_keyboard_manager_init(FlKeyboardManager* self) {} static void fl_keyboard_manager_dispose(GObject* object) { FlKeyboardManager* self = FL_KEYBOARD_MANAGER(object); - if (self->text_input_plugin != nullptr) + if (self->text_input_plugin != nullptr) { g_clear_object(&self->text_input_plugin); + } g_ptr_array_free(self->responder_list, TRUE); g_ptr_array_set_free_func(self->pending_responds, g_object_unref); g_ptr_array_free(self->pending_responds, TRUE); @@ -234,8 +235,9 @@ gboolean g_ptr_array_find_with_equal_func1(GPtrArray* haystack, guint* index_) { guint i; g_return_val_if_fail(haystack != NULL, FALSE); - if (equal_func == NULL) + if (equal_func == NULL) { equal_func = g_direct_equal; + } for (i = 0; i < haystack->len; i++) { if (equal_func(g_ptr_array_index(haystack, i), needle)) { if (index_ != NULL) { diff --git a/shell/platform/linux/fl_renderer.cc b/shell/platform/linux/fl_renderer.cc index dde23f60d66f3..f32215dd38ecc 100644 --- a/shell/platform/linux/fl_renderer.cc +++ b/shell/platform/linux/fl_renderer.cc @@ -70,8 +70,9 @@ gboolean fl_renderer_start(FlRenderer* self, FlView* view, GError** error) { gdk_gl_context_realize(priv->resource_context, error); } - if (*error != nullptr) + if (*error != nullptr) { return FALSE; + } return TRUE; } diff --git a/shell/platform/linux/fl_renderer_gl.cc b/shell/platform/linux/fl_renderer_gl.cc index 52fbe44e6f041..ec44b9b2dc5b8 100644 --- a/shell/platform/linux/fl_renderer_gl.cc +++ b/shell/platform/linux/fl_renderer_gl.cc @@ -23,13 +23,15 @@ static gboolean fl_renderer_gl_create_contexts(FlRenderer* renderer, *visible = gdk_window_create_gl_context(window, error); - if (*error != nullptr) + if (*error != nullptr) { return FALSE; + } *resource = gdk_window_create_gl_context(window, error); - if (*error != nullptr) + if (*error != nullptr) { return FALSE; + } return TRUE; } @@ -93,8 +95,9 @@ static gboolean fl_renderer_gl_present_layers(FlRenderer* renderer, size_t layers_count) { FlView* view = fl_renderer_get_view(renderer); GdkGLContext* context = fl_renderer_get_context(renderer); - if (!view || !context) + if (!view || !context) { return FALSE; + } fl_view_begin_frame(view); for (size_t i = 0; i < layers_count; ++i) { diff --git a/shell/platform/linux/fl_settings_plugin.cc b/shell/platform/linux/fl_settings_plugin.cc index c7b31a466bd2d..1cf50112f8efa 100644 --- a/shell/platform/linux/fl_settings_plugin.cc +++ b/shell/platform/linux/fl_settings_plugin.cc @@ -42,8 +42,9 @@ G_DEFINE_TYPE(FlSettingsPlugin, fl_settings_plugin, G_TYPE_OBJECT) // See . static gdouble linearize_color_component(gdouble component) { - if (component <= 0.03928) + if (component <= 0.03928) { return component / 12.92; + } return pow((component + 0.055) / 1.055, 2.4); } @@ -61,8 +62,9 @@ static Brightness estimate_brightness_for_color(GdkRGBA* color) { // See and // . const gdouble kThreshold = 0.15; - if ((relative_luminance + 0.05) * (relative_luminance + 0.05) > kThreshold) + if ((relative_luminance + 0.05) * (relative_luminance + 0.05) > kThreshold) { return Brightness::Light; + } return Brightness::Dark; } @@ -70,8 +72,9 @@ static bool is_dark_theme() { // GTK doesn't have a specific flag for dark themes, so we check if the // style text color is light or dark GList* windows = gtk_window_list_toplevels(); - if (windows == nullptr) + if (windows == nullptr) { return false; + } GtkWidget* window = GTK_WIDGET(windows->data); g_list_free(windows); diff --git a/shell/platform/linux/fl_standard_message_codec_test.cc b/shell/platform/linux/fl_standard_message_codec_test.cc index a9b3d75f08789..b3b13a5a5c557 100644 --- a/shell/platform/linux/fl_standard_message_codec_test.cc +++ b/shell/platform/linux/fl_standard_message_codec_test.cc @@ -661,10 +661,11 @@ TEST(FlStandardMessageCodecTest, EncodeListNested) { g_autoptr(FlValue) even_numbers = fl_value_new_list(); g_autoptr(FlValue) odd_numbers = fl_value_new_list(); for (int i = 0; i < 10; i++) { - if (i % 2 == 0) + if (i % 2 == 0) { fl_value_append_take(even_numbers, fl_value_new_int(i)); - else + } else { fl_value_append_take(odd_numbers, fl_value_new_int(i)); + } } g_autoptr(FlValue) value = fl_value_new_list(); fl_value_append(value, even_numbers); @@ -758,8 +759,9 @@ TEST(FlStandardMessageCodecTest, EncodeDecodeLargeList) { g_autoptr(FlStandardMessageCodec) codec = fl_standard_message_codec_new(); g_autoptr(FlValue) value = fl_value_new_list(); - for (int i = 0; i < 65535; i++) + for (int i = 0; i < 65535; i++) { fl_value_append_take(value, fl_value_new_int(i)); + } g_autoptr(GError) error = nullptr; g_autoptr(GBytes) message = diff --git a/shell/platform/linux/fl_view.cc b/shell/platform/linux/fl_view.cc index dca1a21079d15..ca955d891fba3 100644 --- a/shell/platform/linux/fl_view.cc +++ b/shell/platform/linux/fl_view.cc @@ -375,8 +375,9 @@ static void fl_view_get_preferred_width(GtkWidget* widget, iterator = iterator->next) { FlViewChild* child = reinterpret_cast(iterator->data); - if (!gtk_widget_get_visible(child->widget)) + if (!gtk_widget_get_visible(child->widget)) { continue; + } gtk_widget_get_preferred_width(child->widget, &child_min, &child_nat); @@ -398,8 +399,9 @@ static void fl_view_get_preferred_height(GtkWidget* widget, iterator = iterator->next) { FlViewChild* child = reinterpret_cast(iterator->data); - if (!gtk_widget_get_visible(child->widget)) + if (!gtk_widget_get_visible(child->widget)) { continue; + } gtk_widget_get_preferred_height(child->widget, &child_min, &child_nat); @@ -416,17 +418,19 @@ static void fl_view_size_allocate(GtkWidget* widget, gtk_widget_set_allocation(widget, allocation); if (gtk_widget_get_has_window(widget)) { - if (gtk_widget_get_realized(widget)) + if (gtk_widget_get_realized(widget)) { gdk_window_move_resize(gtk_widget_get_window(widget), allocation->x, allocation->y, allocation->width, allocation->height); + } } for (GList* iterator = self->children_list; iterator; iterator = iterator->next) { FlViewChild* child = reinterpret_cast(iterator->data); - if (!gtk_widget_get_visible(child->widget)) + if (!gtk_widget_get_visible(child->widget)) { continue; + } GtkAllocation child_allocation = child->geometry; GtkRequisition child_requisition; @@ -758,10 +762,11 @@ static void fl_view_add_pending_child(FlView* self, GdkRectangle* geometry) { FlViewChild* child = g_new(FlViewChild, 1); child->widget = widget; - if (geometry) + if (geometry) { child->geometry = *geometry; - else + } else { child->geometry = {0, 0, 0, 0}; + } self->pending_children_list = g_list_append(self->pending_children_list, child); @@ -796,8 +801,9 @@ void fl_view_add_widget(FlView* view, GList* find_child(GList* list, GtkWidget* widget) { for (GList* i = list; i; i = i->next) { FlViewChild* child = reinterpret_cast(i->data); - if (child && child->widget == widget) + if (child && child->widget == widget) { return i; + } } return nullptr; } diff --git a/vulkan/vulkan_application.cc b/vulkan/vulkan_application.cc index 38560ac2ad08c..31dd54aaa1bf1 100644 --- a/vulkan/vulkan_application.cc +++ b/vulkan/vulkan_application.cc @@ -101,15 +101,16 @@ VulkanApplication::VulkanApplication( } // Now that we have an instance, set up instance proc table entries. - if (!vk.SetupInstanceProcAddresses(instance)) { + if (!vk.SetupInstanceProcAddresses(VulkanHandle(instance))) { FML_DLOG(INFO) << "Could not set up instance proc addresses."; return; } - instance_ = {instance, [this](VkInstance i) { - FML_DLOG(INFO) << "Destroying Vulkan instance"; - vk.DestroyInstance(i, nullptr); - }}; + instance_ = VulkanHandle{instance, [this](VkInstance i) { + FML_DLOG(INFO) + << "Destroying Vulkan instance"; + vk.DestroyInstance(i, nullptr); + }}; if (enable_instance_debugging) { auto debug_report = std::make_unique(vk, instance_); @@ -178,7 +179,8 @@ std::unique_ptr VulkanApplication::AcquireFirstCompatibleLogicalDevice() const { for (auto device_handle : GetPhysicalDevices()) { auto logical_device = std::make_unique( - vk, device_handle, enable_validation_layers_); + vk, VulkanHandle(device_handle), + enable_validation_layers_); if (logical_device->IsValid()) { return logical_device; } diff --git a/vulkan/vulkan_backbuffer.cc b/vulkan/vulkan_backbuffer.cc index d8be29e51d3db..b8b62aedbeb9f 100644 --- a/vulkan/vulkan_backbuffer.cc +++ b/vulkan/vulkan_backbuffer.cc @@ -65,7 +65,7 @@ bool VulkanBackbuffer::CreateSemaphores() { return false; } - semaphores_[i] = {semaphore, semaphore_collect}; + semaphores_[i] = VulkanHandle{semaphore, semaphore_collect}; } return true; @@ -90,7 +90,7 @@ bool VulkanBackbuffer::CreateFences() { return false; } - use_fences_[i] = {fence, fence_collect}; + use_fences_[i] = VulkanHandle{fence, fence_collect}; } return true; diff --git a/vulkan/vulkan_command_buffer.cc b/vulkan/vulkan_command_buffer.cc index c98a345fb3b75..8b767808b7ba0 100644 --- a/vulkan/vulkan_command_buffer.cc +++ b/vulkan/vulkan_command_buffer.cc @@ -33,7 +33,7 @@ VulkanCommandBuffer::VulkanCommandBuffer( vk.FreeCommandBuffers(device_, pool_, 1, &buffer); }; - handle_ = {buffer, buffer_collect}; + handle_ = VulkanHandle{buffer, buffer_collect}; valid_ = true; } diff --git a/vulkan/vulkan_debug_report.cc b/vulkan/vulkan_debug_report.cc index f086746229328..5994363f67abe 100644 --- a/vulkan/vulkan_debug_report.cc +++ b/vulkan/vulkan_debug_report.cc @@ -209,9 +209,10 @@ VulkanDebugReport::VulkanDebugReport( return; } - handle_ = {handle, [this](VkDebugReportCallbackEXT handle) { - vk.DestroyDebugReportCallbackEXT(application_, handle, nullptr); - }}; + handle_ = VulkanHandle{ + handle, [this](VkDebugReportCallbackEXT handle) { + vk.DestroyDebugReportCallbackEXT(application_, handle, nullptr); + }}; valid_ = true; } diff --git a/vulkan/vulkan_device.cc b/vulkan/vulkan_device.cc index 4684a62b3ef1f..67191a2810c9a 100644 --- a/vulkan/vulkan_device.cc +++ b/vulkan/vulkan_device.cc @@ -103,8 +103,8 @@ VulkanDevice::VulkanDevice(VulkanProcTable& p_vk, return; } - device_ = {device, - [this](VkDevice device) { vk.DestroyDevice(device, nullptr); }}; + device_ = VulkanHandle{ + device, [this](VkDevice device) { vk.DestroyDevice(device, nullptr); }}; if (!vk.SetupDeviceProcAddresses(device_)) { FML_DLOG(INFO) << "Could not set up device proc addresses."; @@ -120,7 +120,7 @@ VulkanDevice::VulkanDevice(VulkanProcTable& p_vk, return; } - queue_ = queue; + queue_ = VulkanHandle(queue); const VkCommandPoolCreateInfo command_pool_create_info = { .sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, @@ -137,9 +137,10 @@ VulkanDevice::VulkanDevice(VulkanProcTable& p_vk, return; } - command_pool_ = {command_pool, [this](VkCommandPool pool) { - vk.DestroyCommandPool(device_, pool, nullptr); - }}; + command_pool_ = VulkanHandle{ + command_pool, [this](VkCommandPool pool) { + vk.DestroyCommandPool(device_, pool, nullptr); + }}; valid_ = true; } diff --git a/vulkan/vulkan_handle.h b/vulkan/vulkan_handle.h index d011493d6f19c..eb53a063d9cf0 100644 --- a/vulkan/vulkan_handle.h +++ b/vulkan/vulkan_handle.h @@ -21,7 +21,7 @@ class VulkanHandle { VulkanHandle() : handle_(VK_NULL_HANDLE) {} - VulkanHandle(Handle handle, const Disposer& disposer = nullptr) + explicit VulkanHandle(Handle handle, const Disposer& disposer = nullptr) : handle_(handle), disposer_(disposer) {} VulkanHandle(VulkanHandle&& other) @@ -46,8 +46,9 @@ class VulkanHandle { return *this; } - operator bool() const { return handle_ != VK_NULL_HANDLE; } + explicit operator bool() const { return handle_ != VK_NULL_HANDLE; } + // NOLINTNEXTLINE(google-explicit-constructor) operator Handle() const { return handle_; } /// Relinquish responsibility of collecting the underlying handle when this diff --git a/vulkan/vulkan_image.h b/vulkan/vulkan_image.h index 9c401a640dcfb..cdab2faeaca06 100644 --- a/vulkan/vulkan_image.h +++ b/vulkan/vulkan_image.h @@ -16,7 +16,7 @@ class VulkanCommandBuffer; class VulkanImage { public: - VulkanImage(VulkanHandle image); + explicit VulkanImage(VulkanHandle image); ~VulkanImage(); diff --git a/vulkan/vulkan_proc_table.cc b/vulkan/vulkan_proc_table.cc index ceea6a9655b06..775da412c9887 100644 --- a/vulkan/vulkan_proc_table.cc +++ b/vulkan/vulkan_proc_table.cc @@ -99,7 +99,7 @@ bool VulkanProcTable::SetupInstanceProcAddresses( return true; }(); - instance_ = {handle, nullptr}; + instance_ = VulkanHandle{handle, nullptr}; return true; } @@ -147,7 +147,7 @@ bool VulkanProcTable::SetupDeviceProcAddresses( ACQUIRE_PROC(GetBufferCollectionPropertiesFUCHSIAX, handle); #endif // OS_FUCHSIA #endif // TEST_VULKAN_PROCS - device_ = {handle, nullptr}; + device_ = VulkanHandle{handle, nullptr}; return true; } @@ -193,13 +193,14 @@ GrVkGetProc VulkanProcTable::CreateSkiaGetProc() const { return [this](const char* proc_name, VkInstance instance, VkDevice device) { if (device != VK_NULL_HANDLE) { - auto result = AcquireProc(proc_name, {device, nullptr}); + auto result = + AcquireProc(proc_name, VulkanHandle{device, nullptr}); if (result != nullptr) { return result; } } - return AcquireProc(proc_name, {instance, nullptr}); + return AcquireProc(proc_name, VulkanHandle{instance, nullptr}); }; } diff --git a/vulkan/vulkan_proc_table.h b/vulkan/vulkan_proc_table.h index 1b81f74b22bb0..7ecc348d366ee 100644 --- a/vulkan/vulkan_proc_table.h +++ b/vulkan/vulkan_proc_table.h @@ -26,7 +26,7 @@ class VulkanProcTable : public fml::RefCountedThreadSafe { public: using Proto = T; - Proc(T proc = nullptr) : proc_(proc) {} + explicit Proc(T proc = nullptr) : proc_(proc) {} ~Proc() { proc_ = nullptr; } @@ -40,9 +40,9 @@ class VulkanProcTable : public fml::RefCountedThreadSafe { return *this; } - operator bool() const { return proc_ != nullptr; } + explicit operator bool() const { return proc_ != nullptr; } - operator T() const { return proc_; } + operator T() const { return proc_; } // NOLINT(google-explicit-constructor) private: T proc_; @@ -136,7 +136,7 @@ class VulkanProcTable : public fml::RefCountedThreadSafe { VulkanHandle device_; VulkanProcTable(); - VulkanProcTable(const char* path); + explicit VulkanProcTable(const char* path); ~VulkanProcTable(); bool OpenLibraryHandle(const char* path); bool SetupLoaderProcAddresses(); diff --git a/vulkan/vulkan_provider.h b/vulkan/vulkan_provider.h index 6dd8ff109d675..e32e99b917446 100644 --- a/vulkan/vulkan_provider.h +++ b/vulkan/vulkan_provider.h @@ -25,9 +25,10 @@ class VulkanProvider { &fence)) != VK_SUCCESS) return vulkan::VulkanHandle(); - return {fence, [this](VkFence fence) { - vk().DestroyFence(vk_device(), fence, nullptr); - }}; + return VulkanHandle{fence, [this](VkFence fence) { + vk().DestroyFence(vk_device(), fence, + nullptr); + }}; } }; diff --git a/vulkan/vulkan_surface.cc b/vulkan/vulkan_surface.cc index f410d43f81719..31e460344c070 100644 --- a/vulkan/vulkan_surface.cc +++ b/vulkan/vulkan_surface.cc @@ -30,10 +30,10 @@ VulkanSurface::VulkanSurface( return; } - surface_ = {surface, [this](VkSurfaceKHR surface) { - vk.DestroySurfaceKHR(application_.GetInstance(), surface, - nullptr); - }}; + surface_ = VulkanHandle{ + surface, [this](VkSurfaceKHR surface) { + vk.DestroySurfaceKHR(application_.GetInstance(), surface, nullptr); + }}; valid_ = true; }