1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
|
// Copyright 2021 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef COMPONENTS_VIZ_SERVICE_DISPLAY_DISPLAY_RESOURCE_PROVIDER_SOFTWARE_H_
#define COMPONENTS_VIZ_SERVICE_DISPLAY_DISPLAY_RESOURCE_PROVIDER_SOFTWARE_H_
#include <memory>
#include <utility>
#include <vector>
#include "base/memory/raw_ptr.h"
#include "components/viz/service/display/display_resource_provider.h"
#include "components/viz/service/viz_service_export.h"
#include "gpu/command_buffer/service/blocking_sequence_runner.h"
#include "gpu/command_buffer/service/memory_tracking.h"
#include "gpu/command_buffer/service/shared_image/shared_image_representation.h"
#include "third_party/skia/include/core/SkBitmap.h"
namespace gpu {
class SharedImageManager;
class Scheduler;
}
namespace viz {
// DisplayResourceProvider implementation used with SoftwareRenderer.
class VIZ_SERVICE_EXPORT DisplayResourceProviderSoftware
: public DisplayResourceProvider {
public:
explicit DisplayResourceProviderSoftware(
gpu::SharedImageManager* shared_image_manager,
gpu::Scheduler* scheduler);
~DisplayResourceProviderSoftware() override;
class VIZ_SERVICE_EXPORT ScopedReadLockSkImage {
public:
ScopedReadLockSkImage(DisplayResourceProviderSoftware* resource_provider,
ResourceId resource_id);
~ScopedReadLockSkImage();
ScopedReadLockSkImage(const ScopedReadLockSkImage&) = delete;
ScopedReadLockSkImage& operator=(const ScopedReadLockSkImage& other) =
delete;
const SkImage* sk_image() const { return sk_image_.get(); }
sk_sp<SkImage> TakeSkImage() { return std::move(sk_image_); }
bool valid() const { return !!sk_image_; }
private:
const raw_ptr<DisplayResourceProviderSoftware> resource_provider_;
const ResourceId resource_id_;
sk_sp<SkImage> sk_image_;
};
// Waits on the SyncToken and returns MemoryImageRepresentation of the
// SharedImage pointed by mailbox.
std::unique_ptr<gpu::MemoryImageRepresentation> GetSharedImageRepresentation(
const gpu::Mailbox& mailbox,
const gpu::SyncToken& sync_token);
private:
// These functions are used by ScopedReadLockSkImage to lock and unlock
// resources.
const ChildResource* LockForRead(ResourceId id);
void UnlockForRead(ResourceId id, const SkImage* sk_image);
// DisplayResourceProvider overrides:
std::vector<ReturnedResource> DeleteAndReturnUnusedResourcesToChildImpl(
Child& child_info,
DeleteStyle style,
const std::vector<ResourceId>& unused) override;
void WaitSyncToken(gpu::SyncToken sync_token);
const raw_ptr<gpu::SharedImageManager> shared_image_manager_;
const raw_ptr<gpu::Scheduler> gpu_scheduler_;
std::unique_ptr<gpu::BlockingSequenceRunner> blocking_sequence_runner_;
base::flat_map<ResourceId, sk_sp<SkImage>> resource_sk_images_;
std::unique_ptr<gpu::MemoryTypeTracker> memory_tracker_;
struct SharedImageAccess {
SharedImageAccess();
~SharedImageAccess();
SharedImageAccess(SharedImageAccess&& other);
SharedImageAccess& operator=(SharedImageAccess&& other);
SharedImageAccess(const SharedImageAccess&) = delete;
SharedImageAccess& operator=(const SharedImageAccess&) = delete;
std::unique_ptr<gpu::MemoryImageRepresentation> representation;
std::unique_ptr<gpu::MemoryImageRepresentation::ScopedReadAccess>
read_access;
};
base::flat_map<ResourceId, std::unique_ptr<SharedImageAccess>>
resource_shared_images_;
};
} // namespace viz
#endif // COMPONENTS_VIZ_SERVICE_DISPLAY_DISPLAY_RESOURCE_PROVIDER_SOFTWARE_H_
|