Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(302)

Unified Diff: cc/resources/resource_helper.cc

Issue 375303002: cc: Refactor ResourceProvider. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: cc/resources/resource_helper.cc
diff --git a/cc/resources/resource_helper.cc b/cc/resources/resource_helper.cc
new file mode 100644
index 0000000000000000000000000000000000000000..63c150e061d6334e95e82acea0a923a02cd2b5e6
--- /dev/null
+++ b/cc/resources/resource_helper.cc
@@ -0,0 +1,102 @@
+// Copyright 2012 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 "cc/resources/resource_helper.h"
+
+#include "gpu/GLES2/gl2extchromium.h"
+#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"
+
+using gpu::gles2::GLES2Interface;
+
+namespace cc {
+
+ResourceHelper::ResourceHelper(OutputSurface* output_surface)
+ : output_surface_(output_surface) {
+}
+
+ResourceHelper::~ResourceHelper() {
+}
+
+ResourceHelper::ScopedGpuRaster::ScopedGpuRaster(
+ ResourceHelper* resource_helper)
+ : resource_helper_(resource_helper) {
+ BeginGpuRaster();
+}
+
+ResourceHelper::ScopedGpuRaster::~ScopedGpuRaster() {
+ EndGpuRaster();
+}
+
+void ResourceHelper::Flush() {
+ DCHECK(thread_checker_.CalledOnValidThread());
+ GLES2Interface* gl = this->ContextGL();
+ if (gl)
+ gl->Flush();
+}
+
+void ResourceHelper::Finish() {
+ DCHECK(thread_checker_.CalledOnValidThread());
+ GLES2Interface* gl = this->ContextGL();
+ if (gl)
+ gl->Finish();
+}
+
+bool ResourceHelper::ShallowFlushIfSupported() {
+ DCHECK(thread_checker_.CalledOnValidThread());
+ GLES2Interface* gl = this->ContextGL();
+ if (!gl)
+ return false;
+
+ gl->ShallowFlushCHROMIUM();
+ return true;
+}
+
+GLint ResourceHelper::GetActiveTextureUnit(GLES2Interface* gl) {
+ GLint active_unit = 0;
+ gl->GetIntegerv(GL_ACTIVE_TEXTURE, &active_unit);
+ return active_unit;
+}
+
+GLES2Interface* ResourceHelper::ContextGL() const {
+ ContextProvider* context_provider = output_surface_->context_provider();
+ return context_provider ? context_provider->ContextGL() : NULL;
+}
+
+class GrContext* ResourceHelper::GrContext() const {
+ ContextProvider* context_provider = output_surface_->context_provider();
+ return context_provider ? context_provider->GrContext() : NULL;
+}
+
+void ResourceHelper::ScopedGpuRaster::BeginGpuRaster() {
+ GLES2Interface* gl = resource_helper_->ContextGL();
+ DCHECK(gl);
+
+ // TODO(alokp): Use a trace macro to push/pop markers.
+ // Using push/pop functions directly incurs cost to evaluate function
+ // arguments even when tracing is disabled.
+ gl->PushGroupMarkerEXT(0, "GpuRasterization");
+
+ class GrContext* gr_context = resource_helper_->GrContext();
+ if (gr_context)
+ gr_context->resetContext();
+}
+
+void ResourceHelper::ScopedGpuRaster::EndGpuRaster() {
+ GLES2Interface* gl = resource_helper_->ContextGL();
+ DCHECK(gl);
+
+ class GrContext* gr_context = resource_helper_->GrContext();
+ if (gr_context)
+ gr_context->flush();
+
+ // TODO(alokp): Use a trace macro to push/pop markers.
+ // Using push/pop functions directly incurs cost to evaluate function
+ // arguments even when tracing is disabled.
+ gl->PopGroupMarkerEXT();
+}
+
+} // namespace cc

Powered by Google App Engine
This is Rietveld 408576698