Commit 2abe2821 authored by Daniele Castagna's avatar Daniele Castagna Committed by Commit Bot

exo: Use SharedImages instead of GL images

This patch gets rid of GL dependencies in exo.
It replaces GL images creations, updates and deletions with SharedImages.
Copies between shared images and queries are now issued using
RasterInterface.

Test: ARC++ works with Playstore and Youtube
Change-Id: I1dda38fb2b4b93393f9f4a7d308a5c80a53c47e4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1527328Reviewed-by: default avatarkylechar <kylechar@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Reviewed-by: default avatarAntoine Labour <piman@chromium.org>
Reviewed-by: default avatarAndres Calderon Jaramillo <andrescj@chromium.org>
Commit-Queue: Daniele Castagna <dcastagna@chromium.org>
Auto-Submit: Daniele Castagna <dcastagna@chromium.org>
Cr-Commit-Position: refs/heads/master@{#644525}
parent 46889bc4
...@@ -59,7 +59,7 @@ source_set("exo") { ...@@ -59,7 +59,7 @@ source_set("exo") {
"//device/gamepad", "//device/gamepad",
"//device/gamepad/public/cpp:shared_with_blink", "//device/gamepad/public/cpp:shared_with_blink",
"//gpu", "//gpu",
"//gpu/command_buffer/client:gles2_interface", "//gpu/command_buffer/client:raster_interface",
"//services/ws/public/mojom", "//services/ws/public/mojom",
"//skia", "//skia",
"//ui/aura", "//ui/aura",
...@@ -184,7 +184,7 @@ source_set("unit_tests") { ...@@ -184,7 +184,7 @@ source_set("unit_tests") {
"//components/viz/service", "//components/viz/service",
"//components/viz/test:test_support", "//components/viz/test:test_support",
"//device/gamepad:test_helpers", "//device/gamepad:test_helpers",
"//gpu/command_buffer/client:gles2_interface", "//gpu/command_buffer/client:raster_interface",
"//skia", "//skia",
"//testing/gmock", "//testing/gmock",
"//testing/gtest", "//testing/gtest",
......
...@@ -4,9 +4,6 @@ ...@@ -4,9 +4,6 @@
#include "components/exo/buffer.h" #include "components/exo/buffer.h"
#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
#include <GLES2/gl2extchromium.h>
#include <stdint.h> #include <stdint.h>
#include <algorithm> #include <algorithm>
...@@ -27,9 +24,12 @@ ...@@ -27,9 +24,12 @@
#include "components/viz/common/resources/resource_format.h" #include "components/viz/common/resources/resource_format.h"
#include "components/viz/common/resources/resource_format_utils.h" #include "components/viz/common/resources/resource_format_utils.h"
#include "components/viz/common/resources/single_release_callback.h" #include "components/viz/common/resources/single_release_callback.h"
#include "gpu/GLES2/gl2extchromium.h"
#include "gpu/command_buffer/client/context_support.h" #include "gpu/command_buffer/client/context_support.h"
#include "gpu/command_buffer/client/gles2_interface.h" #include "gpu/command_buffer/client/raster_interface.h"
#include "gpu/command_buffer/client/shared_image_interface.h"
#include "gpu/command_buffer/common/mailbox.h" #include "gpu/command_buffer/common/mailbox.h"
#include "gpu/command_buffer/common/shared_image_usage.h"
#include "gpu/command_buffer/common/sync_token.h" #include "gpu/command_buffer/common/sync_token.h"
#include "ui/aura/env.h" #include "ui/aura/env.h"
#include "ui/compositor/compositor.h" #include "ui/compositor/compositor.h"
...@@ -44,56 +44,16 @@ const int kWaitForReleaseDelayMs = 500; ...@@ -44,56 +44,16 @@ const int kWaitForReleaseDelayMs = 500;
constexpr char kBufferInUse[] = "BufferInUse"; constexpr char kBufferInUse[] = "BufferInUse";
GLenum GLInternalFormat(gfx::BufferFormat format) {
const GLenum kGLInternalFormats[] = {
GL_R8_EXT, // R_8
GL_R16_EXT, // R_16
GL_RG8_EXT, // RG_88
GL_RGB, // BGR_565
GL_RGBA, // RGBA_4444
GL_RGB, // RGBX_8888
GL_RGBA, // RGBA_8888
GL_RGB, // BGRX_8888
GL_RGB10_A2_EXT, // BGRX_1010102
GL_RGB10_A2_EXT, // RGBX_1010102
GL_BGRA_EXT, // BGRA_8888
GL_RGBA, // RGBA_F16
GL_RGB_YCRCB_420_CHROMIUM, // YVU_420
GL_RGB_YCBCR_420V_CHROMIUM, // YUV_420_BIPLANAR
GL_RGB_YCBCR_422_CHROMIUM, // UYVY_422
};
static_assert(base::size(kGLInternalFormats) ==
(static_cast<int>(gfx::BufferFormat::LAST) + 1),
"BufferFormat::LAST must be last value of kGLInternalFormats");
DCHECK(format <= gfx::BufferFormat::LAST);
return kGLInternalFormats[static_cast<int>(format)];
}
unsigned CreateGLTexture(gpu::gles2::GLES2Interface* gles2, GLenum target) {
unsigned texture_id = 0;
gles2->GenTextures(1, &texture_id);
gles2->ActiveTexture(GL_TEXTURE0);
gles2->BindTexture(target, texture_id);
gles2->TexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
gles2->TexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
gles2->TexParameteri(target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
gles2->TexParameteri(target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
return texture_id;
}
} // namespace } // namespace
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// Buffer::Texture // Buffer::Texture
// Encapsulates the state and logic needed to bind a buffer to a GLES2 texture. // Encapsulates the state and logic needed to bind a buffer to a SharedImage.
class Buffer::Texture : public ui::ContextFactoryObserver { class Buffer::Texture : public ui::ContextFactoryObserver {
public: public:
Texture(ui::ContextFactory* context_factory, const gfx::Size& size);
Texture(ui::ContextFactory* context_factory, Texture(ui::ContextFactory* context_factory,
viz::ContextProvider* context_provider);
Texture(ui::ContextFactory* context_factory,
viz::ContextProvider* context_provider,
gfx::GpuMemoryBuffer* gpu_memory_buffer, gfx::GpuMemoryBuffer* gpu_memory_buffer,
unsigned texture_target, unsigned texture_target,
unsigned query_type, unsigned query_type,
...@@ -104,7 +64,7 @@ class Buffer::Texture : public ui::ContextFactoryObserver { ...@@ -104,7 +64,7 @@ class Buffer::Texture : public ui::ContextFactoryObserver {
void OnLostSharedContext() override; void OnLostSharedContext() override;
void OnLostVizProcess() override; void OnLostVizProcess() override;
// Returns true if GLES2 resources for texture have been lost. // Returns true if the RasterInterface context has been lost.
bool IsLost(); bool IsLost();
// Allow texture to be reused after |sync_token| has passed and runs // Allow texture to be reused after |sync_token| has passed and runs
...@@ -113,16 +73,17 @@ class Buffer::Texture : public ui::ContextFactoryObserver { ...@@ -113,16 +73,17 @@ class Buffer::Texture : public ui::ContextFactoryObserver {
const gpu::SyncToken& sync_token, const gpu::SyncToken& sync_token,
bool is_lost); bool is_lost);
// Binds the contents referenced by |image_id_| to the texture returned by // Updates the contents referenced by |gpu_memory_buffer_| returned by
// mailbox(). Returns a sync token that can be used when accessing texture // mailbox().
// from a different context. // Returns a sync token that can be used when accessing the SharedImage from a
gpu::SyncToken BindTexImage(); // different context.
gpu::SyncToken UpdateSharedImage();
// Releases the contents referenced by |image_id_| after |sync_token| has // Releases the contents referenced by |mailbox_| after |sync_token| has
// passed and runs |callback| when completed. // passed and runs |callback| when completed.
void ReleaseTexImage(const base::Closure& callback, void ReleaseSharedImage(const base::Closure& callback,
const gpu::SyncToken& sync_token, const gpu::SyncToken& sync_token,
bool is_lost); bool is_lost);
// Copy the contents of texture to |destination| and runs |callback| when // Copy the contents of texture to |destination| and runs |callback| when
// completed. Returns a sync token that can be used when accessing texture // completed. Returns a sync token that can be used when accessing texture
...@@ -141,14 +102,12 @@ class Buffer::Texture : public ui::ContextFactoryObserver { ...@@ -141,14 +102,12 @@ class Buffer::Texture : public ui::ContextFactoryObserver {
void WaitForRelease(); void WaitForRelease();
gfx::GpuMemoryBuffer* const gpu_memory_buffer_; gfx::GpuMemoryBuffer* const gpu_memory_buffer_;
const gfx::Size size_;
ui::ContextFactory* context_factory_; ui::ContextFactory* context_factory_;
scoped_refptr<viz::ContextProvider> context_provider_; scoped_refptr<viz::RasterContextProvider> context_provider_;
const unsigned texture_target_; const unsigned texture_target_;
const unsigned query_type_; const unsigned query_type_;
const GLenum internalformat_;
unsigned image_id_ = 0;
unsigned query_id_ = 0; unsigned query_id_ = 0;
unsigned texture_id_ = 0;
gpu::Mailbox mailbox_; gpu::Mailbox mailbox_;
base::Closure release_callback_; base::Closure release_callback_;
const base::TimeDelta wait_for_release_delay_; const base::TimeDelta wait_for_release_delay_;
...@@ -160,52 +119,63 @@ class Buffer::Texture : public ui::ContextFactoryObserver { ...@@ -160,52 +119,63 @@ class Buffer::Texture : public ui::ContextFactoryObserver {
}; };
Buffer::Texture::Texture(ui::ContextFactory* context_factory, Buffer::Texture::Texture(ui::ContextFactory* context_factory,
viz::ContextProvider* context_provider) const gfx::Size& size)
: gpu_memory_buffer_(nullptr), : gpu_memory_buffer_(nullptr),
size_(size),
context_factory_(context_factory), context_factory_(context_factory),
context_provider_(context_provider), context_provider_(
context_factory->SharedMainThreadRasterContextProvider()),
texture_target_(GL_TEXTURE_2D), texture_target_(GL_TEXTURE_2D),
query_type_(GL_COMMANDS_COMPLETED_CHROMIUM), query_type_(GL_COMMANDS_COMPLETED_CHROMIUM),
internalformat_(GL_RGBA),
weak_ptr_factory_(this) { weak_ptr_factory_(this) {
gpu::gles2::GLES2Interface* gles2 = context_provider_->ContextGL(); gpu::SharedImageInterface* sii = context_provider_->SharedImageInterface();
texture_id_ = CreateGLTexture(gles2, texture_target_); const uint32_t usage =
// Generate a crypto-secure random mailbox name. gpu::SHARED_IMAGE_USAGE_RASTER | gpu::SHARED_IMAGE_USAGE_DISPLAY;
gles2->ProduceTextureDirectCHROMIUM(texture_id_, mailbox_.name);
mailbox_ = sii->CreateSharedImage(viz::ResourceFormat::RGBA_8888, size,
gfx::ColorSpace(), usage);
DCHECK(!mailbox_.IsZero());
gpu::raster::RasterInterface* ri = context_provider_->RasterInterface();
ri->WaitSyncTokenCHROMIUM(sii->GenUnverifiedSyncToken().GetConstData());
// Provides a notification when |context_provider_| is lost. // Provides a notification when |context_provider_| is lost.
context_factory_->AddObserver(this); context_factory_->AddObserver(this);
} }
Buffer::Texture::Texture(ui::ContextFactory* context_factory, Buffer::Texture::Texture(ui::ContextFactory* context_factory,
viz::ContextProvider* context_provider,
gfx::GpuMemoryBuffer* gpu_memory_buffer, gfx::GpuMemoryBuffer* gpu_memory_buffer,
unsigned texture_target, unsigned texture_target,
unsigned query_type, unsigned query_type,
base::TimeDelta wait_for_release_delay) base::TimeDelta wait_for_release_delay)
: gpu_memory_buffer_(gpu_memory_buffer), : gpu_memory_buffer_(gpu_memory_buffer),
size_(gpu_memory_buffer->GetSize()),
context_factory_(context_factory), context_factory_(context_factory),
context_provider_(context_provider), context_provider_(
context_factory->SharedMainThreadRasterContextProvider()),
texture_target_(texture_target), texture_target_(texture_target),
query_type_(query_type), query_type_(query_type),
internalformat_(GLInternalFormat(gpu_memory_buffer->GetFormat())),
wait_for_release_delay_(wait_for_release_delay), wait_for_release_delay_(wait_for_release_delay),
weak_ptr_factory_(this) { weak_ptr_factory_(this) {
gpu::gles2::GLES2Interface* gles2 = context_provider_->ContextGL(); gpu::SharedImageInterface* sii = context_provider_->SharedImageInterface();
gfx::Size size = gpu_memory_buffer->GetSize(); const uint32_t usage = gpu::SHARED_IMAGE_USAGE_RASTER |
image_id_ = gpu::SHARED_IMAGE_USAGE_DISPLAY |
gles2->CreateImageCHROMIUM(gpu_memory_buffer->AsClientBuffer(), gpu::SHARED_IMAGE_USAGE_SCANOUT;
size.width(), size.height(), internalformat_);
DLOG_IF(WARNING, !image_id_) << "Failed to create GLImage"; mailbox_ = sii->CreateSharedImage(
gpu_memory_buffer_, context_factory_->GetGpuMemoryBufferManager(),
gles2->GenQueriesEXT(1, &query_id_); gfx::ColorSpace(), usage);
texture_id_ = CreateGLTexture(gles2, texture_target_); DCHECK(!mailbox_.IsZero());
gpu::raster::RasterInterface* ri = context_provider_->RasterInterface();
ri->WaitSyncTokenCHROMIUM(sii->GenUnverifiedSyncToken().GetConstData());
ri->GenQueriesEXT(1, &query_id_);
// Provides a notification when |context_provider_| is lost. // Provides a notification when |context_provider_| is lost.
context_factory_->AddObserver(this); context_factory_->AddObserver(this);
} }
Buffer::Texture::~Texture() { Buffer::Texture::~Texture() {
DestroyResources(); DestroyResources();
if (context_provider_) if (context_factory_)
context_factory_->RemoveObserver(this); context_factory_->RemoveObserver(this);
} }
...@@ -220,8 +190,8 @@ void Buffer::Texture::OnLostVizProcess() {} ...@@ -220,8 +190,8 @@ void Buffer::Texture::OnLostVizProcess() {}
bool Buffer::Texture::IsLost() { bool Buffer::Texture::IsLost() {
if (context_provider_) { if (context_provider_) {
gpu::gles2::GLES2Interface* gles2 = context_provider_->ContextGL(); gpu::raster::RasterInterface* ri = context_provider_->RasterInterface();
return gles2->GetGraphicsResetStatusKHR() != GL_NO_ERROR; return ri->GetGraphicsResetStatusKHR() != GL_NO_ERROR;
} }
return true; return true;
} }
...@@ -230,9 +200,10 @@ void Buffer::Texture::Release(const base::Closure& callback, ...@@ -230,9 +200,10 @@ void Buffer::Texture::Release(const base::Closure& callback,
const gpu::SyncToken& sync_token, const gpu::SyncToken& sync_token,
bool is_lost) { bool is_lost) {
if (context_provider_) { if (context_provider_) {
gpu::gles2::GLES2Interface* gles2 = context_provider_->ContextGL(); if (sync_token.HasData()) {
if (sync_token.HasData()) gpu::raster::RasterInterface* ri = context_provider_->RasterInterface();
gles2->WaitSyncTokenCHROMIUM(sync_token.GetConstData()); ri->WaitSyncTokenCHROMIUM(sync_token.GetConstData());
}
} }
// Run callback as texture can be reused immediately after waiting for sync // Run callback as texture can be reused immediately after waiting for sync
...@@ -240,43 +211,36 @@ void Buffer::Texture::Release(const base::Closure& callback, ...@@ -240,43 +211,36 @@ void Buffer::Texture::Release(const base::Closure& callback,
callback.Run(); callback.Run();
} }
gpu::SyncToken Buffer::Texture::BindTexImage() { gpu::SyncToken Buffer::Texture::UpdateSharedImage() {
gpu::SyncToken sync_token; gpu::SyncToken sync_token;
if (context_provider_) { if (context_provider_) {
gpu::gles2::GLES2Interface* gles2 = context_provider_->ContextGL(); gpu::SharedImageInterface* sii = context_provider_->SharedImageInterface();
gles2->ActiveTexture(GL_TEXTURE0); DCHECK(!mailbox_.IsZero());
gles2->BindTexture(texture_target_, texture_id_); // UpdateSharedImage gets called only after |mailbox_| can be reused.
DCHECK_NE(image_id_, 0u); // A buffer can be reattached to a surface only after it has been returned
gles2->BindTexImage2DCHROMIUM(texture_target_, image_id_); // to wayland clients. We return buffers to clients only after the query
// Generate a crypto-secure random mailbox name if not already done. // |query_type_| is available.
if (mailbox_.IsZero()) sii->UpdateSharedImage(gpu::SyncToken(), mailbox_);
gles2->ProduceTextureDirectCHROMIUM(texture_id_, mailbox_.name); sync_token = sii->GenUnverifiedSyncToken();
// Create and return a sync token that can be used to ensure that the
// BindTexImage2DCHROMIUM call is processed before issuing any commands
// that will read from the texture on a different context.
gles2->GenUnverifiedSyncTokenCHROMIUM(sync_token.GetData());
TRACE_EVENT_ASYNC_STEP_INTO0("exo", kBufferInUse, gpu_memory_buffer_, TRACE_EVENT_ASYNC_STEP_INTO0("exo", kBufferInUse, gpu_memory_buffer_,
"bound"); "bound");
} }
return sync_token; return sync_token;
} }
void Buffer::Texture::ReleaseTexImage(const base::Closure& callback, void Buffer::Texture::ReleaseSharedImage(const base::Closure& callback,
const gpu::SyncToken& sync_token, const gpu::SyncToken& sync_token,
bool is_lost) { bool is_lost) {
if (context_provider_) { if (context_provider_) {
gpu::gles2::GLES2Interface* gles2 = context_provider_->ContextGL(); gpu::raster::RasterInterface* ri = context_provider_->RasterInterface();
if (sync_token.HasData()) if (sync_token.HasData())
gles2->WaitSyncTokenCHROMIUM(sync_token.GetConstData()); ri->WaitSyncTokenCHROMIUM(sync_token.GetConstData());
gles2->ActiveTexture(GL_TEXTURE0); ri->BeginQueryEXT(query_type_, query_id_);
gles2->BindTexture(texture_target_, texture_id_); ri->EndQueryEXT(query_type_);
DCHECK_NE(query_id_, 0u); // Run callback when query result is available (i.e., when all operations on
gles2->BeginQueryEXT(query_type_, query_id_); // the shared image have completed and it's ready to be reused) if sync
gles2->ReleaseTexImage2DCHROMIUM(texture_target_, image_id_); // token has data and buffer has been used. If buffer was never used then
gles2->EndQueryEXT(query_type_); // run the callback immediately.
// Run callback when query result is available and ReleaseTexImage has been
// handled if sync token has data and buffer has been used. If buffer was
// never used then run the callback immediately.
if (sync_token.HasData()) { if (sync_token.HasData()) {
ReleaseWhenQueryResultIsAvailable(callback); ReleaseWhenQueryResultIsAvailable(callback);
return; return;
...@@ -289,37 +253,34 @@ gpu::SyncToken Buffer::Texture::CopyTexImage(Texture* destination, ...@@ -289,37 +253,34 @@ gpu::SyncToken Buffer::Texture::CopyTexImage(Texture* destination,
const base::Closure& callback) { const base::Closure& callback) {
gpu::SyncToken sync_token; gpu::SyncToken sync_token;
if (context_provider_) { if (context_provider_) {
gpu::gles2::GLES2Interface* gles2 = context_provider_->ContextGL(); DCHECK(!mailbox_.IsZero());
gles2->ActiveTexture(GL_TEXTURE0);
gles2->BindTexture(texture_target_, texture_id_); gpu::raster::RasterInterface* ri = context_provider_->RasterInterface();
DCHECK_NE(image_id_, 0u);
gles2->BindTexImage2DCHROMIUM(texture_target_, image_id_);
gles2->CopyTextureCHROMIUM(texture_id_, 0, destination->texture_target_,
destination->texture_id_, 0, internalformat_,
GL_UNSIGNED_BYTE, false, false, false);
DCHECK_NE(query_id_, 0u); DCHECK_NE(query_id_, 0u);
gles2->BeginQueryEXT(query_type_, query_id_); ri->BeginQueryEXT(query_type_, query_id_);
gles2->ReleaseTexImage2DCHROMIUM(texture_target_, image_id_); ri->CopySubTexture(mailbox_, destination->mailbox_,
gles2->EndQueryEXT(query_type_); destination->texture_target_, 0, 0, 0, 0, size_.width(),
// Run callback when query result is available and ReleaseTexImage has been size_.height());
// handled. ri->EndQueryEXT(query_type_);
// Run callback when query result is available.
ReleaseWhenQueryResultIsAvailable(callback); ReleaseWhenQueryResultIsAvailable(callback);
// Create and return a sync token that can be used to ensure that the // Create and return a sync token that can be used to ensure that the
// CopyTextureCHROMIUM call is processed before issuing any commands // CopyTextureCHROMIUM call is processed before issuing any commands
// that will read from the target texture on a different context. // that will read from the target texture on a different context.
gles2->GenUnverifiedSyncTokenCHROMIUM(sync_token.GetData()); ri->GenUnverifiedSyncTokenCHROMIUM(sync_token.GetData());
} }
return sync_token; return sync_token;
} }
void Buffer::Texture::DestroyResources() { void Buffer::Texture::DestroyResources() {
if (context_provider_) { if (context_provider_) {
gpu::gles2::GLES2Interface* gles2 = context_provider_->ContextGL(); if (query_id_) {
gles2->DeleteTextures(1, &texture_id_); gpu::raster::RasterInterface* ri = context_provider_->RasterInterface();
if (query_id_) ri->DeleteQueriesEXT(1, &query_id_);
gles2->DeleteQueriesEXT(1, &query_id_); query_id_ = 0;
if (image_id_) }
gles2->DestroyImageCHROMIUM(image_id_); gpu::SharedImageInterface* sii = context_provider_->SharedImageInterface();
sii->DestroySharedImage(gpu::SyncToken(), mailbox_);
} }
} }
...@@ -376,8 +337,8 @@ void Buffer::Texture::WaitForRelease() { ...@@ -376,8 +337,8 @@ void Buffer::Texture::WaitForRelease() {
// the query implies waiting for it to become available. The actual result // the query implies waiting for it to become available. The actual result
// is unimportant and also not well defined. // is unimportant and also not well defined.
unsigned result = 0; unsigned result = 0;
gpu::gles2::GLES2Interface* gles2 = context_provider_->ContextGL(); gpu::raster::RasterInterface* ri = context_provider_->RasterInterface();
gles2->GetQueryObjectuivEXT(query_id_, GL_QUERY_RESULT_EXT, &result); ri->GetQueryObjectuivEXT(query_id_, GL_QUERY_RESULT_EXT, &result);
} }
callback.Run(); callback.Run();
...@@ -428,8 +389,8 @@ bool Buffer::ProduceTransferableResource( ...@@ -428,8 +389,8 @@ bool Buffer::ProduceTransferableResource(
ui::ContextFactory* context_factory = ui::ContextFactory* context_factory =
WMHelper::GetInstance()->env()->context_factory(); WMHelper::GetInstance()->env()->context_factory();
// Note: This can fail if GPU acceleration has been disabled. // Note: This can fail if GPU acceleration has been disabled.
scoped_refptr<viz::ContextProvider> context_provider = scoped_refptr<viz::RasterContextProvider> context_provider =
context_factory->SharedMainThreadContextProvider(); context_factory->SharedMainThreadRasterContextProvider();
if (!context_provider) { if (!context_provider) {
DLOG(WARNING) << "Failed to acquire a context provider"; DLOG(WARNING) << "Failed to acquire a context provider";
resource->id = 0; resource->id = 0;
...@@ -447,8 +408,8 @@ bool Buffer::ProduceTransferableResource( ...@@ -447,8 +408,8 @@ bool Buffer::ProduceTransferableResource(
// |texture| using a call to CopyTexImage. // |texture| using a call to CopyTexImage.
if (!contents_texture_) { if (!contents_texture_) {
contents_texture_ = std::make_unique<Texture>( contents_texture_ = std::make_unique<Texture>(
context_factory, context_provider.get(), gpu_memory_buffer_.get(), context_factory, gpu_memory_buffer_.get(), texture_target_, query_type_,
texture_target_, query_type_, wait_for_release_delay_); wait_for_release_delay_);
} }
Texture* contents_texture = contents_texture_.get(); Texture* contents_texture = contents_texture_.get();
...@@ -463,7 +424,7 @@ bool Buffer::ProduceTransferableResource( ...@@ -463,7 +424,7 @@ bool Buffer::ProduceTransferableResource(
// Zero-copy means using the contents texture directly. // Zero-copy means using the contents texture directly.
if (use_zero_copy_) { if (use_zero_copy_) {
// This binds the latest contents of this buffer to |contents_texture|. // This binds the latest contents of this buffer to |contents_texture|.
gpu::SyncToken sync_token = contents_texture->BindTexImage(); gpu::SyncToken sync_token = contents_texture->UpdateSharedImage();
resource->mailbox_holder = gpu::MailboxHolder(contents_texture->mailbox(), resource->mailbox_holder = gpu::MailboxHolder(contents_texture->mailbox(),
sync_token, texture_target_); sync_token, texture_target_);
resource->is_overlay_candidate = is_overlay_candidate_; resource->is_overlay_candidate = is_overlay_candidate_;
...@@ -473,7 +434,7 @@ bool Buffer::ProduceTransferableResource( ...@@ -473,7 +434,7 @@ bool Buffer::ProduceTransferableResource(
// compositor. // compositor.
resource_manager->SetResourceReleaseCallback( resource_manager->SetResourceReleaseCallback(
resource->id, resource->id,
base::BindOnce(&Buffer::Texture::ReleaseTexImage, base::BindOnce(&Buffer::Texture::ReleaseSharedImage,
base::Unretained(contents_texture), base::Unretained(contents_texture),
base::Bind(&Buffer::ReleaseContentsTexture, AsWeakPtr(), base::Bind(&Buffer::ReleaseContentsTexture, AsWeakPtr(),
base::Passed(&contents_texture_), base::Passed(&contents_texture_),
...@@ -483,8 +444,8 @@ bool Buffer::ProduceTransferableResource( ...@@ -483,8 +444,8 @@ bool Buffer::ProduceTransferableResource(
// Create a mailbox texture that we copy the buffer contents to. // Create a mailbox texture that we copy the buffer contents to.
if (!texture_) { if (!texture_) {
texture_ = texture_ = std::make_unique<Texture>(context_factory,
std::make_unique<Texture>(context_factory, context_provider.get()); gpu_memory_buffer_->GetSize());
} }
Texture* texture = texture_.get(); Texture* texture = texture_.get();
......
...@@ -14,9 +14,8 @@ ...@@ -14,9 +14,8 @@
#include "components/exo/test/exo_test_helper.h" #include "components/exo/test/exo_test_helper.h"
#include "components/viz/common/gpu/context_provider.h" #include "components/viz/common/gpu/context_provider.h"
#include "components/viz/common/resources/single_release_callback.h" #include "components/viz/common/resources/single_release_callback.h"
#include "gpu/command_buffer/client/gles2_interface.h" #include "gpu/command_buffer/client/raster_interface.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "third_party/khronos/GLES2/gl2.h"
#include "ui/aura/env.h" #include "ui/aura/env.h"
#include "ui/compositor/compositor.h" #include "ui/compositor/compositor.h"
#include "ui/compositor/test/in_process_context_factory.h" #include "ui/compositor/test/in_process_context_factory.h"
...@@ -39,11 +38,12 @@ void VerifySyncTokensInCompositorFrame(viz::CompositorFrame* frame) { ...@@ -39,11 +38,12 @@ void VerifySyncTokensInCompositorFrame(viz::CompositorFrame* frame) {
std::vector<GLbyte*> sync_tokens; std::vector<GLbyte*> sync_tokens;
for (auto& resource : frame->resource_list) for (auto& resource : frame->resource_list)
sync_tokens.push_back(resource.mailbox_holder.sync_token.GetData()); sync_tokens.push_back(resource.mailbox_holder.sync_token.GetData());
gpu::gles2::GLES2Interface* gles2 = GetAuraEnv() gpu::raster::RasterInterface* ri =
->context_factory() GetAuraEnv()
->SharedMainThreadContextProvider() ->context_factory()
->ContextGL(); ->SharedMainThreadRasterContextProvider()
gles2->VerifySyncTokensCHROMIUM(sync_tokens.data(), sync_tokens.size()); ->RasterInterface();
ri->VerifySyncTokensCHROMIUM(sync_tokens.data(), sync_tokens.size());
} }
TEST_F(BufferTest, ReleaseCallback) { TEST_F(BufferTest, ReleaseCallback) {
...@@ -102,12 +102,12 @@ TEST_F(BufferTest, IsLost) { ...@@ -102,12 +102,12 @@ TEST_F(BufferTest, IsLost) {
frame_sink_holder->resource_manager(), false, &resource); frame_sink_holder->resource_manager(), false, &resource);
ASSERT_TRUE(rv); ASSERT_TRUE(rv);
scoped_refptr<viz::ContextProvider> context_provider = scoped_refptr<viz::RasterContextProvider> context_provider =
GetAuraEnv()->context_factory()->SharedMainThreadContextProvider(); GetAuraEnv()->context_factory()->SharedMainThreadRasterContextProvider();
if (context_provider) { if (context_provider) {
gpu::gles2::GLES2Interface* gles2 = context_provider->ContextGL(); gpu::raster::RasterInterface* ri = context_provider->RasterInterface();
gles2->LoseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET_ARB, ri->LoseContextCHROMIUM(GL_GUILTY_CONTEXT_RESET_ARB,
GL_INNOCENT_CONTEXT_RESET_ARB); GL_INNOCENT_CONTEXT_RESET_ARB);
} }
// Release buffer. // Release buffer.
......
...@@ -877,7 +877,7 @@ GpuProcessTransportFactory::SharedMainThreadContextProvider() { ...@@ -877,7 +877,7 @@ GpuProcessTransportFactory::SharedMainThreadContextProvider() {
bool need_alpha_channel = false; bool need_alpha_channel = false;
bool support_locking = false; bool support_locking = false;
bool support_gles2_interface = true; bool support_gles2_interface = true;
bool support_raster_interface = false; bool support_raster_interface = true;
bool support_grcontext = true; bool support_grcontext = true;
shared_main_thread_contexts_ = CreateContextCommon( shared_main_thread_contexts_ = CreateContextCommon(
std::move(gpu_channel_host), gpu::kNullSurfaceHandle, need_alpha_channel, std::move(gpu_channel_host), gpu::kNullSurfaceHandle, need_alpha_channel,
...@@ -893,6 +893,14 @@ GpuProcessTransportFactory::SharedMainThreadContextProvider() { ...@@ -893,6 +893,14 @@ GpuProcessTransportFactory::SharedMainThreadContextProvider() {
return shared_main_thread_contexts_; return shared_main_thread_contexts_;
} }
scoped_refptr<viz::RasterContextProvider>
GpuProcessTransportFactory::SharedMainThreadRasterContextProvider() {
SharedMainThreadContextProvider();
DCHECK(!shared_main_thread_contexts_ ||
shared_main_thread_contexts_->RasterInterface());
return shared_main_thread_contexts_;
}
scoped_refptr<viz::RasterContextProvider> scoped_refptr<viz::RasterContextProvider>
GpuProcessTransportFactory::shared_worker_context_provider() { GpuProcessTransportFactory::shared_worker_context_provider() {
return shared_worker_context_provider_factory_.provider(); return shared_worker_context_provider_factory_.provider();
......
...@@ -70,6 +70,9 @@ class GpuProcessTransportFactory : public ui::ContextFactory, ...@@ -70,6 +70,9 @@ class GpuProcessTransportFactory : public ui::ContextFactory,
base::WeakPtr<ui::Compositor> compositor) override; base::WeakPtr<ui::Compositor> compositor) override;
scoped_refptr<viz::ContextProvider> SharedMainThreadContextProvider() scoped_refptr<viz::ContextProvider> SharedMainThreadContextProvider()
override; override;
scoped_refptr<viz::RasterContextProvider>
SharedMainThreadRasterContextProvider() override;
gpu::GpuMemoryBufferManager* GetGpuMemoryBufferManager() override; gpu::GpuMemoryBufferManager* GetGpuMemoryBufferManager() override;
cc::TaskGraphRunner* GetTaskGraphRunner() override; cc::TaskGraphRunner* GetTaskGraphRunner() override;
void AddObserver(ui::ContextFactoryObserver* observer) override; void AddObserver(ui::ContextFactoryObserver* observer) override;
......
...@@ -95,6 +95,12 @@ TestImageTransportFactory::SharedMainThreadContextProvider() { ...@@ -95,6 +95,12 @@ TestImageTransportFactory::SharedMainThreadContextProvider() {
return shared_main_context_provider_; return shared_main_context_provider_;
} }
scoped_refptr<viz::RasterContextProvider>
TestImageTransportFactory::SharedMainThreadRasterContextProvider() {
NOTIMPLEMENTED();
return nullptr;
}
gpu::GpuMemoryBufferManager* gpu::GpuMemoryBufferManager*
TestImageTransportFactory::GetGpuMemoryBufferManager() { TestImageTransportFactory::GetGpuMemoryBufferManager() {
return &gpu_memory_buffer_manager_; return &gpu_memory_buffer_manager_;
......
...@@ -47,6 +47,9 @@ class TestImageTransportFactory : public ui::ContextFactory, ...@@ -47,6 +47,9 @@ class TestImageTransportFactory : public ui::ContextFactory,
base::WeakPtr<ui::Compositor> compositor) override; base::WeakPtr<ui::Compositor> compositor) override;
scoped_refptr<viz::ContextProvider> SharedMainThreadContextProvider() scoped_refptr<viz::ContextProvider> SharedMainThreadContextProvider()
override; override;
scoped_refptr<viz::RasterContextProvider>
SharedMainThreadRasterContextProvider() override;
void RemoveCompositor(ui::Compositor* compositor) override {} void RemoveCompositor(ui::Compositor* compositor) override {}
gpu::GpuMemoryBufferManager* GetGpuMemoryBufferManager() override; gpu::GpuMemoryBufferManager* GetGpuMemoryBufferManager() override;
cc::TaskGraphRunner* GetTaskGraphRunner() override; cc::TaskGraphRunner* GetTaskGraphRunner() override;
......
...@@ -248,6 +248,13 @@ VizProcessTransportFactory::SharedMainThreadContextProvider() { ...@@ -248,6 +248,13 @@ VizProcessTransportFactory::SharedMainThreadContextProvider() {
return main_context_provider_; return main_context_provider_;
} }
scoped_refptr<viz::RasterContextProvider>
VizProcessTransportFactory::SharedMainThreadRasterContextProvider() {
SharedMainThreadContextProvider();
DCHECK(!main_context_provider_ || main_context_provider_->RasterInterface());
return main_context_provider_;
}
void VizProcessTransportFactory::RemoveCompositor(ui::Compositor* compositor) { void VizProcessTransportFactory::RemoveCompositor(ui::Compositor* compositor) {
context_factory_private_.UnconfigureCompositor(compositor); context_factory_private_.UnconfigureCompositor(compositor);
} }
...@@ -451,7 +458,7 @@ VizProcessTransportFactory::TryCreateContextsForGpuCompositing( ...@@ -451,7 +458,7 @@ VizProcessTransportFactory::TryCreateContextsForGpuCompositing(
if (!main_context_provider_) { if (!main_context_provider_) {
constexpr bool kCompositorContextSupportsLocking = false; constexpr bool kCompositorContextSupportsLocking = false;
constexpr bool kCompositorContextSupportsGLES2 = true; constexpr bool kCompositorContextSupportsGLES2 = true;
constexpr bool kCompositorContextSupportsRaster = false; constexpr bool kCompositorContextSupportsRaster = true;
constexpr bool kCompositorContextSupportsGrContext = true; constexpr bool kCompositorContextSupportsGrContext = true;
constexpr bool kCompositorContextSupportsOOPR = false; constexpr bool kCompositorContextSupportsOOPR = false;
......
...@@ -64,6 +64,9 @@ class VizProcessTransportFactory : public ui::ContextFactory, ...@@ -64,6 +64,9 @@ class VizProcessTransportFactory : public ui::ContextFactory,
base::WeakPtr<ui::Compositor> compositor) override; base::WeakPtr<ui::Compositor> compositor) override;
scoped_refptr<viz::ContextProvider> SharedMainThreadContextProvider() scoped_refptr<viz::ContextProvider> SharedMainThreadContextProvider()
override; override;
scoped_refptr<viz::RasterContextProvider>
SharedMainThreadRasterContextProvider() override;
void RemoveCompositor(ui::Compositor* compositor) override; void RemoveCompositor(ui::Compositor* compositor) override;
gpu::GpuMemoryBufferManager* GetGpuMemoryBufferManager() override; gpu::GpuMemoryBufferManager* GetGpuMemoryBufferManager() override;
cc::TaskGraphRunner* GetTaskGraphRunner() override; cc::TaskGraphRunner* GetTaskGraphRunner() override;
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "components/viz/common/gpu/raster_context_provider.h" #include "components/viz/common/gpu/raster_context_provider.h"
#include "components/viz/host/host_frame_sink_manager.h" #include "components/viz/host/host_frame_sink_manager.h"
#include "services/ws/ids.h" #include "services/ws/ids.h"
#include "services/ws/public/cpp/gpu/context_provider_command_buffer.h"
#include "services/ws/public/cpp/gpu/gpu.h" #include "services/ws/public/cpp/gpu/gpu.h"
#include "ui/compositor/host/host_context_factory_private.h" #include "ui/compositor/host/host_context_factory_private.h"
...@@ -37,7 +38,7 @@ void HostContextFactory::OnEstablishedGpuChannel( ...@@ -37,7 +38,7 @@ void HostContextFactory::OnEstablishedGpuChannel(
if (!compositor) if (!compositor)
return; return;
scoped_refptr<viz::ContextProvider> context_provider = scoped_refptr<ws::ContextProviderCommandBuffer> context_provider =
gpu_->CreateContextProvider(std::move(gpu_channel)); gpu_->CreateContextProvider(std::move(gpu_channel));
// If the binding fails, then we need to return early since the compositor // If the binding fails, then we need to return early since the compositor
// expects a successfully initialized/bound provider. // expects a successfully initialized/bound provider.
...@@ -70,6 +71,16 @@ HostContextFactory::SharedMainThreadContextProvider() { ...@@ -70,6 +71,16 @@ HostContextFactory::SharedMainThreadContextProvider() {
return shared_main_thread_context_provider_; return shared_main_thread_context_provider_;
} }
scoped_refptr<viz::RasterContextProvider>
HostContextFactory::SharedMainThreadRasterContextProvider() {
// Exo is currently the only client requesting this context provider.
// Exo does not request this context in the Window Service.
SharedMainThreadContextProvider();
DCHECK(!shared_main_thread_context_provider_ ||
shared_main_thread_context_provider_->RasterInterface());
return shared_main_thread_context_provider_;
}
void HostContextFactory::RemoveCompositor(ui::Compositor* compositor) { void HostContextFactory::RemoveCompositor(ui::Compositor* compositor) {
context_factory_private_->UnconfigureCompositor(compositor); context_factory_private_->UnconfigureCompositor(compositor);
} }
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "components/viz/common/display/renderer_settings.h" #include "components/viz/common/display/renderer_settings.h"
#include "components/viz/common/gpu/context_provider.h" #include "components/viz/common/gpu/context_provider.h"
#include "components/viz/common/gpu/raster_context_provider.h"
#include "services/ws/public/cpp/raster_thread_helper.h" #include "services/ws/public/cpp/raster_thread_helper.h"
#include "ui/compositor/compositor.h" #include "ui/compositor/compositor.h"
...@@ -27,6 +28,7 @@ class HostContextFactoryPrivate; ...@@ -27,6 +28,7 @@ class HostContextFactoryPrivate;
namespace ws { namespace ws {
class ContextProviderCommandBuffer;
class Gpu; class Gpu;
// ui::ContextFactory used when the WindowService is acting as the viz host. // ui::ContextFactory used when the WindowService is acting as the viz host.
...@@ -50,6 +52,8 @@ class HostContextFactory : public ui::ContextFactory { ...@@ -50,6 +52,8 @@ class HostContextFactory : public ui::ContextFactory {
base::WeakPtr<ui::Compositor> compositor) override; base::WeakPtr<ui::Compositor> compositor) override;
scoped_refptr<viz::ContextProvider> SharedMainThreadContextProvider() scoped_refptr<viz::ContextProvider> SharedMainThreadContextProvider()
override; override;
scoped_refptr<viz::RasterContextProvider>
SharedMainThreadRasterContextProvider() override;
void RemoveCompositor(ui::Compositor* compositor) override; void RemoveCompositor(ui::Compositor* compositor) override;
gpu::GpuMemoryBufferManager* GetGpuMemoryBufferManager() override; gpu::GpuMemoryBufferManager* GetGpuMemoryBufferManager() override;
cc::TaskGraphRunner* GetTaskGraphRunner() override; cc::TaskGraphRunner* GetTaskGraphRunner() override;
...@@ -59,7 +63,8 @@ class HostContextFactory : public ui::ContextFactory { ...@@ -59,7 +63,8 @@ class HostContextFactory : public ui::ContextFactory {
RasterThreadHelper raster_thread_helper_; RasterThreadHelper raster_thread_helper_;
Gpu* gpu_; Gpu* gpu_;
scoped_refptr<viz::ContextProvider> shared_main_thread_context_provider_; scoped_refptr<ws::ContextProviderCommandBuffer>
shared_main_thread_context_provider_;
std::unique_ptr<ui::HostContextFactoryPrivate> context_factory_private_; std::unique_ptr<ui::HostContextFactoryPrivate> context_factory_private_;
......
...@@ -276,7 +276,7 @@ std::unique_ptr<Gpu> Gpu::Create( ...@@ -276,7 +276,7 @@ std::unique_ptr<Gpu> Gpu::Create(
return base::WrapUnique(new Gpu(std::move(gpu_ptr), std::move(task_runner))); return base::WrapUnique(new Gpu(std::move(gpu_ptr), std::move(task_runner)));
} }
scoped_refptr<viz::ContextProvider> Gpu::CreateContextProvider( scoped_refptr<ws::ContextProviderCommandBuffer> Gpu::CreateContextProvider(
scoped_refptr<gpu::GpuChannelHost> gpu_channel) { scoped_refptr<gpu::GpuChannelHost> gpu_channel) {
int32_t stream_id = 0; int32_t stream_id = 0;
gpu::SchedulingPriority stream_priority = gpu::SchedulingPriority::kNormal; gpu::SchedulingPriority stream_priority = gpu::SchedulingPriority::kNormal;
...@@ -293,6 +293,7 @@ scoped_refptr<viz::ContextProvider> Gpu::CreateContextProvider( ...@@ -293,6 +293,7 @@ scoped_refptr<viz::ContextProvider> Gpu::CreateContextProvider(
attributes.sample_buffers = 0; attributes.sample_buffers = 0;
attributes.bind_generates_resource = false; attributes.bind_generates_resource = false;
attributes.lose_context_when_out_of_memory = true; attributes.lose_context_when_out_of_memory = true;
attributes.enable_raster_interface = true;
return base::MakeRefCounted<ContextProviderCommandBuffer>( return base::MakeRefCounted<ContextProviderCommandBuffer>(
std::move(gpu_channel), GetGpuMemoryBufferManager(), stream_id, std::move(gpu_channel), GetGpuMemoryBufferManager(), stream_id,
stream_priority, gpu::kNullSurfaceHandle, stream_priority, gpu::kNullSurfaceHandle,
......
...@@ -22,6 +22,8 @@ class Connector; ...@@ -22,6 +22,8 @@ class Connector;
namespace ws { namespace ws {
class ContextProviderCommandBuffer;
class Gpu : public gpu::GpuChannelEstablishFactory { class Gpu : public gpu::GpuChannelEstablishFactory {
public: public:
// The Gpu has to be initialized in the main thread before establishing // The Gpu has to be initialized in the main thread before establishing
...@@ -37,7 +39,7 @@ class Gpu : public gpu::GpuChannelEstablishFactory { ...@@ -37,7 +39,7 @@ class Gpu : public gpu::GpuChannelEstablishFactory {
return gpu_memory_buffer_manager_.get(); return gpu_memory_buffer_manager_.get();
} }
scoped_refptr<viz::ContextProvider> CreateContextProvider( scoped_refptr<ws::ContextProviderCommandBuffer> CreateContextProvider(
scoped_refptr<gpu::GpuChannelHost> gpu_channel); scoped_refptr<gpu::GpuChannelHost> gpu_channel);
void CreateJpegDecodeAccelerator( void CreateJpegDecodeAccelerator(
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "components/viz/host/renderer_settings_creation.h" #include "components/viz/host/renderer_settings_creation.h"
#include "gpu/command_buffer/common/scheduling_priority.h" #include "gpu/command_buffer/common/scheduling_priority.h"
#include "services/ws/public/cpp/gpu/command_buffer_metrics.h" #include "services/ws/public/cpp/gpu/command_buffer_metrics.h"
#include "services/ws/public/cpp/gpu/context_provider_command_buffer.h"
#include "services/ws/public/cpp/gpu/gpu.h" #include "services/ws/public/cpp/gpu/gpu.h"
#include "services/ws/public/cpp/gpu/shared_worker_context_provider_factory.h" #include "services/ws/public/cpp/gpu/shared_worker_context_provider_factory.h"
#include "ui/aura/mus/window_port_mus.h" #include "ui/aura/mus/window_port_mus.h"
...@@ -49,7 +50,7 @@ void MusContextFactory::OnEstablishedGpuChannel( ...@@ -49,7 +50,7 @@ void MusContextFactory::OnEstablishedGpuChannel(
DCHECK_EQ(host->compositor(), compositor.get()); DCHECK_EQ(host->compositor(), compositor.get());
scoped_refptr<viz::ContextProvider> context_provider = scoped_refptr<ws::ContextProviderCommandBuffer> context_provider =
gpu_->CreateContextProvider(gpu_channel); gpu_->CreateContextProvider(gpu_channel);
// If the binding fails, then we need to return early since the compositor // If the binding fails, then we need to return early since the compositor
// expects a successfully initialized/bound provider. // expects a successfully initialized/bound provider.
...@@ -107,6 +108,14 @@ MusContextFactory::SharedMainThreadContextProvider() { ...@@ -107,6 +108,14 @@ MusContextFactory::SharedMainThreadContextProvider() {
return shared_main_thread_context_provider_; return shared_main_thread_context_provider_;
} }
scoped_refptr<viz::RasterContextProvider>
MusContextFactory::SharedMainThreadRasterContextProvider() {
// Exo is currently the only client requesting this context provider.
// Exo does not request this context in MUS.
NOTREACHED();
return nullptr;
}
void MusContextFactory::RemoveCompositor(ui::Compositor* compositor) { void MusContextFactory::RemoveCompositor(ui::Compositor* compositor) {
// NOTIMPLEMENTED(); // NOTIMPLEMENTED();
} }
......
...@@ -48,6 +48,10 @@ class AURA_EXPORT MusContextFactory : public ui::ContextFactory { ...@@ -48,6 +48,10 @@ class AURA_EXPORT MusContextFactory : public ui::ContextFactory {
base::WeakPtr<ui::Compositor> compositor) override; base::WeakPtr<ui::Compositor> compositor) override;
scoped_refptr<viz::ContextProvider> SharedMainThreadContextProvider() scoped_refptr<viz::ContextProvider> SharedMainThreadContextProvider()
override; override;
scoped_refptr<viz::RasterContextProvider>
SharedMainThreadRasterContextProvider() override;
void RemoveCompositor(ui::Compositor* compositor) override; void RemoveCompositor(ui::Compositor* compositor) override;
gpu::GpuMemoryBufferManager* GetGpuMemoryBufferManager() override; gpu::GpuMemoryBufferManager* GetGpuMemoryBufferManager() override;
cc::TaskGraphRunner* GetTaskGraphRunner() override; cc::TaskGraphRunner* GetTaskGraphRunner() override;
......
...@@ -67,6 +67,7 @@ namespace viz { ...@@ -67,6 +67,7 @@ namespace viz {
class FrameSinkManagerImpl; class FrameSinkManagerImpl;
class ContextProvider; class ContextProvider;
class HostFrameSinkManager; class HostFrameSinkManager;
class RasterContextProvider;
} }
namespace ui { namespace ui {
...@@ -86,10 +87,11 @@ class COMPOSITOR_EXPORT ContextFactoryObserver { ...@@ -86,10 +87,11 @@ class COMPOSITOR_EXPORT ContextFactoryObserver {
public: public:
virtual ~ContextFactoryObserver() {} virtual ~ContextFactoryObserver() {}
// Notifies that the viz::ContextProvider returned from // Notifies that the viz::ContextProviders returned from
// ui::ContextFactory::SharedMainThreadContextProvider was lost. When this // ui::ContextFactory::SharedMainThreadContextProvider and/or
// is called, the old resources (e.g. shared context, GL helper) still // ui::ContextFactory::SharedMainThreadRasterContextProvider were lost.
// exist, but are about to be destroyed. Getting a reference to those // When this is called, the old resources (e.g. shared context, GL helper)
// still exist, but are about to be destroyed. Getting a reference to those
// resources from the ContextFactory (e.g. through // resources from the ContextFactory (e.g. through
// SharedMainThreadContextProvider()) will return newly recreated, valid // SharedMainThreadContextProvider()) will return newly recreated, valid
// resources. // resources.
...@@ -177,6 +179,11 @@ class COMPOSITOR_EXPORT ContextFactory { ...@@ -177,6 +179,11 @@ class COMPOSITOR_EXPORT ContextFactory {
virtual scoped_refptr<viz::ContextProvider> virtual scoped_refptr<viz::ContextProvider>
SharedMainThreadContextProvider() = 0; SharedMainThreadContextProvider() = 0;
// Return a reference to a shared offscreen context provider usable from the
// main thread.
virtual scoped_refptr<viz::RasterContextProvider>
SharedMainThreadRasterContextProvider() = 0;
// Destroys per-compositor data. // Destroys per-compositor data.
virtual void RemoveCompositor(Compositor* compositor) = 0; virtual void RemoveCompositor(Compositor* compositor) = 0;
......
...@@ -51,6 +51,11 @@ FakeContextFactory::SharedMainThreadContextProvider() { ...@@ -51,6 +51,11 @@ FakeContextFactory::SharedMainThreadContextProvider() {
return nullptr; return nullptr;
} }
scoped_refptr<viz::RasterContextProvider>
FakeContextFactory::SharedMainThreadRasterContextProvider() {
return nullptr;
}
void FakeContextFactory::RemoveCompositor(ui::Compositor* compositor) { void FakeContextFactory::RemoveCompositor(ui::Compositor* compositor) {
frame_sink_ = nullptr; frame_sink_ = nullptr;
} }
......
...@@ -35,6 +35,8 @@ class FakeContextFactory : public ui::ContextFactory { ...@@ -35,6 +35,8 @@ class FakeContextFactory : public ui::ContextFactory {
base::WeakPtr<ui::Compositor> compositor) override; base::WeakPtr<ui::Compositor> compositor) override;
scoped_refptr<viz::ContextProvider> SharedMainThreadContextProvider() scoped_refptr<viz::ContextProvider> SharedMainThreadContextProvider()
override; override;
scoped_refptr<viz::RasterContextProvider>
SharedMainThreadRasterContextProvider() override;
void RemoveCompositor(ui::Compositor* compositor) override; void RemoveCompositor(ui::Compositor* compositor) override;
gpu::GpuMemoryBufferManager* GetGpuMemoryBufferManager() override; gpu::GpuMemoryBufferManager* GetGpuMemoryBufferManager() override;
cc::TaskGraphRunner* GetTaskGraphRunner() override; cc::TaskGraphRunner* GetTaskGraphRunner() override;
......
...@@ -311,6 +311,14 @@ InProcessContextFactory::SharedMainThreadContextProvider() { ...@@ -311,6 +311,14 @@ InProcessContextFactory::SharedMainThreadContextProvider() {
return shared_main_thread_contexts_; return shared_main_thread_contexts_;
} }
scoped_refptr<viz::RasterContextProvider>
InProcessContextFactory::SharedMainThreadRasterContextProvider() {
SharedMainThreadContextProvider();
DCHECK(!shared_main_thread_contexts_ ||
shared_main_thread_contexts_->RasterInterface());
return shared_main_thread_contexts_;
}
void InProcessContextFactory::RemoveCompositor(Compositor* compositor) { void InProcessContextFactory::RemoveCompositor(Compositor* compositor) {
auto it = per_compositor_data_.find(compositor); auto it = per_compositor_data_.find(compositor);
if (it == per_compositor_data_.end()) if (it == per_compositor_data_.end())
......
...@@ -65,6 +65,9 @@ class InProcessContextFactory : public ContextFactory, ...@@ -65,6 +65,9 @@ class InProcessContextFactory : public ContextFactory,
scoped_refptr<viz::ContextProvider> SharedMainThreadContextProvider() scoped_refptr<viz::ContextProvider> SharedMainThreadContextProvider()
override; override;
scoped_refptr<viz::RasterContextProvider>
SharedMainThreadRasterContextProvider() override;
void RemoveCompositor(Compositor* compositor) override; void RemoveCompositor(Compositor* compositor) override;
gpu::GpuMemoryBufferManager* GetGpuMemoryBufferManager() override; gpu::GpuMemoryBufferManager* GetGpuMemoryBufferManager() override;
cc::TaskGraphRunner* GetTaskGraphRunner() override; cc::TaskGraphRunner* GetTaskGraphRunner() override;
......
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