mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
After an application is suspended and the GrContext associated with the Flutter view is destroyed, the raster cache still contains images tied to the defunct context. The SkyShell process will crash if these images are used after the application resumes.
50 lines
1.0 KiB
C++
50 lines
1.0 KiB
C++
// Copyright 2016 The Chromium 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 FLOW_RASTER_CACHE_H_
|
|
#define FLOW_RASTER_CACHE_H_
|
|
|
|
#include <memory>
|
|
#include <unordered_map>
|
|
|
|
#include "base/macros.h"
|
|
#include "skia/ext/refptr.h"
|
|
#include "third_party/skia/include/core/SkSize.h"
|
|
#include "third_party/skia/include/core/SkImage.h"
|
|
#include "flow/instrumentation.h"
|
|
|
|
namespace flow {
|
|
|
|
class RasterCache {
|
|
public:
|
|
RasterCache();
|
|
~RasterCache();
|
|
|
|
skia::RefPtr<SkImage> GetPrerolledImage(
|
|
GrContext* context, SkPicture* picture, const SkMatrix& ctm);
|
|
void SweepAfterFrame();
|
|
|
|
void Clear();
|
|
|
|
private:
|
|
struct Entry {
|
|
Entry();
|
|
~Entry();
|
|
|
|
bool used_this_frame = false;
|
|
int access_count = 0;
|
|
SkISize physical_size;
|
|
skia::RefPtr<SkImage> image;
|
|
};
|
|
|
|
using Cache = std::unordered_map<uint32_t, Entry>;
|
|
Cache cache_;
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(RasterCache);
|
|
};
|
|
|
|
} // namespace flow
|
|
|
|
#endif // FLOW_RASTER_CACHE_H_
|