blob: db5ccf404594a38c5cede7ce3e683180e73a7be8 [file] [log] [blame]
// Copyright 2017 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.
#include <unordered_map>
#include <vector>
#include "cc/cc_export.h"
#include "cc/paint/image_id.h"
#include "cc/tiles/image_controller.h"
#include "third_party/skia/include/core/SkImage.h"
namespace cc {
class CC_EXPORT CheckerImageTrackerClient {
virtual ~CheckerImageTrackerClient() = default;
virtual void NeedsInvalidationForCheckerImagedTiles() = 0;
// CheckerImageTracker is used to track the set of images in a frame which are
// decoded asynchronously, using the ImageDecodeService, from the rasterization
// of tiles which depend on them. Once decoded, these images are stored for
// invalidation on the next sync tree. TakeImagesToInvalidateOnSyncTree will
// return this set and maintain a copy to keeps these images locked until the
// sync tree is activated.
// Note: It is illegal to call TakeImagesToInvalidateOnSyncTree for the next
// sync tree until the previous tree is activated.
class CC_EXPORT CheckerImageTracker {
CheckerImageTracker(ImageController* image_controller,
CheckerImageTrackerClient* client,
bool enable_checker_imaging);
// Returns true if the decode for |image| will be deferred to the image decode
// service and it should be be skipped during raster.
bool ShouldCheckerImage(const sk_sp<const SkImage>& image, WhichTree tree);
using ImageDecodeQueue = std::vector<sk_sp<const SkImage>>;
void ScheduleImageDecodeQueue(ImageDecodeQueue image_decode_queue);
// Returns the set of images to invalidate on the sync tree.
const ImageIdFlatSet& TakeImagesToInvalidateOnSyncTree();
void DidActivateSyncTree();
enum class DecodePolicy {
// The image can be decoded asynchronously from raster. When set, the image
// is always skipped during rasterization of content that includes this
// image until it has been decoded using the decode service.
// The image has been decoded asynchronously once and should now be
// synchronously rasterized with the content.
// The image has been permanently vetoed from being decoded async.
void DidFinishImageDecode(ImageId image_id,
ImageController::ImageDecodeRequestId request_id,
ImageController::ImageDecodeResult result);
// Called when the next request in the |image_decode_queue_| should be
// scheduled with the image decode service.
void ScheduleNextImageDecode();
ImageController* image_controller_;
CheckerImageTrackerClient* client_;
const bool enable_checker_imaging_;
// A set of images which have been decoded and are pending invalidation for
// raster on the checkered tiles.
ImageIdFlatSet images_pending_invalidation_;
// A set of images which were invalidated on the current sync tree.
ImageIdFlatSet invalidated_images_on_current_sync_tree_;
// The queue of images pending decode. We maintain a queue to ensure that the
// order in which images are decoded is aligned with the priority of the tiles
// dependent on these images.
ImageDecodeQueue image_decode_queue_;
// The currently outstanding image decode that has been scheduled with the
// decode service. There can be only one outstanding decode at a time.
sk_sp<const SkImage> outstanding_image_decode_;
// A map of ImageId to its DecodePolicy.
// TODO(khushalsagar): Limit the size of this set.
// TODO(khushalsagar): Plumb navigation changes here to reset this. See
std::unordered_map<ImageId, DecodePolicy> image_async_decode_state_;
// A map of image id to image decode request id for images to be unlocked.
std::unordered_map<ImageId, ImageController::ImageDecodeRequestId>
base::WeakPtrFactory<CheckerImageTracker> weak_factory_;
} // namespace cc