Fixed constness of display list storage. (flutter/engine#52705)

Previously you could have a const DisplayListStorage and still have
access to editing it. This fixes that.

testing: refactor only

## Pre-launch Checklist

- [x] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [x] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [x] I read and followed the [Flutter Style Guide] and the [C++,
Objective-C, Java style guides].
- [x] I listed at least one issue that this PR fixes in the description
above.
- [x] I added new tests to check the change I am making or feature I am
adding, or the PR is [test-exempt]. See [testing the engine] for
instructions on writing and running engine tests.
- [x] I updated/added relevant documentation (doc comments with `///`).
- [x] I signed the [CLA].
- [x] All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel
on [Discord].

<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/wiki/Tree-hygiene#overview
[Tree Hygiene]: https://github.com/flutter/flutter/wiki/Tree-hygiene
[test-exempt]:
https://github.com/flutter/flutter/wiki/Tree-hygiene#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo
[C++, Objective-C, Java style guides]:
https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
[testing the engine]:
https://github.com/flutter/flutter/wiki/Testing-the-engine
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/wiki/Tree-hygiene#handling-breaking-changes
[Discord]: https://github.com/flutter/flutter/wiki/Chat
This commit is contained in:
gaaclarke
2024-05-10 09:10:33 -07:00
committed by GitHub
parent 9d6bf0d3b0
commit 2d6f998e85
2 changed files with 22 additions and 18 deletions

View File

@@ -51,7 +51,7 @@ DisplayList::DisplayList(DisplayListStorage&& storage,
rtree_(std::move(rtree)) {}
DisplayList::~DisplayList() {
uint8_t* ptr = storage_.get();
const uint8_t* ptr = storage_.get();
DisposeOps(ptr, ptr + byte_count_);
}
@@ -142,7 +142,7 @@ class VectorCuller final : public Culler {
};
void DisplayList::Dispatch(DlOpReceiver& receiver) const {
uint8_t* ptr = storage_.get();
const uint8_t* ptr = storage_.get();
Dispatch(receiver, ptr, ptr + byte_count_, NopCuller::instance);
}
@@ -162,7 +162,7 @@ void DisplayList::Dispatch(DlOpReceiver& receiver,
}
const DlRTree* rtree = this->rtree().get();
FML_DCHECK(rtree != nullptr);
uint8_t* ptr = storage_.get();
const uint8_t* ptr = storage_.get();
std::vector<int> rect_indices;
rtree->search(cull_rect, &rect_indices);
VectorCuller culler(rtree, rect_indices);
@@ -170,8 +170,8 @@ void DisplayList::Dispatch(DlOpReceiver& receiver,
}
void DisplayList::Dispatch(DlOpReceiver& receiver,
uint8_t* ptr,
uint8_t* end,
const uint8_t* ptr,
const uint8_t* end,
Culler& culler) const {
DispatchContext context = {
.receiver = receiver,
@@ -207,7 +207,7 @@ void DisplayList::Dispatch(DlOpReceiver& receiver,
}
}
void DisplayList::DisposeOps(uint8_t* ptr, uint8_t* end) {
void DisplayList::DisposeOps(const uint8_t* ptr, const uint8_t* end) {
while (ptr < end) {
auto op = reinterpret_cast<const DLOp*>(ptr);
ptr += op->size;
@@ -234,15 +234,15 @@ void DisplayList::DisposeOps(uint8_t* ptr, uint8_t* end) {
}
}
static bool CompareOps(uint8_t* ptrA,
uint8_t* endA,
uint8_t* ptrB,
uint8_t* endB) {
static bool CompareOps(const uint8_t* ptrA,
const uint8_t* endA,
const uint8_t* ptrB,
const uint8_t* endB) {
// These conditions are checked by the caller...
FML_DCHECK((endA - ptrA) == (endB - ptrB));
FML_DCHECK(ptrA != ptrB);
uint8_t* bulk_start_a = ptrA;
uint8_t* bulk_start_b = ptrB;
const uint8_t* bulk_start_a = ptrA;
const uint8_t* bulk_start_b = ptrB;
while (ptrA < endA && ptrB < endB) {
auto opA = reinterpret_cast<const DLOp*>(ptrA);
auto opB = reinterpret_cast<const DLOp*>(ptrB);
@@ -310,8 +310,8 @@ bool DisplayList::Equals(const DisplayList* other) const {
if (byte_count_ != other->byte_count_ || op_count_ != other->op_count_) {
return false;
}
uint8_t* ptr = storage_.get();
uint8_t* o_ptr = other->storage_.get();
const uint8_t* ptr = storage_.get();
const uint8_t* o_ptr = other->storage_.get();
if (ptr == o_ptr) {
return true;
}

View File

@@ -237,7 +237,9 @@ class DisplayListStorage {
DisplayListStorage() = default;
DisplayListStorage(DisplayListStorage&&) = default;
uint8_t* get() const { return ptr_.get(); }
uint8_t* get() { return ptr_.get(); }
const uint8_t* get() const { return ptr_.get(); }
void realloc(size_t count) {
ptr_.reset(static_cast<uint8_t*>(std::realloc(ptr_.release(), count)));
@@ -309,6 +311,8 @@ class DisplayList : public SkRefCnt {
return modifies_transparent_black_;
}
const DisplayListStorage& GetStorage() const { return storage_; }
private:
DisplayList(DisplayListStorage&& ptr,
size_t byte_count,
@@ -324,7 +328,7 @@ class DisplayList : public SkRefCnt {
static uint32_t next_unique_id();
static void DisposeOps(uint8_t* ptr, uint8_t* end);
static void DisposeOps(const uint8_t* ptr, const uint8_t* end);
const DisplayListStorage storage_;
const size_t byte_count_;
@@ -345,8 +349,8 @@ class DisplayList : public SkRefCnt {
const sk_sp<const DlRTree> rtree_;
void Dispatch(DlOpReceiver& ctx,
uint8_t* ptr,
uint8_t* end,
const uint8_t* ptr,
const uint8_t* end,
Culler& culler) const;
friend class DisplayListBuilder;