summaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authorzhenghao@google.com <zhenghao@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2011-09-21 23:41:39 +0000
committerzhenghao@google.com <zhenghao@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2011-09-21 23:41:39 +0000
commit665ec133de02c0c8c1fcef13c4fe722aec036505 (patch)
treed016a9a48471e30aaa26bf2ea471cf791b8eec5b /ui
parent0dda19952c2e3b058b367cb0ed8e989a63c2ef99 (diff)
downloadchromium_src-665ec133de02c0c8c1fcef13c4fe722aec036505.zip
chromium_src-665ec133de02c0c8c1fcef13c4fe722aec036505.tar.gz
chromium_src-665ec133de02c0c8c1fcef13c4fe722aec036505.tar.bz2
Compile gl/ and surface/ on Android.
BUG=none TEST=none Review URL: http://codereview.chromium.org/7981034 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@102204 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui')
-rw-r--r--ui/gfx/gl/gl.gyp2
-rw-r--r--ui/gfx/gl/gl_bindings.h4
-rw-r--r--ui/gfx/surface/surface.gyp1
-rw-r--r--ui/gfx/surface/transport_dib.h18
-rw-r--r--ui/gfx/surface/transport_dib_android.cc101
5 files changed, 123 insertions, 3 deletions
diff --git a/ui/gfx/gl/gl.gyp b/ui/gfx/gl/gl.gyp
index 3a9ad6d..f29f270 100644
--- a/ui/gfx/gl/gl.gyp
+++ b/ui/gfx/gl/gl.gyp
@@ -109,7 +109,7 @@
},
],
'conditions': [
- ['OS != "mac"', {
+ ['OS != "mac" and OS != "android"', {
'sources': [
'egl_util.cc',
'egl_util.h',
diff --git a/ui/gfx/gl/gl_bindings.h b/ui/gfx/gl/gl_bindings.h
index 3615e88..8951225 100644
--- a/ui/gfx/gl/gl_bindings.h
+++ b/ui/gfx/gl/gl_bindings.h
@@ -65,6 +65,10 @@ typedef void* GLeglImageOES;
typedef HDC EGLNativeDisplayType;
typedef HBITMAP EGLNativePixmapType;
typedef HWND EGLNativeWindowType;
+#elif defined(OS_ANDROID)
+typedef void *EGLNativeDisplayType;
+typedef struct egl_native_pixmap_t *EGLNativePixmapType;
+typedef struct ANativeWindow *EGLNativeWindowType;
#elif defined(USE_WAYLAND)
typedef struct wl_display *EGLNativeDisplayType;
typedef struct wl_egl_pixmap *EGLNativePixmapType;
diff --git a/ui/gfx/surface/surface.gyp b/ui/gfx/surface/surface.gyp
index 231dcbb..e93014b 100644
--- a/ui/gfx/surface/surface.gyp
+++ b/ui/gfx/surface/surface.gyp
@@ -37,6 +37,7 @@
'io_surface_support_mac.h',
'surface_export.h',
'transport_dib.h',
+ 'transport_dib_android.cc',
'transport_dib_linux.cc',
'transport_dib_mac.cc',
'transport_dib_win.cc',
diff --git a/ui/gfx/surface/transport_dib.h b/ui/gfx/surface/transport_dib.h
index 6a8d0e0..4e4d62a 100644
--- a/ui/gfx/surface/transport_dib.h
+++ b/ui/gfx/surface/transport_dib.h
@@ -9,7 +9,7 @@
#include "base/basictypes.h"
#include "ui/gfx/surface/surface_export.h"
-#if defined(OS_WIN) || defined(OS_MACOSX)
+#if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_ANDROID)
#include "base/shared_memory.h"
#endif
@@ -118,6 +118,20 @@ class SURFACE_EXPORT TransportDIB {
static int fake_handle = 10;
return fake_handle++;
}
+#elif defined(OS_ANDROID)
+ typedef base::SharedMemoryHandle Handle;
+ typedef base::SharedMemoryHandle Id;
+
+ // Returns a default, invalid handle, that is meant to indicate a missing
+ // Transport DIB.
+ static Handle DefaultHandleValue() { return Handle(); }
+
+ // Returns a value that is ONLY USEFUL FOR TESTS WHERE IT WON'T BE
+ // ACTUALLY USED AS A REAL HANDLE.
+ static Handle GetFakeHandleForTest() {
+ static int fake_handle = 10;
+ return Handle(fake_handle++, false);
+ }
#endif
// Create a new TransportDIB, returning NULL on failure.
@@ -185,7 +199,7 @@ class SURFACE_EXPORT TransportDIB {
private:
TransportDIB();
-#if defined(OS_WIN) || defined(OS_MACOSX)
+#if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_ANDROID)
explicit TransportDIB(base::SharedMemoryHandle dib);
base::SharedMemory shared_memory_;
uint32 sequence_num_;
diff --git a/ui/gfx/surface/transport_dib_android.cc b/ui/gfx/surface/transport_dib_android.cc
new file mode 100644
index 0000000..432ae71
--- /dev/null
+++ b/ui/gfx/surface/transport_dib_android.cc
@@ -0,0 +1,101 @@
+// Copyright (c) 2011 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 "ui/gfx/surface/transport_dib.h"
+
+#include <unistd.h>
+#include <sys/stat.h>
+
+#include "base/eintr_wrapper.h"
+#include "base/logging.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/shared_memory.h"
+#include "skia/ext/platform_canvas.h"
+
+TransportDIB::TransportDIB()
+ : size_(0) {
+}
+
+TransportDIB::TransportDIB(TransportDIB::Handle dib)
+ : shared_memory_(dib, false /* read write */),
+ size_(0) {
+}
+
+TransportDIB::~TransportDIB() {
+}
+
+// static
+TransportDIB* TransportDIB::Create(size_t size, uint32 sequence_num) {
+ TransportDIB* dib = new TransportDIB;
+ // We will use ashmem_get_size_region() to figure out the size in Map(size).
+ if (!dib->shared_memory_.CreateAndMapAnonymous(size)) {
+ delete dib;
+ return NULL;
+ }
+
+ dib->size_ = size;
+ return dib;
+}
+
+// static
+TransportDIB* TransportDIB::Map(Handle handle) {
+ scoped_ptr<TransportDIB> dib(CreateWithHandle(handle));
+ if (!dib->Map())
+ return NULL;
+ return dib.release();
+}
+
+// static
+TransportDIB* TransportDIB::CreateWithHandle(Handle handle) {
+ return new TransportDIB(handle);
+}
+
+// static
+bool TransportDIB::is_valid_handle(Handle dib) {
+ return dib.fd >= 0;
+}
+
+// static
+bool TransportDIB::is_valid_id(Id id) {
+ // Same as is_valid_handle().
+ return id.fd >= 0;
+}
+
+skia::PlatformCanvas* TransportDIB::GetPlatformCanvas(int w, int h) {
+ if (!memory() && !Map())
+ return NULL;
+ scoped_ptr<skia::PlatformCanvas> canvas(new skia::PlatformCanvas);
+ if (!canvas->initialize(w, h, true, reinterpret_cast<uint8_t*>(memory()))) {
+ // TODO(husky): Remove when http://b/issue?id=4233182 is definitely fixed.
+ LOG(ERROR) << "Failed to initialize canvas of size " << w << "x" << h;
+ return NULL;
+ }
+ return canvas.release();
+}
+
+bool TransportDIB::Map() {
+ if (!is_valid_handle(handle()))
+ return false;
+ // We will use ashmem_get_size_region() to figure out the size in Map(size).
+ if (!shared_memory_.Map(0))
+ return false;
+
+ // TODO: Note that using created_size() below is a hack. See the comment in
+ // SharedMemory::Map().
+ size_ = shared_memory_.created_size();
+ return true;
+}
+
+void* TransportDIB::memory() const {
+ return shared_memory_.memory();
+}
+
+TransportDIB::Id TransportDIB::id() const {
+ // Use FileDescriptor as id.
+ return shared_memory_.handle();
+}
+
+TransportDIB::Handle TransportDIB::handle() const {
+ return shared_memory_.handle();
+}