Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit b2a4e74

Browse files
committed
Check more optional accesses
1 parent 6d1ed1a commit b2a4e74

File tree

6 files changed

+27
-54
lines changed

6 files changed

+27
-54
lines changed

flow/layers/layer_raster_cache_item.cc

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@
77
#include "flutter/flow/raster_cache_item.h"
88
#include "flutter/flow/raster_cache_util.h"
99

10-
// TODO(zanderso): https://github.com/flutter/flutter/issues/127701
11-
// NOLINTBEGIN(bugprone-unchecked-optional-access)
12-
1310
namespace flutter {
1411

1512
LayerRasterCacheItem::LayerRasterCacheItem(Layer* layer,
@@ -143,7 +140,8 @@ static const auto* flow_type = "RasterCacheFlow::Layer";
143140

144141
bool LayerRasterCacheItem::TryToPrepareRasterCache(const PaintContext& context,
145142
bool parent_cached) const {
146-
if (!context.raster_cache || parent_cached) {
143+
auto maybe_id = GetId();
144+
if (!maybe_id.has_value() || !context.raster_cache || parent_cached) {
147145
return false;
148146
}
149147
if (cache_state_ != kNone) {
@@ -157,8 +155,9 @@ bool LayerRasterCacheItem::TryToPrepareRasterCache(const PaintContext& context,
157155
.flow_type = flow_type,
158156
// clang-format on
159157
};
158+
auto id = maybe_id.value();
160159
return context.raster_cache->UpdateCacheEntry(
161-
GetId().value(), r_context,
160+
id, r_context,
162161
[ctx = context, cache_state = cache_state_,
163162
layer = layer_](DlCanvas* canvas) {
164163
Rasterize(cache_state, layer, ctx, canvas);
@@ -176,7 +175,7 @@ bool LayerRasterCacheItem::Draw(const PaintContext& context,
176175
bool LayerRasterCacheItem::Draw(const PaintContext& context,
177176
DlCanvas* canvas,
178177
const DlPaint* paint) const {
179-
if (!context.raster_cache || !canvas) {
178+
if (!layer_children_id_.has_value() || !context.raster_cache || !canvas) {
180179
return false;
181180
}
182181
switch (cache_state_) {
@@ -193,5 +192,3 @@ bool LayerRasterCacheItem::Draw(const PaintContext& context,
193192
}
194193

195194
} // namespace flutter
196-
197-
// NOLINTEND(bugprone-unchecked-optional-access)

impeller/display_list/skia_conversions.cc

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44

55
#include "impeller/display_list/skia_conversions.h"
66

7-
// TODO(zanderso): https://github.com/flutter/flutter/issues/127701
8-
// NOLINTBEGIN(bugprone-unchecked-optional-access)
9-
107
namespace impeller {
118
namespace skia_conversions {
129

@@ -24,7 +21,7 @@ std::optional<Rect> ToRect(const SkRect* rect) {
2421
std::vector<Rect> ToRects(const SkRect tex[], int count) {
2522
auto result = std::vector<Rect>();
2623
for (int i = 0; i < count; i++) {
27-
result.push_back(ToRect(&tex[i]).value());
24+
result.push_back(ToRect(tex[i]));
2825
}
2926
return result;
3027
}
@@ -180,5 +177,3 @@ std::optional<impeller::PixelFormat> ToPixelFormat(SkColorType type) {
180177

181178
} // namespace skia_conversions
182179
} // namespace impeller
183-
184-
// NOLINTEND(bugprone-unchecked-optional-access)

impeller/entity/contents/content_context.cc

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@
1616
#include "impeller/renderer/render_target.h"
1717
#include "impeller/tessellator/tessellator.h"
1818

19-
// TODO(zanderso): https://github.com/flutter/flutter/issues/127701
20-
// NOLINTBEGIN(bugprone-unchecked-optional-access)
21-
2219
namespace impeller {
2320

2421
void ContentContextOptions::ApplyToPipelineDescriptor(
@@ -33,13 +30,7 @@ void ContentContextOptions::ApplyToPipelineDescriptor(
3330
desc.SetSampleCount(sample_count);
3431

3532
ColorAttachmentDescriptor color0 = *desc.GetColorAttachmentDescriptor(0u);
36-
if (!color_attachment_pixel_format.has_value()) {
37-
VALIDATION_LOG << "Color attachment pixel format must be set.";
38-
color0.format = PixelFormat::kB8G8R8A8UNormInt;
39-
} else {
40-
color0.format = *color_attachment_pixel_format;
41-
}
42-
color0.format = *color_attachment_pixel_format;
33+
color0.format = color_attachment_pixel_format.value_or(PixelFormat::kUnknown);
4334
color0.alpha_blend_op = BlendOperation::kAdd;
4435
color0.color_blend_op = BlendOperation::kAdd;
4536

@@ -137,9 +128,9 @@ void ContentContextOptions::ApplyToPipelineDescriptor(
137128
desc.ClearStencilAttachments();
138129
}
139130

140-
if (desc.GetFrontStencilAttachmentDescriptor().has_value()) {
141-
StencilAttachmentDescriptor stencil =
142-
desc.GetFrontStencilAttachmentDescriptor().value();
131+
auto maybe_stencil = desc.GetFrontStencilAttachmentDescriptor();
132+
if (maybe_stencil.has_value()) {
133+
StencilAttachmentDescriptor stencil = maybe_stencil.value();
143134
stencil.stencil_compare = stencil_compare;
144135
stencil.depth_stencil_pass = stencil_operation;
145136
desc.SetStencilAttachmentDescriptors(stencil);
@@ -312,9 +303,9 @@ ContentContext::ContentContext(std::shared_ptr<Context> context)
312303
context_->GetPipelineLibrary()->GetPipeline(uv_pipeline_desc).Get();
313304
}
314305

315-
if (solid_fill_pipelines_[{}]->GetDescriptor().has_value()) {
316-
auto clip_pipeline_descriptor =
317-
solid_fill_pipelines_[{}]->GetDescriptor().value();
306+
auto maybe_pipeline_desc = solid_fill_pipelines_[{}]->GetDescriptor();
307+
if (maybe_pipeline_desc.has_value()) {
308+
auto clip_pipeline_descriptor = maybe_pipeline_desc.value();
318309
clip_pipeline_descriptor.SetLabel("Clip Pipeline");
319310
// Disable write to all color attachments.
320311
auto color_attachments =
@@ -412,5 +403,3 @@ void ContentContext::SetWireframe(bool wireframe) {
412403
}
413404

414405
} // namespace impeller
415-
416-
// NOLINTEND(bugprone-unchecked-optional-access)

impeller/entity/contents/filters/filter_contents.cc

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,6 @@
2828
#include "impeller/renderer/command_buffer.h"
2929
#include "impeller/renderer/render_pass.h"
3030

31-
// TODO(zanderso): https://github.com/flutter/flutter/issues/127701
32-
// NOLINTBEGIN(bugprone-unchecked-optional-access)
33-
3431
namespace impeller {
3532

3633
std::shared_ptr<FilterContents> FilterContents::MakeDirectionalGaussianBlur(
@@ -180,8 +177,9 @@ bool FilterContents::Render(const ContentContext& renderer,
180177
std::optional<Rect> FilterContents::GetLocalCoverage(
181178
const Entity& local_entity) const {
182179
auto coverage = GetFilterCoverage(inputs_, local_entity, effect_transform_);
183-
if (GetCoverageHint().has_value() && coverage.has_value()) {
184-
coverage = coverage->Intersection(*GetCoverageHint());
180+
auto coverage_hint = GetCoverageHint();
181+
if (coverage_hint.has_value() && coverage.has_value()) {
182+
coverage = coverage->Intersection(coverage_hint.value());
185183
}
186184

187185
return coverage;
@@ -272,5 +270,3 @@ Matrix FilterContents::GetTransform(const Matrix& parent_transform) const {
272270
}
273271

274272
} // namespace impeller
275-
276-
// NOLINTEND(bugprone-unchecked-optional-access)

impeller/entity/entity_pass.cc

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,6 @@
3434
#include "impeller/entity/contents/checkerboard_contents.h"
3535
#endif // IMPELLER_DEBUG
3636

37-
// TODO(zanderso): https://github.com/flutter/flutter/issues/127701
38-
// NOLINTBEGIN(bugprone-unchecked-optional-access)
39-
4037
namespace impeller {
4138

4239
EntityPass::EntityPass() = default;
@@ -317,8 +314,9 @@ bool EntityPass::Render(ContentContext& renderer,
317314

318315
// If a root stencil was provided by the caller, then verify that it has a
319316
// configuration which can be used to render this pass.
320-
if (root_render_target.GetStencilAttachment().has_value()) {
321-
auto stencil_texture = root_render_target.GetStencilAttachment()->texture;
317+
auto stencil_attachment = root_render_target.GetStencilAttachment();
318+
if (stencil_attachment.has_value()) {
319+
auto stencil_texture = stencil_attachment->texture;
322320
if (!stencil_texture) {
323321
VALIDATION_LOG << "The root RenderTarget must have a stencil texture.";
324322
return false;
@@ -437,20 +435,23 @@ EntityPass::EntityResult EntityPass::GetEntityForElement(
437435
pass_context.EndPass();
438436
}
439437

440-
if (stencil_coverage_stack.empty() ||
441-
!stencil_coverage_stack.back().coverage.has_value()) {
438+
if (stencil_coverage_stack.empty()) {
442439
// The current clip is empty. This means the pass texture won't be
443440
// visible, so skip it.
444441
return EntityPass::EntityResult::Skip();
445442
}
443+
auto stencil_coverage_back = stencil_coverage_stack.back().coverage;
444+
if (!stencil_coverage_back.has_value()) {
445+
return EntityPass::EntityResult::Skip();
446+
}
446447

447448
// The maximum coverage of the subpass. Subpasses textures should never
448449
// extend outside the parent pass texture or the current clip coverage.
449450
auto coverage_limit =
450451
Rect(global_pass_position, Size(pass_context.GetPassTarget()
451452
.GetRenderTarget()
452453
.GetRenderTargetSize()))
453-
.Intersection(*stencil_coverage_stack.back().coverage);
454+
.Intersection(stencil_coverage_back.value());
454455
if (!coverage_limit.has_value()) {
455456
return EntityPass::EntityResult::Skip();
456457
}
@@ -913,5 +914,3 @@ void EntityPass::SetEnableOffscreenCheckerboard(bool enabled) {
913914
}
914915

915916
} // namespace impeller
916-
917-
// NOLINTEND(bugprone-unchecked-optional-access)

shell/common/shell.cc

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,6 @@
4141
#include "third_party/skia/include/utils/SkBase64.h"
4242
#include "third_party/tonic/common/log.h"
4343

44-
// TODO(zanderso): https://github.com/flutter/flutter/issues/127701
45-
// NOLINTBEGIN(bugprone-unchecked-optional-access)
46-
4744
namespace flutter {
4845

4946
constexpr char kSkiaChannel[] = "flutter/skia";
@@ -1556,6 +1553,8 @@ fml::TimePoint Shell::GetLatestFrameTargetTime() const {
15561553
std::scoped_lock time_recorder_lock(time_recorder_mutex_);
15571554
FML_CHECK(latest_frame_target_time_.has_value())
15581555
<< "GetLatestFrameTargetTime called before OnAnimatorBeginFrame";
1556+
// Covered by FML_CHECK().
1557+
// NOLINTNEXTLINE(bugprone-unchecked-optional-access)
15591558
return latest_frame_target_time_.value();
15601559
}
15611560

@@ -2147,5 +2146,3 @@ Shell::GetConcurrentWorkerTaskRunner() const {
21472146
}
21482147

21492148
} // namespace flutter
2150-
2151-
// NOLINTEND(bugprone-unchecked-optional-access)

0 commit comments

Comments
 (0)