Skip to content

Commit 72cd58f

Browse files
committed
Add codes from content_shell
0 parents  commit 72cd58f

103 files changed

Lines changed: 10235 additions & 0 deletions

File tree

Some content is hidden

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

src/DEPS

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
include_rules = [
2+
"+v8/include",
3+
4+
# For chromeos build config
5+
"+chromeos/dbus",
6+
7+
# The content_shell is the canonical sample embedder, so it only uses
8+
# content's public API.
9+
"+content/public",
10+
11+
# The content_shell is an embedder so it must work with resource bundles.
12+
"+ui/base/l10n",
13+
"+ui/base/resource",
14+
15+
# Shell resources
16+
"+grit/net_resources.h",
17+
"+grit/shell_resources.h",
18+
19+
# The content_shell for aura must work with the views and aura
20+
"+ui/aura",
21+
"+ui/views",
22+
]

src/OWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
jochen@chromium.org

src/android/OWNERS

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
jcivelli@chromium.org
2+
satish@chromium.org
3+
tedchoc@chromium.org
4+
jrg@chromium.org
5+
yfriedman@chromium.org

src/android/draw_context.cc

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
// Copyright (c) 2012 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.
4+
5+
#include "content/shell/android/draw_context.h"
6+
7+
#include "base/logging.h"
8+
#include "content/public/browser/android/graphics_context.h"
9+
#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebGraphicsContext3D.h"
10+
11+
namespace {
12+
13+
static const char g_vertex_shader[] =
14+
"attribute vec4 a_Position;"
15+
"attribute vec2 a_texCoord;"
16+
"varying vec2 v_texCoord;"
17+
"void main() {"
18+
" gl_Position = a_Position;"
19+
" v_texCoord = a_texCoord;"
20+
"}";
21+
22+
// Minimal texture mapping pixel shader.
23+
static const char g_fragment_shader[] =
24+
"precision mediump float;"
25+
"varying vec2 v_texCoord;"
26+
"uniform sampler2D s_texture;"
27+
"void main() {"
28+
" gl_FragColor = texture2D(s_texture, v_texCoord);"
29+
"}";
30+
31+
} // anonymous namespace
32+
33+
namespace content {
34+
35+
DrawContext::DrawContext(ANativeWindow* window)
36+
: program_(GL_ZERO),
37+
vertex_shader_(0),
38+
fragment_shader_(0),
39+
texture_uniform_(GL_ZERO),
40+
vertex_buffer_(GL_ZERO),
41+
context_(content::GraphicsContext::CreateForUI(window)) {
42+
const GLfloat attribs[] = {
43+
-1.0f, -1.0f,
44+
1.0f, -1.0f,
45+
-1.0f, 1.0f,
46+
1.0f, 1.0f,
47+
0.0f, 0.0f,
48+
1.0f, 0.0f,
49+
0.0f, 1.0f,
50+
1.0f, 1.0f };
51+
WebKit::WebGraphicsContext3D* context3D = context_->GetContext3D();
52+
vertex_buffer_ = context3D->createBuffer();
53+
context3D->bindBuffer(GL_ARRAY_BUFFER, vertex_buffer_);
54+
context3D->bufferData(GL_ARRAY_BUFFER, 16 * sizeof(GLfloat), attribs,
55+
GL_STATIC_DRAW);
56+
57+
vertex_shader_ = context3D->createShader(GL_VERTEX_SHADER);
58+
context3D->shaderSource(vertex_shader_, g_vertex_shader);
59+
context3D->compileShader(vertex_shader_);
60+
61+
fragment_shader_ = context3D->createShader(GL_FRAGMENT_SHADER);
62+
context3D->shaderSource(fragment_shader_, g_fragment_shader);
63+
context3D->compileShader(fragment_shader_);
64+
65+
program_ = context3D->createProgram();
66+
context3D->attachShader(program_, vertex_shader_);
67+
context3D->attachShader(program_, fragment_shader_);
68+
context3D->linkProgram(program_);
69+
70+
texture_uniform_ = context3D->getUniformLocation(program_, "s_texture");
71+
}
72+
73+
DrawContext::~DrawContext() {
74+
if (vertex_buffer_ != GL_ZERO)
75+
context_->GetContext3D()->deleteBuffer(vertex_buffer_);
76+
if (program_ != GL_ZERO)
77+
context_->GetContext3D()->deleteProgram(program_);
78+
}
79+
80+
uint32 DrawContext::Draw(int texture) {
81+
DCHECK(program_ != GL_ZERO);
82+
WebKit::WebGraphicsContext3D* context3D = context_->GetContext3D();
83+
84+
context3D->useProgram(program_);
85+
86+
context3D->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
87+
context3D->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
88+
context3D->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
89+
context3D->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
90+
91+
context3D->uniform1i(texture_uniform_, 0);
92+
context3D->activeTexture(GL_TEXTURE0);
93+
context3D->bindTexture(GL_TEXTURE_2D, texture);
94+
95+
context3D->bindBuffer(GL_ARRAY_BUFFER, vertex_buffer_);
96+
context3D->enableVertexAttribArray(0);
97+
context3D->vertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, 0);
98+
context3D->bindAttribLocation(program_, 0, "a_Position");
99+
context3D->enableVertexAttribArray(1);
100+
context3D->vertexAttribPointer(
101+
1, 2, GL_FLOAT, GL_FALSE, 0, 8 * sizeof(GLfloat));
102+
context3D->bindAttribLocation(program_, 1, "a_texCoord");
103+
104+
context3D->drawArrays(GL_TRIANGLE_STRIP, 0, 4);
105+
106+
context3D->prepareTexture();
107+
108+
return context_->InsertSyncPoint();
109+
}
110+
111+
void DrawContext::Reshape(int width, int height) {
112+
WebKit::WebGraphicsContext3D* context3D = context_->GetContext3D();
113+
context3D->viewport(0, 0, width, height);
114+
context3D->reshape(width, height);
115+
}
116+
117+
} // namespace content

src/android/draw_context.h

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// Copyright (c) 2012 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.
4+
5+
#ifndef CONTENT_SHELL_ANDROID_DRAW_CONTEXT_H_
6+
#define CONTENT_SHELL_ANDROID_DRAW_CONTEXT_H_
7+
8+
#include "base/memory/scoped_ptr.h"
9+
#include "base/synchronization/lock.h"
10+
#include "ui/gfx/native_widget_types.h"
11+
12+
#include <GLES2/gl2.h>
13+
14+
namespace content {
15+
class GraphicsContext;
16+
17+
// Helper class for drawing content textures to the UI window surface.
18+
class DrawContext {
19+
public:
20+
DrawContext(ANativeWindow* window);
21+
~DrawContext();
22+
23+
// Draws the given texture to the UI and returns a
24+
// SyncPoint identifier.
25+
uint32 Draw(int texture);
26+
27+
void Reshape(int width, int height);
28+
29+
private:
30+
// The shader program.
31+
int program_;
32+
int vertex_shader_;
33+
int fragment_shader_;
34+
35+
// Shader uniform locations.
36+
int texture_uniform_;
37+
38+
// The vertex attribute array used to draw a simple quad.
39+
unsigned int vertex_buffer_;
40+
41+
// The graphics context used for drawing.
42+
scoped_ptr<content::GraphicsContext> context_;
43+
44+
DISALLOW_COPY_AND_ASSIGN(DrawContext);
45+
};
46+
47+
} // namespace content
48+
49+
#endif // CONTENT_SHELL_ANDROID_DRAW_CONTEXT_H_
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
3+
<!-- Copyright (c) 2012 The Chromium Authors. All rights reserved.
4+
5+
Use of this source code is governed by a BSD-style license that can be
6+
found in the LICENSE file.
7+
-->
8+
9+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
10+
package="org.chromium.content_shell">
11+
12+
<permission android:name="org.chromium.content_shell.permission.SANDBOX"
13+
android:protectionLevel="signature" />
14+
15+
<application android:name="ContentShellApplication"
16+
android:label="ContentShell"
17+
android:debuggable="true">
18+
<activity android:name="ContentShellActivity"
19+
android:launchMode="singleTask"
20+
android:theme="@android:style/Theme.Holo.Light.NoActionBar"
21+
android:configChanges="orientation|keyboardHidden|keyboard|screenSize"
22+
android:hardwareAccelerated="true">
23+
<intent-filter>
24+
<action android:name="android.intent.action.MAIN"/>
25+
<category android:name="android.intent.category.LAUNCHER"/>
26+
</intent-filter>
27+
</activity>
28+
29+
<!-- The following service entries exist in order to allow us to
30+
start more than one sandboxed process. -->
31+
32+
<!-- NOTE: If you change the values of "android:process" for any of the below services,
33+
you also need to update kHelperProcessExecutableName in chrome_constants.cc. -->
34+
<service android:name="org.chromium.content.app.SandboxedProcessService0"
35+
android:process=":sandboxed_process0"
36+
android:permission="org.chromium.content_shell.permission.SANDBOX"
37+
android:exported="false" />
38+
<service android:name="org.chromium.content.app.SandboxedProcessService1"
39+
android:process=":sandboxed_process1"
40+
android:permission="org.chromium.content_shell.permission.SANDBOX"
41+
android:exported="false" />
42+
<service android:name="org.chromium.content.app.SandboxedProcessService2"
43+
android:process=":sandboxed_process2"
44+
android:permission="org.chromium.content_shell.permission.SANDBOX"
45+
android:exported="false" />
46+
<service android:name="org.chromium.content.app.SandboxedProcessService3"
47+
android:process=":sandboxed_process3"
48+
android:permission="org.chromium.content_shell.permission.SANDBOX"
49+
android:exported="false" />
50+
<service android:name="org.chromium.content.app.SandboxedProcessService4"
51+
android:process=":sandboxed_process4"
52+
android:permission="org.chromium.content_shell.permission.SANDBOX"
53+
android:exported="false" />
54+
</application>
55+
56+
<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="14" />
57+
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
58+
<uses-permission android:name="android.permission.INTERNET"/>
59+
<uses-permission android:name="android.permission.VIBRATE"/>
60+
<uses-permission android:name="android.permission.WAKE_LOCK"/>
61+
</manifest>
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
Copyright (c) 2012 The Chromium Authors. All rights reserved.
4+
Use of this source code is governed by a BSD-style license that can be
5+
found in the LICENSE file.
6+
-->
7+
<project name="ContentShell" default="debug" basedir=".">
8+
<description>
9+
Building ContentShell.apk
10+
</description>
11+
<import file="../../../../build/android/ant/common.xml"/>
12+
<import file="../../../../build/android/ant/sdk-targets.xml"/>
13+
<property-value name="target.abi" value="${APP_ABI}"/>
14+
<property-location name="out.dir" location="${PRODUCT_DIR}/content_shell"
15+
check-exists="false"/>
16+
<property name="resource.absolute.dir" value="../res"/>
17+
<property name="gen.absolute.dir" value="${out.dir}/gen"/>
18+
<property name="jar.libs.dir" value="${out.dir}/java/libs"/>
19+
<path id="native.libs.gdbserver">
20+
<fileset file="${toolchain.dir}/../../gdbserver"/>
21+
</path>
22+
<property name="native.libs.absolute.dir" location="${out.dir}/libs"/>
23+
<property name="asset.absolute.dir" location="${out.dir}/assets"/>
24+
25+
<path id="out.dex.jar.input.ref">
26+
<fileset file="${out.dir}/java/libs/chromium_content.jar"/>
27+
<fileset file="${out.dir}/java/libs/chromium_net.jar"/>
28+
<fileset file="${out.dir}/java/libs/chromium_base.jar"/>
29+
<fileset file="${out.dir}/java/libs/chromium_media.jar"/>
30+
</path>
31+
<property name="java.compilerargs" value="-classpath ${toString:out.dex.jar.input.ref}"/>
32+
33+
<!-- We expect PRODUCT_DIR to be set like the gyp var (e.g. $ROOT/out/Debug) -->
34+
<fail message="PRODUCT_DIR env var not set?">
35+
<condition>
36+
<not>
37+
<isset property="PRODUCT_DIR"/>
38+
</not>
39+
</condition>
40+
</fail>
41+
42+
<target name="-post-compile">
43+
<!--
44+
Copy gdbserver to main libs directory if building debug.
45+
TODO(jrg): for now, Chrome on Android always builds native code
46+
as Release and java/ant as Debug, which means we always install
47+
gdbserver. Resolve this discrepancy, possibly by making this
48+
Release Official build java/ant as Release.
49+
-->
50+
<if>
51+
<condition>
52+
<equals arg1="${build.target}" arg2="debug"/>
53+
</condition>
54+
<then>
55+
<echo message="Copying gdbserver to the apk to enable native debugging" />
56+
<copy todir="${out.dir}/libs/${target.abi}">
57+
<path refid="native.libs.gdbserver"/>
58+
</copy>
59+
</then>
60+
</if>
61+
</target>
62+
63+
<!-- Classpath for javac -->
64+
<path id="javac.custom.classpath">
65+
<path refid="out.dex.jar.input.ref"/>
66+
</path>
67+
<import file="${sdk.dir}/tools/ant/build.xml"/>
68+
</project>

0 commit comments

Comments
 (0)