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

Unified Diff: components/mus/gles2/gl_helper.cc

Issue 1848033006: Mus version of GLHelper (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fixed deps Created 4 years, 8 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
« no previous file with comments | « components/mus/gles2/gl_helper.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/mus/gles2/gl_helper.cc
diff --git a/components/mus/gles2/gl_helper.cc b/components/mus/gles2/gl_helper.cc
new file mode 100644
index 0000000000000000000000000000000000000000..bbfef3f8807e5dd59b4b40551f7c547671db6ccb
--- /dev/null
+++ b/components/mus/gles2/gl_helper.cc
@@ -0,0 +1,108 @@
+// Copyright (c) 2016 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/mus/gles2/gl_helper.h"
+
+#include "base/macros.h"
+#include "third_party/skia/include/core/SkRect.h"
+#include "third_party/skia/include/core/SkRegion.h"
+
+namespace mus {
+
+namespace {
+
+class ScopedGLuint {
+ public:
+ typedef void (gpu::gles2::GLES2Interface::*GenFunc)(GLsizei n, GLuint* ids);
+ typedef void (gpu::gles2::GLES2Interface::*DeleteFunc)(GLsizei n,
+ const GLuint* ids);
+ ScopedGLuint(gpu::gles2::GLES2Interface* gl,
+ GenFunc gen_func,
+ DeleteFunc delete_func)
+ : gl_(gl), id_(0u), delete_func_(delete_func) {
+ (gl_->*gen_func)(1, &id_);
+ }
+
+ operator GLuint() const { return id_; }
+
+ GLuint id() const { return id_; }
+
+ ~ScopedGLuint() {
+ if (id_ != 0) {
+ (gl_->*delete_func_)(1, &id_);
+ }
+ }
+
+ private:
+ gpu::gles2::GLES2Interface* gl_;
+ GLuint id_;
+ DeleteFunc delete_func_;
+
+ DISALLOW_COPY_AND_ASSIGN(ScopedGLuint);
+};
+
+class ScopedFramebuffer : public ScopedGLuint {
+ public:
+ explicit ScopedFramebuffer(gpu::gles2::GLES2Interface* gl)
+ : ScopedGLuint(gl,
+ &gpu::gles2::GLES2Interface::GenFramebuffers,
+ &gpu::gles2::GLES2Interface::DeleteFramebuffers) {}
+};
+
+template <GLenum Target>
+class ScopedBinder {
+ public:
+ typedef void (gpu::gles2::GLES2Interface::*BindFunc)(GLenum target,
+ GLuint id);
+ ScopedBinder(gpu::gles2::GLES2Interface* gl, GLuint id, BindFunc bind_func)
+ : gl_(gl), bind_func_(bind_func) {
+ (gl_->*bind_func_)(Target, id);
+ }
+
+ virtual ~ScopedBinder() { (gl_->*bind_func_)(Target, 0); }
+
+ private:
+ gpu::gles2::GLES2Interface* gl_;
+ BindFunc bind_func_;
+
+ DISALLOW_COPY_AND_ASSIGN(ScopedBinder);
+};
+
+template <GLenum Target>
+class ScopedFramebufferBinder : ScopedBinder<Target> {
+ public:
+ ScopedFramebufferBinder(gpu::gles2::GLES2Interface* gl, GLuint id)
+ : ScopedBinder<Target>(gl,
+ id,
+ &gpu::gles2::GLES2Interface::BindFramebuffer) {}
+};
+
+} // namespace
+
+// Cribbed from content/common/gpu/client/gl_helper.cc
+void GLCopySubBufferDamage(gpu::gles2::GLES2Interface* gl,
+ GLenum target,
+ GLuint texture,
+ GLuint previous_texture,
+ const SkRegion& new_damage,
+ const SkRegion& old_damage) {
+ SkRegion region(old_damage);
+ if (region.op(new_damage, SkRegion::kDifference_Op)) {
+ ScopedFramebuffer dst_framebuffer(gl);
+ ScopedFramebufferBinder<GL_FRAMEBUFFER> framebuffer_binder(gl,
+ dst_framebuffer);
+ gl->BindTexture(target, texture);
+ gl->FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, target,
+ previous_texture, 0);
+ for (SkRegion::Iterator it(region); !it.done(); it.next()) {
+ const SkIRect& rect = it.rect();
+ gl->CopyTexSubImage2D(target, 0, rect.x(), rect.y(), rect.x(), rect.y(),
+ rect.width(), rect.height());
+ }
+ gl->BindTexture(target, 0);
+ gl->Flush();
+ }
+}
+
+} // namespace mus
« no previous file with comments | « components/mus/gles2/gl_helper.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698