Skip to content

Commit 65953da

Browse files
committed
Multi-Project Commit: Move of filterfw out of system/media (2 of 7)
This is part of the multi-project commit to move the filter-framework from system/media/mca to frameworks/base/media/mca. Note that the filter-framework will soon be replaced with a refactored version currently under API review (also to go under frameworks/base). This move is done now to unblock the PDK efforts. Change-Id: I9f42be5a12a9e8157512be11f04e38e4548970be
1 parent 80e4ee4 commit 65953da

File tree

246 files changed

+31005
-5
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

246 files changed

+31005
-5
lines changed

Android.mk

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -324,9 +324,6 @@ fwbase_dirs_to_document := \
324324
# include definition of libcore_to_document
325325
include $(LOCAL_PATH)/../../libcore/Docs.mk
326326

327-
# include definition of libfilterfw_to_document
328-
include $(LOCAL_PATH)/../../system/media/mca/Docs.mk
329-
330327
non_base_dirs := \
331328
../../external/apache-http/src/org/apache/http
332329

@@ -349,8 +346,7 @@ html_dirs := \
349346
# Common sources for doc check and api check
350347
common_src_files := \
351348
$(call find-other-html-files, $(html_dirs)) \
352-
$(addprefix ../../libcore/, $(call libcore_to_document, $(LOCAL_PATH)/../../libcore)) \
353-
$(addprefix ../../system/media/mca/, $(call libfilterfw_to_document, $(LOCAL_PATH)/../../system/media/mca)) \
349+
$(addprefix ../../libcore/, $(call libcore_to_document, $(LOCAL_PATH)/../../libcore))
354350

355351
# These are relative to frameworks/base
356352
framework_docs_LOCAL_SRC_FILES := \

media/mca/Android.mk

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Copyright (C) 2011 The Android Open Source Project
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
#
15+
16+
#
17+
# Build all native libraries
18+
#
19+
include $(call all-subdir-makefiles)
20+
21+
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
/*
2+
* Copyright (C) 2011 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
18+
package android.media.effect;
19+
20+
21+
/**
22+
* <p>Effects are high-performance transformations that can be applied to image frames. These are
23+
* passed in the form of OpenGL ES 2.0 texture names. Typical frames could be images loaded from
24+
* disk, or frames from the camera or other video streams.</p>
25+
*
26+
* <p>To create an Effect you must first create an EffectContext. You can obtain an instance of the
27+
* context's EffectFactory by calling
28+
* {@link android.media.effect.EffectContext#getFactory() getFactory()}. The EffectFactory allows
29+
* you to instantiate specific Effects.</p>
30+
*
31+
* <p>The application is responsible for creating an EGL context, and making it current before
32+
* applying an effect. An effect is bound to a single EffectContext, which in turn is bound to a
33+
* single EGL context. If your EGL context is destroyed, the EffectContext becomes invalid and any
34+
* effects bound to this context can no longer be used.</p>
35+
*
36+
*/
37+
public abstract class Effect {
38+
39+
/**
40+
* Get the effect name.
41+
*
42+
* Returns the unique name of the effect, which matches the name used for instantiating this
43+
* effect by the EffectFactory.
44+
*
45+
* @return The name of the effect.
46+
*/
47+
public abstract String getName();
48+
49+
/**
50+
* Apply an effect to GL textures.
51+
*
52+
* <p>Apply the Effect on the specified input GL texture, and write the result into the
53+
* output GL texture. The texture names passed must be valid in the current GL context.</p>
54+
*
55+
* <p>The input texture must be a valid texture name with the given width and height and must be
56+
* bound to a GL_TEXTURE_2D texture image (usually done by calling the glTexImage2D() function).
57+
* Multiple mipmap levels may be provided.</p>
58+
*
59+
* <p>If the output texture has not been bound to a texture image, it will be automatically
60+
* bound by the effect as a GL_TEXTURE_2D. It will contain one mipmap level (0), which will have
61+
* the same size as the input. No other mipmap levels are defined. If the output texture was
62+
* bound already, and its size does not match the input texture size, the result may be clipped
63+
* or only partially fill the texture.</p>
64+
*
65+
* <p>Note, that regardless of whether a texture image was originally provided or not, both the
66+
* input and output textures are owned by the caller. That is, the caller is responsible for
67+
* calling glDeleteTextures() to deallocate the input and output textures.</p>
68+
*
69+
* @param inputTexId The GL texture name of a valid and bound input texture.
70+
* @param width The width of the input texture in pixels.
71+
* @param height The height of the input texture in pixels.
72+
* @param outputTexId The GL texture name of the output texture.
73+
*/
74+
public abstract void apply(int inputTexId, int width, int height, int outputTexId);
75+
76+
/**
77+
* Set a filter parameter.
78+
*
79+
* Consult the effect documentation for a list of supported parameter keys for each effect.
80+
*
81+
* @param parameterKey The name of the parameter to adjust.
82+
* @param value The new value to set the parameter to.
83+
* @throws InvalidArgumentException if parameterName is not a recognized name, or the value is
84+
* not a valid value for this parameter.
85+
*/
86+
public abstract void setParameter(String parameterKey, Object value);
87+
88+
/**
89+
* Set an effect listener.
90+
*
91+
* Some effects may report state changes back to the host, if a listener is set. Consult the
92+
* individual effect documentation for more details.
93+
*
94+
* @param listener The listener to receive update callbacks on.
95+
*/
96+
public void setUpdateListener(EffectUpdateListener listener) {
97+
}
98+
99+
/**
100+
* Release an effect.
101+
*
102+
* <p>Releases the effect and any resources associated with it. You may call this if you need to
103+
* make sure acquired resources are no longer held by the effect. Releasing an effect makes it
104+
* invalid for reuse.</p>
105+
*
106+
* <p>Note that this method must be called with the EffectContext and EGL context current, as
107+
* the effect may release internal GL resources.</p>
108+
*/
109+
public abstract void release();
110+
}
111+
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
/*
2+
* Copyright (C) 2011 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
18+
package android.media.effect;
19+
20+
import android.filterfw.core.CachedFrameManager;
21+
import android.filterfw.core.FilterContext;
22+
import android.filterfw.core.FilterFactory;
23+
import android.filterfw.core.GLEnvironment;
24+
import android.filterfw.core.GLFrame;
25+
import android.filterfw.core.FrameManager;
26+
import android.opengl.GLES20;
27+
28+
/**
29+
* <p>An EffectContext keeps all necessary state information to run Effects within a Open GL ES 2.0
30+
* context.</p>
31+
*
32+
* <p>Every EffectContext is bound to one GL context. The application is responsible for creating
33+
* this EGL context, and making it current before applying any effect. If your EGL context is
34+
* destroyed, the EffectContext becomes invalid and any effects bound to this context can no longer
35+
* be used. If you switch to another EGL context, you must create a new EffectContext. Each Effect
36+
* is bound to a single EffectContext, and can only be executed in that context.</p>
37+
*/
38+
public class EffectContext {
39+
40+
private final int GL_STATE_FBO = 0;
41+
private final int GL_STATE_PROGRAM = 1;
42+
private final int GL_STATE_ARRAYBUFFER = 2;
43+
private final int GL_STATE_COUNT = 3;
44+
45+
FilterContext mFilterContext;
46+
47+
private EffectFactory mFactory;
48+
49+
private int[] mOldState = new int[GL_STATE_COUNT];
50+
51+
/**
52+
* Creates a context within the current GL context.
53+
*
54+
* <p>Binds the EffectContext to the current OpenGL context. All subsequent calls to the
55+
* EffectContext must be made in the GL context that was active during creation.
56+
* When you have finished using a context, you must call {@link #release()}. to dispose of all
57+
* resources associated with this context.</p>
58+
*/
59+
public static EffectContext createWithCurrentGlContext() {
60+
EffectContext result = new EffectContext();
61+
result.initInCurrentGlContext();
62+
return result;
63+
}
64+
65+
/**
66+
* Returns the EffectFactory for this context.
67+
*
68+
* <p>The EffectFactory returned from this method allows instantiating new effects within this
69+
* context.</p>
70+
*
71+
* @return The EffectFactory instance for this context.
72+
*/
73+
public EffectFactory getFactory() {
74+
return mFactory;
75+
}
76+
77+
/**
78+
* Releases the context.
79+
*
80+
* <p>Releases all the resources and effects associated with the EffectContext. This renders the
81+
* context and all the effects bound to this context invalid. You must no longer use the context
82+
* or any of its bound effects after calling release().</p>
83+
*
84+
* <p>Note that this method must be called with the proper EGL context made current, as the
85+
* EffectContext and its effects may release internal GL resources.</p>
86+
*/
87+
public void release() {
88+
mFilterContext.tearDown();
89+
mFilterContext = null;
90+
}
91+
92+
private EffectContext() {
93+
mFilterContext = new FilterContext();
94+
mFilterContext.setFrameManager(new CachedFrameManager());
95+
mFactory = new EffectFactory(this);
96+
}
97+
98+
private void initInCurrentGlContext() {
99+
if (!GLEnvironment.isAnyContextActive()) {
100+
throw new RuntimeException("Attempting to initialize EffectContext with no active "
101+
+ "GL context!");
102+
}
103+
GLEnvironment glEnvironment = new GLEnvironment();
104+
glEnvironment.initWithCurrentContext();
105+
mFilterContext.initGLEnvironment(glEnvironment);
106+
}
107+
108+
final void assertValidGLState() {
109+
GLEnvironment glEnv = mFilterContext.getGLEnvironment();
110+
if (glEnv == null || !glEnv.isContextActive()) {
111+
if (GLEnvironment.isAnyContextActive()) {
112+
throw new RuntimeException("Applying effect in wrong GL context!");
113+
} else {
114+
throw new RuntimeException("Attempting to apply effect without valid GL context!");
115+
}
116+
}
117+
}
118+
119+
final void saveGLState() {
120+
GLES20.glGetIntegerv(GLES20.GL_FRAMEBUFFER_BINDING, mOldState, GL_STATE_FBO);
121+
GLES20.glGetIntegerv(GLES20.GL_CURRENT_PROGRAM, mOldState, GL_STATE_PROGRAM);
122+
GLES20.glGetIntegerv(GLES20.GL_ARRAY_BUFFER_BINDING, mOldState, GL_STATE_ARRAYBUFFER);
123+
}
124+
125+
final void restoreGLState() {
126+
GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, mOldState[GL_STATE_FBO]);
127+
GLES20.glUseProgram(mOldState[GL_STATE_PROGRAM]);
128+
GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, mOldState[GL_STATE_ARRAYBUFFER]);
129+
}
130+
}
131+

0 commit comments

Comments
 (0)