summaryrefslogtreecommitdiff
path: root/chromium/plat_support
diff options
context:
space:
mode:
authorKaan Baloglu <kaanb@google.com>2013-02-21 15:22:14 -0800
committerKaan Baloglu <kaanb@google.com>2013-04-16 16:51:21 -0700
commitc5cde8c18df853e11d1ec528508fd0fe2e742d5c (patch)
tree605c6327d44da06c4957482730b4b9128bc451d3 /chromium/plat_support
parentbef5c8e29d2693c07fa32952088de0e46059c461 (diff)
downloadwebview-c5cde8c18df853e11d1ec528508fd0fe2e742d5c.tar.gz
Implementation of the graphic buffer interface for cc
Change-Id: Ic023e690448abbbae8689d13b3357ec497808ea7
Diffstat (limited to 'chromium/plat_support')
-rw-r--r--chromium/plat_support/graphic_buffer_impl.cpp113
-rw-r--r--chromium/plat_support/graphic_buffer_impl.h51
-rw-r--r--chromium/plat_support/graphics_utils.cpp16
3 files changed, 180 insertions, 0 deletions
diff --git a/chromium/plat_support/graphic_buffer_impl.cpp b/chromium/plat_support/graphic_buffer_impl.cpp
new file mode 100644
index 0000000..5ef76c7
--- /dev/null
+++ b/chromium/plat_support/graphic_buffer_impl.cpp
@@ -0,0 +1,113 @@
+/*
+ * Copyright (C) 2013 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// Provides the implementation of the GraphicBuffer interface in
+// renderer compostior
+
+#include "graphic_buffer_impl.h"
+
+#include <utils/Errors.h>
+
+namespace android {
+
+GraphicBufferImpl::GraphicBufferImpl(uint32_t w, uint32_t h)
+ : mBuffer(new android::GraphicBuffer(w, h, PIXEL_FORMAT_RGBA_8888,
+ android::GraphicBuffer::USAGE_HW_TEXTURE |
+ android::GraphicBuffer::USAGE_SW_READ_OFTEN |
+ android::GraphicBuffer::USAGE_SW_WRITE_OFTEN)) {
+}
+
+GraphicBufferImpl::~GraphicBufferImpl() {
+}
+
+// static
+int GraphicBufferImpl::Create(int w, int h) {
+ GraphicBufferImpl* buffer = new GraphicBufferImpl(
+ static_cast<uint32_t>(w), static_cast<uint32_t>(h));
+ if (buffer->InitCheck() != NO_ERROR) {
+ delete buffer;
+ return 0;
+ }
+ return reinterpret_cast<int>(buffer);
+}
+
+// static
+void GraphicBufferImpl::Release(int buffer_id) {
+ GraphicBufferImpl* buffer = reinterpret_cast<GraphicBufferImpl*>(buffer_id);
+ delete buffer;
+}
+
+// static
+int GraphicBufferImpl::LockStatic(int buffer_id, int mode, void** vaddr) {
+ GraphicBufferImpl* buffer = reinterpret_cast<GraphicBufferImpl*>(buffer_id);
+ return buffer->Lock(mode, vaddr);
+}
+
+// static
+int GraphicBufferImpl::UnlockStatic(int buffer_id) {
+ GraphicBufferImpl* buffer = reinterpret_cast<GraphicBufferImpl*>(buffer_id);
+ return buffer->Unlock();
+}
+
+// static
+void* GraphicBufferImpl::GetNativeBufferStatic(int buffer_id) {
+ GraphicBufferImpl* buffer = reinterpret_cast<GraphicBufferImpl*>(buffer_id);
+ return buffer->GetNativeBuffer();
+}
+
+// static
+uint32_t GraphicBufferImpl::GetStrideStatic(int buffer_id) {
+ GraphicBufferImpl* buffer = reinterpret_cast<GraphicBufferImpl*>(buffer_id);
+ return buffer->GetStride();
+}
+
+status_t GraphicBufferImpl::Lock(int mode, void** vaddr) {
+ int usage = 0;
+ switch (mode) {
+ // TODO(kaanb): Use public enum constants instead of integers.
+ case 0:
+ usage = android::GraphicBuffer::USAGE_SW_READ_OFTEN;
+ break;
+ case 1:
+ usage = android::GraphicBuffer::USAGE_SW_WRITE_OFTEN;
+ break;
+ case 2:
+ usage = android::GraphicBuffer::USAGE_SW_READ_OFTEN |
+ android::GraphicBuffer::USAGE_SW_WRITE_OFTEN;
+ break;
+ default:
+ return INVALID_OPERATION;
+ }
+ return mBuffer->lock(usage, vaddr);
+}
+
+status_t GraphicBufferImpl::Unlock() {
+ return mBuffer->unlock();
+}
+
+status_t GraphicBufferImpl::InitCheck() const {
+ return mBuffer->initCheck();
+}
+
+void* GraphicBufferImpl::GetNativeBuffer() const {
+ return mBuffer->getNativeBuffer();
+}
+
+uint32_t GraphicBufferImpl::GetStride() const {
+ return mBuffer->getStride();
+}
+
+} // namespace android
diff --git a/chromium/plat_support/graphic_buffer_impl.h b/chromium/plat_support/graphic_buffer_impl.h
new file mode 100644
index 0000000..7db502f
--- /dev/null
+++ b/chromium/plat_support/graphic_buffer_impl.h
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2013 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// Provides the implementation of the GraphicBuffer interface in
+// renderer compostior
+
+#ifndef ANDROID_GRAPHIC_BUFFER_IMPL_H
+#define ANDROID_GRAPHIC_BUFFER_IMPL_H
+
+#include <ui/GraphicBuffer.h>
+
+namespace android {
+
+class GraphicBufferImpl {
+ public:
+ ~GraphicBufferImpl();
+
+ static int Create(int w, int h);
+ static void Release(int buffer_id);
+ static int LockStatic(int buffer_id, int mode, void** vaddr);
+ static int UnlockStatic(int buffer_id);
+ static void* GetNativeBufferStatic(int buffer_id);
+ static uint32_t GetStrideStatic(int buffer_id);
+
+ private:
+ status_t Lock(int mode, void** vaddr);
+ status_t Unlock();
+ status_t InitCheck() const;
+ void* GetNativeBuffer() const;
+ uint32_t GetStride() const;
+ GraphicBufferImpl(uint32_t w, uint32_t h);
+
+ sp<android::GraphicBuffer> mBuffer;
+};
+
+} // namespace android
+
+#endif // ANDROID_GRAPHIC_BUFFER_IMPL_H
diff --git a/chromium/plat_support/graphics_utils.cpp b/chromium/plat_support/graphics_utils.cpp
index 8bd8254..1db4fc7 100644
--- a/chromium/plat_support/graphics_utils.cpp
+++ b/chromium/plat_support/graphics_utils.cpp
@@ -19,11 +19,13 @@
#define LOG_TAG "webviewchromium_plat_support"
+#include "android_webview/public/browser/draw_gl.h"
#include "android_webview/public/browser/draw_sw.h"
#include <cstdlib>
#include <jni.h>
#include <utils/Log.h>
+#include "graphic_buffer_impl.h"
#include "GraphicsJNI.h"
#include "SkGraphics.h"
#include "SkPicture.h"
@@ -120,10 +122,24 @@ jint GetDrawSWFunctionTable(JNIEnv* env, jclass) {
return reinterpret_cast<jint>(&function_table);
}
+jint GetDrawGLFunctionTable(JNIEnv* env, jclass) {
+ static const AwDrawGLFunctionTable function_table = {
+ &GraphicBufferImpl::Create,
+ &GraphicBufferImpl::Release,
+ &GraphicBufferImpl::LockStatic,
+ &GraphicBufferImpl::UnlockStatic,
+ &GraphicBufferImpl::GetNativeBufferStatic,
+ &GraphicBufferImpl::GetStrideStatic,
+ };
+ return reinterpret_cast<jint>(&function_table);
+}
+
const char kClassName[] = "com/android/webview/chromium/GraphicsUtils";
const JNINativeMethod kJniMethods[] = {
{ "nativeGetDrawSWFunctionTable", "()I",
reinterpret_cast<void*>(GetDrawSWFunctionTable) },
+ { "nativeGetDrawGLFunctionTable", "()I",
+ reinterpret_cast<void*>(GetDrawGLFunctionTable) },
};
} // namespace