1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef UI_GL_ANDROID_SCOPED_JAVA_SURFACE_H_
6 #define UI_GL_ANDROID_SCOPED_JAVA_SURFACE_H_
10 #include "base/android/scoped_java_ref.h"
11 #include "base/move.h"
12 #include "ui/gl/gl_export.h"
18 // A helper class for holding a scoped reference to a Java Surface instance.
19 // When going out of scope, Surface.release() is called on the Java object to
20 // make sure server-side references (esp. wrt graphics memory) are released.
21 class GL_EXPORT ScopedJavaSurface
{
22 MOVE_ONLY_TYPE_FOR_CPP_03(ScopedJavaSurface
, RValue
);
27 // Wraps an existing Java Surface object in a ScopedJavaSurface.
28 explicit ScopedJavaSurface(const base::android::JavaRef
<jobject
>& surface
);
30 // Creates a Java Surface from a SurfaceTexture and wraps it in a
32 explicit ScopedJavaSurface(const SurfaceTexture
* surface_texture
);
34 // Move constructor. Take the surface from another ScopedJavaSurface object,
35 // the latter no longer owns the surface afterwards.
36 ScopedJavaSurface(RValue rvalue
);
37 ScopedJavaSurface
& operator=(RValue rhs
);
39 // Creates a ScopedJavaSurface that is owned externally, i.e.,
40 // someone else is responsible to call Surface.release().
41 static ScopedJavaSurface
AcquireExternalSurface(jobject surface
);
45 // Check whether the surface is an empty one.
48 // Check whether the surface is hardware protected so that no readback is
50 bool is_protected() const { return is_protected_
; }
52 const base::android::JavaRef
<jobject
>& j_surface() const {
57 // Performs destructive move from |other| to this.
58 void MoveFrom(ScopedJavaSurface
& other
);
63 base::android::ScopedJavaGlobalRef
<jobject
> j_surface_
;
68 #endif // UI_GL_ANDROID_SCOPED_JAVA_SURFACE_H_