[go: nahoru, domu]

cc: Guard GrContext access for upload tasks in the GPU image cache.

The RasterInterface should be notified when accessing the GrContext, so
it can make sure any state tracked in the implementation is reset if it
could be modified by using the GrContext. We are already doing this for
raster tasks in GpuRasterBufferProvider, also do this in upload tasks
which use the GrContext for uploading images.

R=ericrk@chromium.org

Bug: 870317
Cq-Include-Trybots: luci.chromium.try:android_optional_gpu_tests_rel;master.tryserver.blink:linux_trusty_blink_rel
Change-Id: I2b5039f2a2f64fb6986181639b81597c741103a5
Reviewed-on: https://chromium-review.googlesource.com/1175415
Commit-Queue: Khushal <khushalsagar@chromium.org>
Reviewed-by: Eric Karl <ericrk@chromium.org>
Cr-Commit-Position: refs/heads/master@{#583188}
diff --git a/cc/BUILD.gn b/cc/BUILD.gn
index ea03f18..793b33e 100644
--- a/cc/BUILD.gn
+++ b/cc/BUILD.gn
@@ -158,6 +158,7 @@
     "raster/raster_source.h",
     "raster/scoped_gpu_raster.cc",
     "raster/scoped_gpu_raster.h",
+    "raster/scoped_grcontext_access.h",
     "raster/single_thread_task_graph_runner.cc",
     "raster/single_thread_task_graph_runner.h",
     "raster/staging_buffer_pool.cc",
diff --git a/cc/raster/gpu_raster_buffer_provider.cc b/cc/raster/gpu_raster_buffer_provider.cc
index 3ec38df..3db004cf 100644
--- a/cc/raster/gpu_raster_buffer_provider.cc
+++ b/cc/raster/gpu_raster_buffer_provider.cc
@@ -18,6 +18,7 @@
 #include "cc/paint/paint_recorder.h"
 #include "cc/raster/raster_source.h"
 #include "cc/raster/scoped_gpu_raster.h"
+#include "cc/raster/scoped_grcontext_access.h"
 #include "components/viz/client/client_resource_provider.h"
 #include "components/viz/common/gpu/context_provider.h"
 #include "components/viz/common/gpu/raster_context_provider.h"
@@ -164,24 +165,6 @@
   ri->DeleteTextures(1, &texture_id);
 }
 
-// The following class is needed to correctly reset GL state when rendering to
-// SkCanvases with a GrContext on a RasterInterface enabled context.
-class ScopedGrContextAccess {
- public:
-  explicit ScopedGrContextAccess(viz::RasterContextProvider* context_provider)
-      : context_provider_(context_provider) {
-    gpu::raster::RasterInterface* ri = context_provider_->RasterInterface();
-    ri->BeginGpuRaster();
-  }
-  ~ScopedGrContextAccess() {
-    gpu::raster::RasterInterface* ri = context_provider_->RasterInterface();
-    ri->EndGpuRaster();
-  }
-
- private:
-  viz::RasterContextProvider* context_provider_;
-};
-
 static void RasterizeSource(
     const RasterSource* raster_source,
     bool resource_has_previous_content,
diff --git a/cc/raster/scoped_grcontext_access.h b/cc/raster/scoped_grcontext_access.h
new file mode 100644
index 0000000..ff10d5b
--- /dev/null
+++ b/cc/raster/scoped_grcontext_access.h
@@ -0,0 +1,29 @@
+// 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 CC_RASTER_SCOPED_GRCONTEXT_ACCESS_H_
+#define CC_RASTER_SCOPED_GRCONTEXT_ACCESS_H_
+
+#include "components/viz/common/gpu/raster_context_provider.h"
+#include "gpu/command_buffer/client/raster_interface.h"
+
+// The following class is needed to correctly reset GL state when using a
+// GrContext on a RasterInterface enabled context.
+class ScopedGrContextAccess {
+ public:
+  explicit ScopedGrContextAccess(viz::RasterContextProvider* context_provider)
+      : context_provider_(context_provider) {
+    gpu::raster::RasterInterface* ri = context_provider_->RasterInterface();
+    ri->BeginGpuRaster();
+  }
+  ~ScopedGrContextAccess() {
+    gpu::raster::RasterInterface* ri = context_provider_->RasterInterface();
+    ri->EndGpuRaster();
+  }
+
+ private:
+  viz::RasterContextProvider* context_provider_;
+};
+
+#endif  // CC_RASTER_SCOPED_GRCONTEXT_ACCESS_H_
diff --git a/cc/tiles/gpu_image_decode_cache.cc b/cc/tiles/gpu_image_decode_cache.cc
index 747f1a3..3cc88536 100644
--- a/cc/tiles/gpu_image_decode_cache.cc
+++ b/cc/tiles/gpu_image_decode_cache.cc
@@ -19,6 +19,7 @@
 #include "cc/base/devtools_instrumentation.h"
 #include "cc/base/histograms.h"
 #include "cc/paint/image_transfer_cache_entry.h"
+#include "cc/raster/scoped_grcontext_access.h"
 #include "cc/raster/tile_task.h"
 #include "cc/tiles/mipmap_util.h"
 #include "components/viz/common/gpu/raster_context_provider.h"
@@ -1111,7 +1112,11 @@
   if (context_->GetLock())
     context_lock.emplace(context_);
 
+  base::Optional<ScopedGrContextAccess> gr_context_access;
+  if (!use_transfer_cache_)
+    gr_context_access.emplace(context_);
   base::AutoLock lock(lock_);
+
   ImageData* image_data = GetImageDataForDrawImage(
       draw_image, InUseCacheKey::FromDrawImage(draw_image));
   DCHECK(image_data);