Commit 1f5d22ca authored by Peng Huang's avatar Peng Huang Committed by Commit Bot

cc::DisplayResourceProivder: Add method GetResourceMetadataForExternalUse

This method will be used by viz::SkiaRenderer to get a resource
metadata, and then the viz::SkiaRenderer will make a SkImage by
SkDeferredDisplayListRecorder::makePromiseTexture(), and then draw the
SkImage to a Skia DDL which will be played back on GPU thread later.

This CL is part of CL https://crrev.com/c/947047 which makes
SkiaRenderer use Skia DDL to render frames.

Bug: 824382
Cq-Include-Trybots: luci.chromium.try:android_optional_gpu_tests_rel;master.tryserver.blink:linux_trusty_blink_rel
Change-Id: Ie182ee9f8ebba0f6f838e6fb191f84b97ee43545
Reviewed-on: https://chromium-review.googlesource.com/973806Reviewed-by: default avatarRobert Kroeger <rjkroege@chromium.org>
Reviewed-by: default avatardanakj <danakj@chromium.org>
Commit-Queue: Peng Huang <penghuang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#545145}
parent 399c2369
......@@ -496,6 +496,48 @@ bool DisplayResourceProvider::InUse(viz::ResourceId id) {
return resource->lock_for_read_count > 0 || resource->lost;
}
viz::ResourceMetadata
DisplayResourceProvider::GetResourceMetadataForExternalUse(
viz::ResourceId id,
const gpu::SyncToken& release_sync_token) {
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
ResourceMap::iterator it = resources_.find(id);
DCHECK(it != resources_.end());
viz::internal::Resource* resource = &it->second;
viz::ResourceMetadata metadata;
// TODO(xing.xu): remove locked_for_write.
DCHECK(!resource->locked_for_write)
<< "locked for write: " << resource->locked_for_write;
DCHECK_EQ(resource->exported_count, 0);
// Uninitialized! Call SetPixels or LockForWrite first.
DCHECK(resource->allocated);
// TODO(penghuang): support software resource.
DCHECK(resource->is_gpu_resource_type());
metadata.mailbox = resource->mailbox;
metadata.backend_format = GrBackendFormat::MakeGL(
TextureStorageFormat(resource->format), resource->target);
metadata.size = resource->size;
metadata.mip_mapped = GrMipMapped::kNo;
metadata.origin = kTopLeft_GrSurfaceOrigin;
metadata.color_type = ResourceFormatToClosestSkColorType(resource->format);
metadata.alpha_type = kPremul_SkAlphaType;
metadata.color_space = nullptr;
metadata.sync_token = resource->sync_token();
// Update the resource sync token to |release_sync_token|. When the next frame
// is being composited, the DeclareUsedResourcesFromChild() will be called
// with resources belong to every child for the next frame. If the resource
// is not used by the next frame, the resource will be returned to a child
// which owns it with the |release_sync_token|. The child is responsible for
// issuing a WaitSyncToken GL command with the |release_sync_token| before
// reusing it.
resource->UpdateSyncToken(release_sync_token);
return metadata;
}
DisplayResourceProvider::ScopedReadLockGL::ScopedReadLockGL(
DisplayResourceProvider* resource_provider,
viz::ResourceId resource_id)
......
......@@ -9,6 +9,7 @@
#include "cc/output/overlay_candidate.h"
#include "cc/resources/resource_provider.h"
#include "components/viz/common/resources/resource_fence.h"
#include "components/viz/common/resources/resource_metadata.h"
namespace viz {
class SharedBitmapManager;
......@@ -56,6 +57,14 @@ class CC_EXPORT DisplayResourceProvider : public ResourceProvider {
// Checks whether a resource is in use.
bool InUse(viz::ResourceId id);
// Get the resource metadata for external use.
// The |release_sync_token| should be one that can be waited on in a command
// buffer to ensure that any external use of it is completed, before reusing
// the resource's backing.
viz::ResourceMetadata GetResourceMetadataForExternalUse(
viz::ResourceId id,
const gpu::SyncToken& release_sync_token);
// The following lock classes are part of the DisplayResourceProvider API and
// are needed to read the resource contents. The user must ensure that they
// only use GL locks on GL resources, etc, and this is enforced by assertions.
......
......@@ -116,6 +116,8 @@ viz_component("common") {
"resources/resource.h",
"resources/resource_fence.h",
"resources/resource_id.h",
"resources/resource_metadata.cc",
"resources/resource_metadata.h",
"resources/resource_settings.cc",
"resources/resource_settings.h",
"resources/resource_sizes.h",
......
// Copyright 2018 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 "components/viz/common/resources/resource_metadata.h"
namespace viz {
ResourceMetadata::ResourceMetadata() = default;
ResourceMetadata::ResourceMetadata(ResourceMetadata&& other) = default;
ResourceMetadata::~ResourceMetadata() = default;
ResourceMetadata& ResourceMetadata::operator=(ResourceMetadata&& other) =
default;
} // namespace viz
// Copyright 2018 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 COMPONENTS_VIZ_COMMON_RESOURCES_RESOURCE_METADATA_H_
#define COMPONENTS_VIZ_COMMON_RESOURCES_RESOURCE_METADATA_H_
#include "components/viz/common/viz_common_export.h"
#include "gpu/command_buffer/common/mailbox.h"
#include "gpu/command_buffer/common/sync_token.h"
#include "third_party/skia/include/core/SkColorSpace.h"
#include "third_party/skia/include/gpu/GrBackendSurface.h"
#include "third_party/skia/include/gpu/GrTypes.h"
#include "ui/gfx/geometry/size.h"
namespace viz {
// Metadata for a Resoource. It is used by SkiaRenderer to get resource metedata
// from DisplayResourceProvider, and make a promise SkImage from it.
struct VIZ_COMMON_EXPORT ResourceMetadata {
ResourceMetadata();
ResourceMetadata(ResourceMetadata&& other);
~ResourceMetadata();
ResourceMetadata& operator=(ResourceMetadata&& other);
// A mailbox for the resource texture.
gpu::Mailbox mailbox;
// The backend format for the resource texture. It includes sized texture
// format and texture target.
GrBackendFormat backend_format;
// The resource size.
gfx::Size size;
// the mipmap of the resource texture.
GrMipMapped mip_mapped = GrMipMapped::kNo;
// The origin type for the resource texture.
GrSurfaceOrigin origin = kTopLeft_GrSurfaceOrigin;
// The color type for creating SkImage from the resource texture.
SkColorType color_type = kUnknown_SkColorType;
// The alpha type for the resource texture.
SkAlphaType alpha_type = kUnknown_SkAlphaType;
// The color space for the resource texture. It could be null.
sk_sp<SkColorSpace> color_space;
// The sync token for the resource texture.
gpu::SyncToken sync_token;
};
} // namespace viz
#endif // COMPONENTS_VIZ_COMMON_RESOURCES_RESOURCE_METADATA_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment