Skip to content

Commit

Permalink
Use new GrDirectContext factories instead of deprecated GrContext ones
Browse files Browse the repository at this point in the history
GrContext is going away (to be replaced with a GrDirectContext/
GrRecordingContext pair). This transitions Chromium over to using
the GrDirectContext factories to create the direct contexts it uses.

Skia's GrContext, in the past, was a catch-all location that stored
information for Skia's GPU backend (e.g., resource caches) and provided
services that required access to the GPU (e.g., creation of backend
textures, flushing, etc.). In the new world, most of these capabilities
are being moved to the GrDirectContext - which has _direct_ access
to the GPU. The GrRecordingContext is a weaker context that lacks
access to the GPU and thus can't provide some of the services of the
old GrContext. The GrRecordingContext gains relevance when DDL
recording. In that mode, both clients and Skia's GPU backend require
some of the services of a context (e.g., memory storage for Skia's
internal operations, access to the GPU capability information and
some thread safe caches).

Here is my thinking wrt reviewers (lines w/ '--' are done/covered):

alcooper         chrome/browser/vr
-- blundell@     services
-- chcunningham@ media
chrishtr@        third_party/blink
-- dalecurtis@   media
-- dcastagna     components/exo
-- fmalita@      skia
-- jam@          content                  services
-- jochen@       content                  third_party/blink
oshima@          components/exo
-- penghuang@    gpu
-- rjkroege@     ui/ozone
-- spang@        ui/ozone
-- vasilyt@      android_webview/browser
-- vmpstr@       cc/layers                components/viz
-- vollick@      ui/compositor

Change-Id: I70d16e2d98cfda8d5f9b6f2492b3292500df4471
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2297920
Commit-Queue: Robert Phillips <robertphillips@google.com>
Reviewed-by: Alexander Cooper <alcooper@chromium.org>
Reviewed-by: Ian Vollick <vollick@chromium.org>
Reviewed-by: Chrome Cunningham <chcunningham@chromium.org>
Reviewed-by: Daniele Castagna <dcastagna@chromium.org>
Reviewed-by: Jochen Eisinger <jochen@chromium.org>
Reviewed-by: John Abd-El-Malek <jam@chromium.org>
Reviewed-by: Dale Curtis <dalecurtis@chromium.org>
Reviewed-by: Michael Spang <spang@chromium.org>
Reviewed-by: Robert Kroeger <rjkroege@chromium.org>
Reviewed-by: vmpstr <vmpstr@chromium.org>
Reviewed-by: Peng Huang <penghuang@chromium.org>
Reviewed-by: Vasiliy Telezhnikov <vasilyt@chromium.org>
Reviewed-by: Florin Malita <fmalita@chromium.org>
Cr-Commit-Position: refs/heads/master@{#792721}
  • Loading branch information
rphilli authored and Commit Bot committed Jul 29, 2020
1 parent d82a651 commit dbb0b7d
Show file tree
Hide file tree
Showing 84 changed files with 203 additions and 168 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include "gpu/config/gpu_feature_info.h"
#include "gpu/ipc/gl_in_process_context.h"
#include "gpu/skia_bindings/gl_bindings_skia_cmd_buffer.h"
#include "third_party/skia/include/gpu/GrContext.h"
#include "third_party/skia/include/gpu/GrDirectContext.h"
#include "third_party/skia/include/gpu/gl/GrGLInterface.h"

namespace android_webview {
Expand Down Expand Up @@ -135,15 +135,15 @@ gpu::ContextSupport* AwRenderThreadContextProvider::ContextSupport() {
return context_->GetImplementation();
}

class GrContext* AwRenderThreadContextProvider::GrContext() {
class GrDirectContext* AwRenderThreadContextProvider::GrContext() {
DCHECK(main_thread_checker_.CalledOnValidThread());

if (gr_context_)
return gr_context_.get();

sk_sp<GrGLInterface> interface(skia_bindings::CreateGLES2InterfaceBindings(
ContextGL(), ContextSupport()));
gr_context_ = GrContext::MakeGL(std::move(interface));
gr_context_ = GrDirectContext::MakeGL(std::move(interface));
cache_controller_->SetGrContext(gr_context_.get());
return gr_context_.get();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include "components/viz/common/gpu/context_provider.h"
#include "gpu/ipc/in_process_command_buffer.h"
#include "third_party/skia/include/core/SkRefCnt.h"
#include "third_party/skia/include/gpu/GrContext.h"
#include "third_party/skia/include/gpu/GrDirectContext.h"

namespace gl {
class GLSurface;
Expand Down Expand Up @@ -50,7 +50,7 @@ class AwRenderThreadContextProvider
const gpu::GpuFeatureInfo& GetGpuFeatureInfo() const override;
gpu::gles2::GLES2Interface* ContextGL() override;
gpu::ContextSupport* ContextSupport() override;
class GrContext* GrContext() override;
class GrDirectContext* GrContext() override;
gpu::SharedImageInterface* SharedImageInterface() override;
viz::ContextCacheController* CacheController() override;
base::Lock* GetLock() override;
Expand All @@ -71,7 +71,7 @@ class AwRenderThreadContextProvider

std::unique_ptr<gpu::GLInProcessContext> context_;
std::unique_ptr<gpu::gles2::GLES2TraceImplementation> trace_impl_;
sk_sp<class GrContext> gr_context_;
sk_sp<class GrDirectContext> gr_context_;
std::unique_ptr<viz::ContextCacheController> cache_controller_;

base::ObserverList<viz::ContextLostObserver>::Unchecked observers_;
Expand Down
6 changes: 3 additions & 3 deletions android_webview/browser/gfx/aw_vulkan_context_provider.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include "gpu/vulkan/vulkan_fence_helper.h"
#include "gpu/vulkan/vulkan_function_pointers.h"
#include "gpu/vulkan/vulkan_util.h"
#include "third_party/skia/include/gpu/GrContext.h"
#include "third_party/skia/include/gpu/GrDirectContext.h"
#include "third_party/skia/include/gpu/vk/GrVkBackendContext.h"
#include "third_party/skia/include/gpu/vk/GrVkExtensions.h"

Expand Down Expand Up @@ -104,7 +104,7 @@ gpu::VulkanDeviceQueue* AwVulkanContextProvider::GetDeviceQueue() {
return device_queue_.get();
}

GrContext* AwVulkanContextProvider::GetGrContext() {
GrDirectContext* AwVulkanContextProvider::GetGrContext() {
return gr_context_.get();
}

Expand Down Expand Up @@ -178,7 +178,7 @@ bool AwVulkanContextProvider::Initialize(AwDrawFn_InitVkParams* params) {
.fGetProc = get_proc,
.fOwnsInstanceAndDevice = false,
};
gr_context_ = GrContext::MakeVulkan(backend_context);
gr_context_ = GrDirectContext::MakeVulkan(backend_context);
if (!gr_context_) {
LOG(ERROR) << "Unable to initialize GrContext.";
return false;
Expand Down
8 changes: 4 additions & 4 deletions android_webview/browser/gfx/aw_vulkan_context_provider.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include "third_party/skia/src/gpu/vk/GrVkSecondaryCBDrawContext.h"

struct AwDrawFn_InitVkParams;
class GrContext;
class GrDirectContext;
class GrVkSecondaryCBDrawContext;

namespace gpu {
Expand Down Expand Up @@ -48,7 +48,7 @@ class AwVulkanContextProvider final : public viz::VulkanContextProvider {
// viz::VulkanContextProvider implementation:
gpu::VulkanImplementation* GetVulkanImplementation() override;
gpu::VulkanDeviceQueue* GetDeviceQueue() override;
GrContext* GetGrContext() override;
GrDirectContext* GetGrContext() override;
GrVkSecondaryCBDrawContext* GetGrSecondaryCBDrawContext() override;
void EnqueueSecondaryCBSemaphores(
std::vector<VkSemaphore> semaphores) override;
Expand All @@ -60,7 +60,7 @@ class AwVulkanContextProvider final : public viz::VulkanContextProvider {
VkDevice device() { return device_queue_->GetVulkanDevice(); }
VkQueue queue() { return device_queue_->GetVulkanQueue(); }
gpu::VulkanImplementation* implementation() { return implementation_.get(); }
GrContext* gr_context() { return gr_context_.get(); }
GrDirectContext* gr_context() { return gr_context_.get(); }

private:
friend class base::RefCounted<AwVulkanContextProvider>;
Expand All @@ -74,7 +74,7 @@ class AwVulkanContextProvider final : public viz::VulkanContextProvider {

std::unique_ptr<gpu::VulkanImplementation> implementation_;
std::unique_ptr<gpu::VulkanDeviceQueue> device_queue_;
sk_sp<GrContext> gr_context_;
sk_sp<GrDirectContext> gr_context_;
sk_sp<GrVkSecondaryCBDrawContext> draw_context_;
std::vector<base::OnceClosure> post_submit_tasks_;
std::vector<VkSemaphore> post_submit_semaphores_;
Expand Down
4 changes: 3 additions & 1 deletion cc/layers/heads_up_display_layer_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <stdint.h>

#include <algorithm>
#include <utility>
#include <vector>

#include "base/logging.h"
Expand Down Expand Up @@ -52,6 +53,7 @@
#include "third_party/skia/include/core/SkPaint.h"
#include "third_party/skia/include/core/SkPath.h"
#include "third_party/skia/include/core/SkTypeface.h"
#include "third_party/skia/include/gpu/GrDirectContext.h"
#include "ui/gfx/geometry/point.h"
#include "ui/gfx/geometry/size.h"
#include "ui/gfx/geometry/size_conversions.h"
Expand Down Expand Up @@ -775,7 +777,7 @@ SkRect HeadsUpDisplayLayerImpl::DrawMemoryDisplay(PaintCanvas* canvas,
int radius = length / 2;
int cx = oval.left() + radius;
int cy = oval.top() + radius;
double angle = ((double)memory_entry_.total_bytes_used /
double angle = (static_cast<double>(memory_entry_.total_bytes_used) /
memory_entry_.total_budget_in_bytes) *
180;

Expand Down
18 changes: 9 additions & 9 deletions cc/paint/image_transfer_cache_entry_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include "third_party/skia/include/core/SkPixmap.h"
#include "third_party/skia/include/core/SkRefCnt.h"
#include "third_party/skia/include/gpu/GrBackendSurface.h"
#include "third_party/skia/include/gpu/GrContext.h"
#include "third_party/skia/include/gpu/GrDirectContext.h"
#include "third_party/skia/include/gpu/GrTypes.h"
#include "third_party/skia/include/gpu/gl/GrGLInterface.h"
#include "third_party/skia/include/gpu/gl/GrGLTypes.h"
Expand Down Expand Up @@ -92,7 +92,7 @@ class ImageTransferCacheEntryTest
ASSERT_TRUE(gl_context_->MakeCurrent(surface_.get()));
sk_sp<GrGLInterface> interface(gl::init::CreateGrGLInterface(
*gl_context_->GetVersionInfo(), false /* use_version_es2 */));
gr_context_ = GrContext::MakeGL(std::move(interface));
gr_context_ = GrDirectContext::MakeGL(std::move(interface));
ASSERT_TRUE(gr_context_);
}

Expand Down Expand Up @@ -157,13 +157,13 @@ class ImageTransferCacheEntryTest
share_group_.reset();
}

GrContext* gr_context() const { return gr_context_.get(); }
GrDirectContext* gr_context() const { return gr_context_.get(); }

private:
// Uploads a texture corresponding to a single plane in a YUV image. All the
// samples in the plane are set to |color|. The texture is not owned by Skia:
// when Skia doesn't need it anymore, MarkTextureAsReleased() will be called.
sk_sp<SkImage> CreateSolidPlane(GrContext* gr_context,
sk_sp<SkImage> CreateSolidPlane(GrDirectContext* gr_context,
int width,
int height,
GrGLenum texture_format,
Expand Down Expand Up @@ -204,7 +204,7 @@ class ImageTransferCacheEntryTest
scoped_refptr<gl::GLSurface> surface_;
scoped_refptr<gl::GLShareGroup> share_group_;
scoped_refptr<gl::GLContext> gl_context_;
sk_sp<GrContext> gr_context_;
sk_sp<GrDirectContext> gr_context_;
gl::DisableNullDrawGLBindings enable_pixel_output_;
};

Expand All @@ -231,8 +231,8 @@ TEST_P(ImageTransferCacheEntryTest, Deserialize) {

void* planes[3];
planes[0] = reinterpret_cast<void*>(planes_data.get());
planes[1] = ((char*)planes[0]) + y_bytes;
planes[2] = ((char*)planes[1]) + uv_bytes;
planes[1] = reinterpret_cast<char*>(planes[0]) + y_bytes;
planes[2] = reinterpret_cast<char*>(planes[1]) + uv_bytes;

auto info = SkImageInfo::Make(image_width, image_height, kGray_8_SkColorType,
kUnknown_SkAlphaType);
Expand Down Expand Up @@ -407,7 +407,7 @@ INSTANTIATE_TEST_SUITE_P(All,

TEST(ImageTransferCacheEntryTestNoYUV, CPUImageWithMips) {
GrMockOptions options;
auto gr_context = GrContext::MakeMock(&options);
auto gr_context = GrDirectContext::MakeMock(&options);

SkBitmap bitmap;
bitmap.allocPixels(
Expand All @@ -433,7 +433,7 @@ TEST(ImageTransferCacheEntryTestNoYUV, CPUImageWithMips) {

TEST(ImageTransferCacheEntryTestNoYUV, CPUImageAddMipsLater) {
GrMockOptions options;
auto gr_context = GrContext::MakeMock(&options);
auto gr_context = GrDirectContext::MakeMock(&options);

SkBitmap bitmap;
bitmap.allocPixels(
Expand Down
4 changes: 3 additions & 1 deletion cc/raster/gpu_raster_buffer_provider.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
#include <stdint.h>

#include <algorithm>
#include <memory>
#include <utility>
#include <vector>

#include "base/logging.h"
#include "base/metrics/histogram_macros.h"
Expand All @@ -34,7 +36,7 @@
#include "gpu/command_buffer/common/shared_image_usage.h"
#include "third_party/skia/include/core/SkPictureRecorder.h"
#include "third_party/skia/include/core/SkSurface.h"
#include "third_party/skia/include/gpu/GrContext.h"
#include "third_party/skia/include/gpu/GrDirectContext.h"
#include "ui/gfx/geometry/axis_transform2d.h"
#include "url/gurl.h"

Expand Down
4 changes: 2 additions & 2 deletions cc/raster/raster_buffer_provider_perftest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/perf/perf_result_reporter.h"
#include "third_party/khronos/GLES2/gl2.h"
#include "third_party/skia/include/gpu/GrContext.h"
#include "third_party/skia/include/gpu/GrDirectContext.h"

namespace cc {
namespace {
Expand Down Expand Up @@ -112,7 +112,7 @@ class PerfContextProvider
return raster_context_.get();
}
gpu::ContextSupport* ContextSupport() override { return &support_; }
class GrContext* GrContext() override {
class GrDirectContext* GrContext() override {
if (!test_context_provider_) {
test_context_provider_ = viz::TestContextProvider::Create();
}
Expand Down
4 changes: 2 additions & 2 deletions cc/raster/scoped_gpu_raster.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include "gpu/command_buffer/client/gles2_interface.h"
#include "third_party/khronos/GLES2/gl2.h"
#include "third_party/khronos/GLES2/gl2ext.h"
#include "third_party/skia/include/gpu/GrContext.h"
#include "third_party/skia/include/gpu/GrDirectContext.h"

using gpu::gles2::GLES2Interface;

Expand All @@ -35,7 +35,7 @@ void ScopedGpuRaster::BeginGpuRaster() {

#if defined(OS_ANDROID)
// TODO(crbug.com/832810): The following reset should not be necessary.
GrContext* gr_context = context_provider_->GrContext();
GrDirectContext* gr_context = context_provider_->GrContext();
gr_context->resetContext();
#endif
}
Expand Down
4 changes: 2 additions & 2 deletions cc/test/skia_common.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include "cc/test/fake_paint_image_generator.h"
#include "third_party/skia/include/core/SkImageGenerator.h"
#include "third_party/skia/include/core/SkPixmap.h"
#include "third_party/skia/include/gpu/GrContext.h"
#include "third_party/skia/include/gpu/GrDirectContext.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/skia_util.h"

Expand Down Expand Up @@ -247,7 +247,7 @@ scoped_refptr<SkottieWrapper> CreateSkottie(const gfx::Size& size,
}

PaintImage CreateNonDiscardablePaintImage(const gfx::Size& size) {
auto context = GrContext::MakeMock(nullptr);
auto context = GrDirectContext::MakeMock(nullptr);
SkBitmap bitmap;
auto info = SkImageInfo::Make(size.width(), size.height(), kN32_SkColorType,
kPremul_SkAlphaType, nullptr /* color_space */);
Expand Down
2 changes: 1 addition & 1 deletion cc/test/test_skcanvas.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ void SaveCountingCanvas::onDrawPaint(const SkPaint& paint) {
}

MockCanvas::MockCanvas() : SkNoDrawCanvas(100, 100) {
context_ = GrContext::MakeMock(nullptr);
context_ = GrDirectContext::MakeMock(nullptr);
}

MockCanvas::~MockCanvas() = default;
Expand Down
5 changes: 3 additions & 2 deletions cc/test/test_skcanvas.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include "testing/gmock/include/gmock/gmock.h"
#include "third_party/skia/include/core/SkCanvas.h"
#include "third_party/skia/include/core/SkPath.h"
#include "third_party/skia/include/gpu/GrContext.h"
#include "third_party/skia/include/gpu/GrDirectContext.h"
#include "third_party/skia/include/utils/SkNoDrawCanvas.h"

namespace cc {
Expand Down Expand Up @@ -47,6 +47,7 @@ class MockCanvas : public SkNoDrawCanvas {
OnDrawRectWithColor(paint.getColor());
}
GrContext* getGrContext() override { return context_.get(); }
GrRecordingContext* recordingContext() override { return context_.get(); }

MOCK_METHOD1(OnDrawPaintWithColor, void(SkColor));
MOCK_METHOD1(OnDrawRectWithColor, void(SkColor));
Expand All @@ -72,7 +73,7 @@ class MockCanvas : public SkNoDrawCanvas {
MOCK_METHOD2(onCustomCallback, void(SkCanvas*, uint32_t));
MOCK_METHOD0(onFlush, void());

sk_sp<GrContext> context_;
sk_sp<GrDirectContext> context_;
};

} // namespace cc
Expand Down
9 changes: 6 additions & 3 deletions cc/test/transfer_cache_test_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,18 @@

#include "cc/test/transfer_cache_test_helper.h"

#include <memory>
#include <utility>

#include "base/check.h"
#include "base/containers/span.h"

namespace cc {

TransferCacheTestHelper::TransferCacheTestHelper(GrContext* context)
TransferCacheTestHelper::TransferCacheTestHelper(GrDirectContext* context)
: context_(context) {
if (!context_) {
owned_context_ = GrContext::MakeMock(nullptr);
owned_context_ = GrDirectContext::MakeMock(nullptr);
context_ = owned_context_.get();
}
}
Expand Down Expand Up @@ -68,7 +71,7 @@ void TransferCacheTestHelper::DeleteEntryDirect(const EntryKey& key) {
entries_.erase(key);
}

void TransferCacheTestHelper::SetGrContext(GrContext* context) {
void TransferCacheTestHelper::SetGrContext(GrDirectContext* context) {
context_ = context;
}

Expand Down
15 changes: 8 additions & 7 deletions cc/test/transfer_cache_test_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,26 @@
#ifndef CC_TEST_TRANSFER_CACHE_TEST_HELPER_H_
#define CC_TEST_TRANSFER_CACHE_TEST_HELPER_H_

#include <limits>
#include <map>
#include <memory>
#include <set>
#include <vector>

#include "base/containers/span.h"
#include "cc/paint/transfer_cache_deserialize_helper.h"
#include "cc/paint/transfer_cache_serialize_helper.h"
#include "third_party/skia/include/gpu/GrContext.h"

class GrContext;
#include "third_party/skia/include/gpu/GrDirectContext.h"

namespace cc {

class TransferCacheTestHelper : public TransferCacheDeserializeHelper,
public TransferCacheSerializeHelper {
public:
explicit TransferCacheTestHelper(GrContext* context = nullptr);
explicit TransferCacheTestHelper(GrDirectContext* context = nullptr);
~TransferCacheTestHelper() override;

void SetGrContext(GrContext* context);
void SetGrContext(GrDirectContext* context);
void SetCachedItemsLimit(size_t limit);

// Direct Access API (simulates ContextSupport methods).
Expand Down Expand Up @@ -59,8 +60,8 @@ class TransferCacheTestHelper : public TransferCacheDeserializeHelper,
std::set<EntryKey> locked_entries_;
EntryKey last_added_entry_ = {TransferCacheEntryType::kRawMemory, ~0};

GrContext* context_ = nullptr;
sk_sp<GrContext> owned_context_;
GrDirectContext* context_ = nullptr;
sk_sp<GrDirectContext> owned_context_;
size_t cached_items_limit_ = std::numeric_limits<size_t>::max();
};

Expand Down
Loading

0 comments on commit dbb0b7d

Please sign in to comment.