summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorfransiskusx@google.com <fransiskusx@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-08-05 00:21:07 +0000
committerfransiskusx@google.com <fransiskusx@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-08-05 00:21:07 +0000
commitb04a424313a92a370993072db73e54e07e9cfa54 (patch)
tree89d7f3e4fe7e6c86d99dbc587c2433104244fa02
parentbad671d9e43be274d926a2204b16e89b21cb7135 (diff)
downloadchromium_src-b04a424313a92a370993072db73e54e07e9cfa54.zip
chromium_src-b04a424313a92a370993072db73e54e07e9cfa54.tar.gz
chromium_src-b04a424313a92a370993072db73e54e07e9cfa54.tar.bz2
Initial version rendering 2D path for O3D. This will eventually allow O3D apps to fall back to 2D logic on systems without (working) GPUs.
Incorporated 2D library Cairo to O3D. Currently only support Linux and compiled when renderer = cairo. TEST= I compiled with renderer = cairo and it worked. Also I compiled with renderer = gl and it worked. BUG=none Review URL: http://codereview.chromium.org/2825074 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@55008 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--o3d/build/common.gypi7
-rw-r--r--o3d/build/libs.gyp28
-rw-r--r--o3d/core/core.gyp14
-rw-r--r--o3d/core/cross/cairo/install_check.cc42
-rw-r--r--o3d/core/cross/cairo/renderer_cairo.cc385
-rw-r--r--o3d/core/cross/cairo/renderer_cairo.h229
-rw-r--r--o3d/core/cross/cairo/texture_cairo.cc139
-rw-r--r--o3d/core/cross/cairo/texture_cairo.h105
-rw-r--r--o3d/core/cross/client_info.h9
-rw-r--r--o3d/core/cross/renderer_platform.h2
-rw-r--r--o3d/import/cross/collada_conditioner.cc4
-rw-r--r--o3d/import/import.gyp11
-rw-r--r--o3d/plugin/idl/client.idl5
-rw-r--r--o3d/tests/common/linux/testing_common.cc6
14 files changed, 985 insertions, 1 deletions
diff --git a/o3d/build/common.gypi b/o3d/build/common.gypi
index a24623f..e4bb0dd 100644
--- a/o3d/build/common.gypi
+++ b/o3d/build/common.gypi
@@ -109,6 +109,13 @@
],
},
],
+ ['renderer == "cairo"',
+ {
+ 'defines': [
+ 'RENDERER_CAIRO',
+ ],
+ },
+ ],
['renderer == "gles2"',
{
'defines': [
diff --git a/o3d/build/libs.gyp b/o3d/build/libs.gyp
index 94f624b..f94cf26 100644
--- a/o3d/build/libs.gyp
+++ b/o3d/build/libs.gyp
@@ -18,6 +18,34 @@
],
'targets': [
{
+ 'target_name': 'cairo_libs',
+ 'type': 'none',
+ 'conditions': [
+ [ 'OS=="linux"',
+ {
+ 'all_dependent_settings': {
+ 'cflags': [
+ '<!@(pkg-config --cflags cairo)',
+ ],
+ 'libraries': [
+ '-lcairo',
+ ],
+ },
+ },
+ ],
+ [ 'OS=="mac"',
+ {
+ #TODO(fransiskusx): Link to Cairo on Win/Mac as a static library
+ },
+ ],
+ [ 'OS=="win"',
+ {
+ #TODO(fransiskusx): Link to Cairo on Win/Mac as a static library,
+ },
+ ],
+ ],
+ },
+ {
'target_name': 'gl_libs',
'type': 'none',
'all_dependent_settings': {
diff --git a/o3d/core/core.gyp b/o3d/core/core.gyp
index f7df445..c071611 100644
--- a/o3d/core/core.gyp
+++ b/o3d/core/core.gyp
@@ -470,6 +470,20 @@
],
},
],
+ ['renderer == "cairo"',
+ {
+ 'sources': [
+ 'cross/cairo/install_check.cc',
+ 'cross/cairo/renderer_cairo.cc',
+ 'cross/cairo/renderer_cairo.h',
+ 'cross/cairo/texture_cairo.cc',
+ 'cross/cairo/texture_cairo.h',
+ ],
+ 'dependencies': [
+ '../build/libs.gyp:cairo_libs',
+ ],
+ },
+ ],
],
},
{
diff --git a/o3d/core/cross/cairo/install_check.cc b/o3d/core/cross/cairo/install_check.cc
new file mode 100644
index 0000000..2784c13
--- /dev/null
+++ b/o3d/core/cross/cairo/install_check.cc
@@ -0,0 +1,42 @@
+/*
+ * Copyright 2010, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+
+#include "core/cross/install_check.h"
+
+namespace o3d {
+
+bool RendererInstallCheck(std::string *error) {
+ return true;
+}
+
+} // namespace o3d
+
diff --git a/o3d/core/cross/cairo/renderer_cairo.cc b/o3d/core/cross/cairo/renderer_cairo.cc
new file mode 100644
index 0000000..4221e0d
--- /dev/null
+++ b/o3d/core/cross/cairo/renderer_cairo.cc
@@ -0,0 +1,385 @@
+/*
+ * Copyright 2010, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+// Renderer that is using 2D Library Cairo.
+
+#include "core/cross/cairo/renderer_cairo.h"
+#include <cairo-xlib.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "core/cross/cairo/texture_cairo.h"
+
+namespace o3d {
+
+Renderer* Renderer::CreateDefaultRenderer(ServiceLocator* service_locator) {
+ return RendererCairo::CreateDefault(service_locator);
+}
+
+RendererCairo::RendererCairo(ServiceLocator* service_locator)
+ : Renderer(service_locator), display_(NULL), window_(0),
+ main_surface_(NULL), frame_src_data_(NULL), frame_src_width_(0),
+ frame_src_height_(0), frame_src_pitch_(0) {
+ // Don't need to do anything.
+}
+
+RendererCairo::~RendererCairo() {
+ Destroy();
+}
+
+RendererCairo* RendererCairo::CreateDefault(ServiceLocator* service_locator) {
+ return new RendererCairo(service_locator);
+}
+
+// Released all hardware resources.
+void RendererCairo::Destroy() {
+ DLOG(INFO) << "To Destroy";
+
+ if (main_surface_ != NULL) {
+ cairo_surface_destroy(main_surface_);
+ main_surface_= NULL;
+ }
+
+ display_ = NULL;
+ frame_src_data_ = NULL;
+}
+
+void RendererCairo::SetNewFrame(const void* src_data, unsigned src_width,
+ unsigned src_height, int src_pitch) {
+ DLOG(INFO) << "To Set New Frame";
+ if (src_data == NULL)
+ return;
+
+ frame_src_data_ = src_data;
+ frame_src_width_ = src_width;
+ frame_src_height_ = src_height;
+ frame_src_pitch_ = src_pitch;
+}
+
+// TODO(fransiskusx): Need to check if the shared memory data has been
+// unregistered. It will prevent errors when accessing unregistered
+// shared memory data to render the frame.
+void RendererCairo::Paint() {
+ DLOG(INFO) << "To paint";
+
+ if (frame_src_data_ != NULL) {
+ DLOG(INFO) << "To paint new drawing";
+
+ // Preparing the image to render
+ cairo_surface_t* image = cairo_image_surface_create_for_data(
+ const_cast<unsigned char*>(
+ static_cast<const unsigned char*>(frame_src_data_)),
+ CAIRO_FORMAT_ARGB32, frame_src_width_,
+ frame_src_height_, frame_src_pitch_);
+ cairo_t* current_drawing = cairo_create(main_surface_);
+
+ // Scaling the image
+ double width_scaling =
+ (static_cast<double>(display_width())) / frame_src_width_;
+ double height_scaling =
+ (static_cast<double>(display_height())) / frame_src_height_;
+ cairo_scale(current_drawing, width_scaling, height_scaling);
+
+ // Painting the image to the surface
+ cairo_set_source_surface(current_drawing, image, 0, 0);
+ cairo_paint(current_drawing);
+
+ // Cleaning up the memory
+ cairo_destroy(current_drawing);
+ cairo_surface_destroy(image);
+ }
+}
+
+void RendererCairo::InitCommon() {
+ main_surface_ = cairo_xlib_surface_create(display_, window_,
+ XDefaultVisual(display_, 0),
+ display_width(), display_height());
+}
+
+void RendererCairo::UninitCommon() {
+ // Don't need to do anything.
+}
+
+Renderer::InitStatus RendererCairo::InitPlatformSpecific(
+ const DisplayWindow& display_window,
+ bool off_screen) {
+ const DisplayWindowLinux &display_platform =
+ static_cast<const DisplayWindowLinux&>(display_window);
+ display_ = display_platform.display();
+ window_ = display_platform.window();
+
+ return SUCCESS;
+}
+
+// Handles the plugin resize event.
+void RendererCairo::Resize(int width, int height) {
+ DLOG(INFO) << "To Resize " << width << " x " << height;
+ SetClientSize(width, height);
+
+ // Resize the mainSurface
+ cairo_xlib_surface_set_size(main_surface_, width, height);
+}
+
+// The platform specific part of BeginDraw.
+bool RendererCairo::PlatformSpecificBeginDraw() {
+ return true;
+}
+
+// Platform specific version of CreateTexture2D
+Texture2D::Ref RendererCairo::CreatePlatformSpecificTexture2D(
+ int width,
+ int height,
+ Texture::Format format,
+ int levels,
+ bool enable_render_surfaces) {
+ return Texture2D::Ref(TextureCairo::Create(service_locator(),
+ format,
+ levels,
+ width,
+ height,
+ enable_render_surfaces));
+}
+
+// The platform specific part of EndDraw.
+void RendererCairo::PlatformSpecificEndDraw() {
+ // Don't need to do anything.
+}
+
+// The platform specific part of StartRendering.
+bool RendererCairo::PlatformSpecificStartRendering() {
+ return true;
+}
+
+// The platform specific part of EndRendering.
+void RendererCairo::PlatformSpecificFinishRendering() {
+ Paint();
+}
+
+// The platform specific part of Present.
+void RendererCairo::PlatformSpecificPresent() {
+ // Don't need to do anything.
+}
+
+// TODO(fransiskusx): DO need to implement before shipped.
+// Get a single fullscreen display mode by id.
+// Returns true on success, false on error.
+bool RendererCairo::GetDisplayMode(int id, DisplayMode* mode) {
+ NOTIMPLEMENTED();
+ return true;
+}
+
+// TODO(fransiskusx): DO need to implement before shipped.
+// Get a vector of the available fullscreen display modes.
+// Clears *modes on error.
+void RendererCairo::GetDisplayModes(std::vector<DisplayMode>* modes) {
+ NOTIMPLEMENTED();
+}
+
+// TODO(fransiskusx): DO need to implement before shipped.
+// The platform specific part of Clear.
+void RendererCairo::PlatformSpecificClear(const Float4 &color,
+ bool color_flag,
+ float depth,
+ bool depth_flag,
+ int stencil,
+ bool stencil_flag) {
+ NOTIMPLEMENTED();
+}
+
+// TODO(fransiskusx): DO need to implement before shipped.
+// Sets the viewport. This is the platform specific version.
+void RendererCairo::SetViewportInPixels(int left,
+ int top,
+ int width,
+ int height,
+ float min_z,
+ float max_z) {
+ NOTIMPLEMENTED();
+}
+
+// TODO(fransiskusx): Need to implement it later.
+// Turns fullscreen display on.
+// Parameters:
+// display: a platform-specific display identifier
+// mode_id: a mode returned by GetDisplayModes
+// Returns true on success, false on failure.
+bool RendererCairo::GoFullscreen(const DisplayWindow& display,
+ int mode_id) {
+ NOTIMPLEMENTED();
+ return false;
+}
+
+// TODO(fransiskusx): Need to implement it later.
+// Cancels fullscreen display. Restores rendering to windowed mode
+// with the given width and height.
+// Parameters:
+// display: a platform-specific display identifier
+// width: the width to which to restore windowed rendering
+// height: the height to which to restore windowed rendering
+// Returns true on success, false on failure.
+bool RendererCairo::CancelFullscreen(const DisplayWindow& display,
+ int width, int height) {
+ NOTIMPLEMENTED();
+ return false;
+}
+
+// TODO(fransiskusx): Need to implement it later.
+// Tells whether we're currently displayed fullscreen or not.
+bool RendererCairo::fullscreen() const {
+ NOTIMPLEMENTED();
+ return false;
+}
+
+// TODO(fransiskusx): This function is not applicable to 2D rendering.
+// Sets rendering to the back buffer.
+void RendererCairo::SetBackBufferPlatformSpecific() {
+ // Don't need to do anything.
+ NOTIMPLEMENTED();
+}
+
+// TODO(fransiskusx): This function is not applicable to 2D rendering.
+// Applies states that have been modified (marked dirty).
+void RendererCairo::ApplyDirtyStates() {
+ // Don't need to do anything.
+ NOTIMPLEMENTED();
+}
+
+// TODO(fransiskusx): This function is not applicable to 2D rendering.
+// Creates a platform specific ParamCache.
+ParamCache* RendererCairo::CreatePlatformSpecificParamCache() {
+ NOTIMPLEMENTED();
+ return NULL;
+}
+
+// TODO(fransiskusx): This function is not applicable to 2D rendering.
+// Platform specific version of CreateTextureCUBE.
+TextureCUBE::Ref RendererCairo::CreatePlatformSpecificTextureCUBE(
+ int edge_length,
+ Texture::Format format,
+ int levels,
+ bool enable_render_surfaces) {
+ NOTIMPLEMENTED();
+ return TextureCUBE::Ref();
+}
+
+// TODO(fransiskusx): This function is not applicable to 2D rendering.
+void RendererCairo::PushRenderStates(State* state) {
+ // Don't need to do anything.;
+ NOTIMPLEMENTED();
+}
+
+// TODO(fransiskusx): This function is not applicable to 2D rendering.
+// Sets the render surfaces on a specific platform.
+void RendererCairo::SetRenderSurfacesPlatformSpecific(
+ const RenderSurface* surface,
+ const RenderDepthStencilSurface* depth_surface) {
+ // Don't need to do anything.
+ NOTIMPLEMENTED();
+}
+
+// TODO(fransiskusx): This function is not applicable to 2D rendering.
+// Creates a StreamBank, returning a platform specific implementation class.
+StreamBank::Ref RendererCairo::CreateStreamBank() {
+ NOTIMPLEMENTED();
+ return StreamBank::Ref();
+}
+
+// TODO(fransiskusx): This function is not applicable to 2D rendering.
+// Creates a Primitive, returning a platform specific implementation class.
+Primitive::Ref RendererCairo::CreatePrimitive() {
+ NOTIMPLEMENTED();
+ return Primitive::Ref();
+}
+
+// TODO(fransiskusx): This function is not applicable to 2D rendering.
+// Creates a DrawElement, returning a platform specific implementation
+// class.
+DrawElement::Ref RendererCairo::CreateDrawElement() {
+ NOTIMPLEMENTED();
+ return DrawElement::Ref();
+}
+
+// TODO(fransiskusx): This function is not applicable to 2D rendering.
+// Creates and returns a platform specific float buffer
+VertexBuffer::Ref RendererCairo::CreateVertexBuffer() {
+ NOTIMPLEMENTED();
+ return VertexBuffer::Ref();
+}
+
+// TODO(fransiskusx): This function is not applicable to 2D rendering.
+// Creates and returns a platform specific integer buffer
+IndexBuffer::Ref RendererCairo::CreateIndexBuffer() {
+ NOTIMPLEMENTED();
+ return IndexBuffer::Ref();
+}
+
+// TODO(fransiskusx): This function is not applicable to 2D rendering.
+// Creates and returns a platform specific effect object
+Effect::Ref RendererCairo::CreateEffect() {
+ NOTIMPLEMENTED();
+ return Effect::Ref();
+}
+
+// TODO(fransiskusx): This function is not applicable to 2D rendering.
+// Creates and returns a platform specific Sampler object.
+Sampler::Ref RendererCairo::CreateSampler() {
+ NOTIMPLEMENTED();
+ return Sampler::Ref();
+}
+
+// TODO(fransiskusx): This function is not applicable to 2D rendering.
+// Returns a platform specific 4 element swizzle table for RGBA UByteN fields.
+// The should contain the index of R, G, B, and A in that order for the
+// current platform.
+const int* RendererCairo::GetRGBAUByteNSwizzleTable() {
+ static int swizzle_table[] = { 0, 1, 2, 3, };
+ NOTIMPLEMENTED();
+ return swizzle_table;
+}
+
+// TODO(fransiskusx): This function is not applicable to 2D rendering.
+// Creates and returns a platform-specific RenderDepthStencilSurface object
+// for use as a depth-stencil render target.
+RenderDepthStencilSurface::Ref RendererCairo::CreateDepthStencilSurface(
+ int width,
+ int height) {
+ NOTIMPLEMENTED();
+ return RenderDepthStencilSurface::Ref();
+}
+
+// TODO(fransiskusx): This function is not applicable to 2D rendering.
+void RendererCairo::SetState(Renderer* renderer, Param* param) {
+ // Don't need to do anything.
+ NOTIMPLEMENTED();
+}
+
+} // namespace o3d
+
diff --git a/o3d/core/cross/cairo/renderer_cairo.h b/o3d/core/cross/cairo/renderer_cairo.h
new file mode 100644
index 0000000..0ecdad0
--- /dev/null
+++ b/o3d/core/cross/cairo/renderer_cairo.h
@@ -0,0 +1,229 @@
+/*
+ * Copyright 2010, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+// Renderer that is using 2D Library Cairo.
+
+#ifndef O3D_CORE_CROSS_CAIRO_RENDERER_CAIRO_H_
+#define O3D_CORE_CROSS_CAIRO_RENDERER_CAIRO_H_
+
+#include <cairo.h>
+#include <build/build_config.h>
+#include <vector>
+#include "core/cross/renderer_platform.h"
+#include "core/cross/renderer.h"
+
+namespace o3d {
+
+class RendererCairo : public Renderer {
+ public:
+ static RendererCairo* CreateDefault(ServiceLocator* service_locator);
+
+ virtual ~RendererCairo();
+
+ // Initializes stuff that has to happen after Init
+ virtual void InitCommon();
+
+ virtual void UninitCommon();
+
+ // Initialises the renderer for use, claiming hardware resources.
+ virtual InitStatus InitPlatformSpecific(const DisplayWindow& display,
+ bool off_screen);
+
+ // Released all hardware resources.
+ virtual void Destroy();
+
+ // set the image surface used to render images to the main surface.
+ void SetNewFrame(const void* src_data, unsigned src_width,
+ unsigned src_height, int src_pitch);
+
+ // Paint the frame to the main view
+ void Paint();
+
+ // Handles the plugin resize event.
+ virtual void Resize(int width, int height);
+
+ // Creates and returns a platform-specific RenderDepthStencilSurface object
+ // for use as a depth-stencil render target.
+ virtual RenderDepthStencilSurface::Ref CreateDepthStencilSurface(int width,
+ int height);
+
+ // Turns fullscreen display on.
+ // Parameters:
+ // display: a platform-specific display identifier
+ // mode_id: a mode returned by GetDisplayModes
+ // Returns true on success, false on failure.
+ virtual bool GoFullscreen(const DisplayWindow& display,
+ int mode_id);
+
+ // Cancels fullscreen display. Restores rendering to windowed mode
+ // with the given width and height.
+ // Parameters:
+ // display: a platform-specific display identifier
+ // width: the width to which to restore windowed rendering
+ // height: the height to which to restore windowed rendering
+ // Returns true on success, false on failure.
+ virtual bool CancelFullscreen(const DisplayWindow& display,
+ int width, int height);
+
+ // Tells whether we're currently displayed fullscreen or not.
+ virtual bool fullscreen() const;
+
+ // Get a vector of the available fullscreen display modes.
+ // Clears *modes on error.
+ virtual void GetDisplayModes(std::vector<DisplayMode> *modes);
+
+ // Get a single fullscreen display mode by id.
+ // Returns true on success, false on error.
+ virtual bool GetDisplayMode(int id, DisplayMode *mode);
+
+ // Sets the state to the value of the param.
+ // Parameters:
+ // renderer: the renderer
+ // param: param with state data
+ virtual void SetState(Renderer* renderer, Param* param);
+
+ // Creates a StreamBank, returning a platform specific implementation class.
+ virtual StreamBank::Ref CreateStreamBank();
+
+ // Creates a Primitive, returning a platform specific implementation class.
+ virtual Primitive::Ref CreatePrimitive();
+
+ // Creates a DrawElement, returning a platform specific implementation
+ // class.
+ virtual DrawElement::Ref CreateDrawElement();
+
+ // Creates and returns a platform specific float buffer
+ virtual VertexBuffer::Ref CreateVertexBuffer();
+
+ // Creates and returns a platform specific integer buffer
+ virtual IndexBuffer::Ref CreateIndexBuffer();
+
+ // Creates and returns a platform specific effect object
+ virtual Effect::Ref CreateEffect();
+
+ // Creates and returns a platform specific Sampler object.
+ virtual Sampler::Ref CreateSampler();
+
+ // Returns a platform specific 4 element swizzle table for RGBA UByteN
+ // fields.
+ // The should contain the index of R, G, B, and A in that order for the
+ // current platform.
+ virtual const int* GetRGBAUByteNSwizzleTable();
+
+ void PushRenderStates(State* state);
+
+ protected:
+ // Keep the constructor protected so only factory methods can create
+ // renderers.
+ explicit RendererCairo(ServiceLocator* service_locator);
+
+ // Sets rendering to the back buffer.
+ virtual void SetBackBufferPlatformSpecific();
+
+ // Sets the render surfaces on a specific platform.
+ virtual void SetRenderSurfacesPlatformSpecific(
+ const RenderSurface* surface,
+ const RenderDepthStencilSurface* depth_surface);
+
+ // Creates a platform specific ParamCache.
+ virtual ParamCache* CreatePlatformSpecificParamCache();
+
+ // Platform specific version of CreateTexture2D
+ virtual Texture2D::Ref CreatePlatformSpecificTexture2D(
+ int width,
+ int height,
+ Texture::Format format,
+ int levels,
+ bool enable_render_surfaces);
+
+ // Platform specific version of CreateTextureCUBE.
+ virtual TextureCUBE::Ref CreatePlatformSpecificTextureCUBE(
+ int edge_length,
+ Texture::Format format,
+ int levels,
+ bool enable_render_surfaces);
+
+ // The platform specific part of BeginDraw.
+ virtual bool PlatformSpecificBeginDraw();
+
+ // The platform specific part of EndDraw.
+ virtual void PlatformSpecificEndDraw();
+
+ // The platform specific part of StartRendering.
+ virtual bool PlatformSpecificStartRendering();
+
+ // The platform specific part of EndRendering.
+ virtual void PlatformSpecificFinishRendering();
+
+ // The platform specific part of Present.
+ virtual void PlatformSpecificPresent();
+
+ // The platform specific part of Clear.
+ virtual void PlatformSpecificClear(const Float4 &color,
+ bool color_flag,
+ float depth,
+ bool depth_flag,
+ int stencil,
+ bool stencil_flag);
+
+ // Applies states that have been modified (marked dirty).
+ virtual void ApplyDirtyStates();
+
+ // Sets the viewport. This is the platform specific version.
+ virtual void SetViewportInPixels(int left,
+ int top,
+ int width,
+ int height,
+ float min_z,
+ float max_z);
+
+ // Linux Client Display
+ Display* display_;
+ // Linux Client Window
+ Window window_;
+
+ // Main surface to render cairo
+ cairo_surface_t* main_surface_;
+
+ // Current Frame Data Source
+ const void* frame_src_data_;
+ // Current Frame Source Width
+ unsigned frame_src_width_;
+ // Current Frame Source Height
+ unsigned frame_src_height_;
+ // Current Frame Source Pitch
+ int frame_src_pitch_;
+};
+
+} // namespace o3d
+
+#endif // O3D_CORE_CROSS_CAIRO_RENDERER_CAIRO_H_
+
diff --git a/o3d/core/cross/cairo/texture_cairo.cc b/o3d/core/cross/cairo/texture_cairo.cc
new file mode 100644
index 0000000..1fbe076
--- /dev/null
+++ b/o3d/core/cross/cairo/texture_cairo.cc
@@ -0,0 +1,139 @@
+/*
+ * Copyright 2010, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+
+// Implementations of the abstract Texture2D.
+// Texture Class for handling Cairo Rendering Mode.
+
+#include "core/cross/cairo/texture_cairo.h"
+#include "core/cross/cairo/renderer_cairo.h"
+
+namespace o3d {
+
+namespace {
+
+Texture::RGBASwizzleIndices g_gl_abgr32f_swizzle_indices = {0, 1, 2, 3};
+
+} // anonymous namespace.
+
+TextureCairo::TextureCairo(ServiceLocator* service_locator,
+ Texture::Format format,
+ int levels,
+ int width,
+ int height,
+ bool enable_render_surfaces)
+ : Texture2D(service_locator,
+ width,
+ height,
+ format,
+ levels,
+ enable_render_surfaces),
+ renderer_(static_cast<RendererCairo*>(
+ service_locator->GetService<Renderer>())) {
+ DLOG(INFO) << "Texture2D Construct";
+ DCHECK_NE(format, Texture::UNKNOWN_FORMAT);
+}
+
+// Creates a new texture object from scratch.
+TextureCairo* TextureCairo::Create(ServiceLocator* service_locator,
+ Texture::Format format,
+ int levels,
+ int width,
+ int height,
+ bool enable_render_surfaces) {
+ DLOG(INFO) << "Texture2DCairo Create";
+ TextureCairo* texture = new TextureCairo(service_locator,
+ format,
+ levels,
+ width,
+ height,
+ enable_render_surfaces);
+ return texture;
+}
+
+// In 2D: is not really used
+const Texture::RGBASwizzleIndices& TextureCairo::GetABGR32FSwizzleIndices() {
+ NOTIMPLEMENTED();
+ return g_gl_abgr32f_swizzle_indices;
+}
+
+TextureCairo::~TextureCairo() {
+ DLOG(INFO) << "Texture2DCairo Destruct";
+}
+
+// Set the image data to the renderer
+void TextureCairo::SetRect(int level,
+ unsigned dst_left,
+ unsigned dst_top,
+ unsigned src_width,
+ unsigned src_height,
+ const void* src_data,
+ int src_pitch) {
+ DLOG(INFO) << "Texture2DCairo SetRect";
+
+ renderer_->SetNewFrame(src_data,
+ src_width, src_height,
+ src_pitch);
+}
+
+// Locks the given mipmap level of this texture for loading from main memory,
+// and returns a pointer to the buffer.
+bool TextureCairo::PlatformSpecificLock(
+ int level, void** data, int* pitch, Texture::AccessMode mode) {
+ NOTIMPLEMENTED();
+ return true;
+}
+
+// In Open GL: Unlocks the given mipmap level of this texture, uploading
+// the main memory data buffer to GL.
+//
+// In 2D: is not really used
+bool TextureCairo::PlatformSpecificUnlock(int level) {
+ NOTIMPLEMENTED();
+ return true;
+}
+
+// In 2D: is not really used
+RenderSurface::Ref TextureCairo::PlatformSpecificGetRenderSurface(
+ int mip_level) {
+ DCHECK_LT(mip_level, levels());
+ NOTIMPLEMENTED();
+ return RenderSurface::Ref(NULL);
+}
+
+// Returns the implementation-specific texture handle for this texture.
+void* TextureCairo::GetTextureHandle() const {
+ NOTIMPLEMENTED();
+ return reinterpret_cast<void*>(NULL);
+}
+
+} // namespace o3d
+
diff --git a/o3d/core/cross/cairo/texture_cairo.h b/o3d/core/cross/cairo/texture_cairo.h
new file mode 100644
index 0000000..5ba4685
--- /dev/null
+++ b/o3d/core/cross/cairo/texture_cairo.h
@@ -0,0 +1,105 @@
+/*
+ * Copyright 2010, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+
+// Implementations of the abstract Texture2D.
+// Texture Class for handling Cairo Rendering Mode.
+
+#ifndef O3D_CORE_CROSS_CAIRO_TEXTURE_CAIRO_H_
+#define O3D_CORE_CROSS_CAIRO_TEXTURE_CAIRO_H_
+
+#include "core/cross/texture.h"
+
+namespace o3d {
+
+class RendererCairo;
+
+// Texture2DCairo implements the Texture2D interface.
+class TextureCairo : public Texture2D {
+ public:
+ typedef SmartPointer<TextureCairo> Ref;
+
+ // Creates a new Texture2DCairo with the given specs. If the texture
+ // creation fails then it returns NULL otherwise it returns a pointer to the
+ // newly created Texture object.
+ static TextureCairo* Create(ServiceLocator* service_locator,
+ Texture::Format format,
+ int levels,
+ int width,
+ int height,
+ bool enable_render_surfaces);
+
+ virtual ~TextureCairo();
+
+ // Overridden from Texture2D
+ virtual void SetRect(int level,
+ unsigned left,
+ unsigned top,
+ unsigned width,
+ unsigned height,
+ const void* src_data,
+ int src_pitch);
+
+ // Gets a RGBASwizzleIndices that contains a mapping from
+ // RGBA to the internal format used by the rendering API.
+ virtual const RGBASwizzleIndices& GetABGR32FSwizzleIndices();
+
+ protected:
+ // Overridden from Texture2D
+ virtual bool PlatformSpecificLock(int level, void** texture_data, int* pitch,
+ AccessMode mode);
+
+ // Overridden from Texture2D
+ virtual bool PlatformSpecificUnlock(int level);
+
+ // Overridden from Texture2D
+ virtual RenderSurface::Ref PlatformSpecificGetRenderSurface(int mip_level);
+
+ // Returns the implementation-specific texture handle for this texture.
+ virtual void* GetTextureHandle() const;
+
+ // The 2d renderer object to be used by client
+ RendererCairo* renderer_;
+
+ private:
+ // Initializes the Texture2D.
+ TextureCairo(ServiceLocator* service_locator,
+ Texture::Format format,
+ int levels,
+ int width,
+ int height,
+ bool enable_render_surfaces);
+};
+
+} // namespace o3d
+
+#endif // O3D_CORE_CROSS_CAIRO_TEXTURE_CAIRO_H_
+
diff --git a/o3d/core/cross/client_info.h b/o3d/core/cross/client_info.h
index 552ce02..396d805 100644
--- a/o3d/core/cross/client_info.h
+++ b/o3d/core/cross/client_info.h
@@ -75,6 +75,15 @@ class ClientInfo {
#endif
}
+ // Whether render in 2d Mode
+ bool render_2d() const {
+#if defined(RENDERER_CAIRO)
+ return true;
+#else
+ return false;
+#endif
+ }
+
// Whether or not the underlying GPU supports non power of 2 textures.
// NOTE: O3D always supports non power of 2 textures from a public API
// point of view and massages the data underneath to make this work.
diff --git a/o3d/core/cross/renderer_platform.h b/o3d/core/cross/renderer_platform.h
index eb969c2..4a4f58d 100644
--- a/o3d/core/cross/renderer_platform.h
+++ b/o3d/core/cross/renderer_platform.h
@@ -73,6 +73,8 @@
#include "core/cross/gl/renderer_gl.h"
#elif defined(RENDERER_GLES2)
#include "core/cross/gles2/renderer_gles2.h"
+#elif defined(RENDERER_CAIRO)
+#include "core/cross/cairo/renderer_cairo.h"
#else
#error Renderer not recognized.
#endif
diff --git a/o3d/import/cross/collada_conditioner.cc b/o3d/import/cross/collada_conditioner.cc
index b5fef31..796c199 100644
--- a/o3d/import/cross/collada_conditioner.cc
+++ b/o3d/import/cross/collada_conditioner.cc
@@ -542,6 +542,7 @@ bool ColladaConditioner::CompileCg(const FilePath& filename,
const String& shader_source,
const String& vs_entry,
const String& ps_entry) {
+#if !defined(RENDERER_CAIRO)
bool retval = false;
String shader_source_cg = shader_source;
shader_source_cg +=
@@ -574,5 +575,8 @@ bool ColladaConditioner::CompileCg(const FilePath& filename,
}
cgDestroyContext(context);
return retval;
+#else
+ return false;
+#endif
}
} // namespace o3d
diff --git a/o3d/import/import.gyp b/o3d/import/import.gyp
index 9c43b72..08fb4da 100644
--- a/o3d/import/import.gyp
+++ b/o3d/import/import.gyp
@@ -29,7 +29,6 @@
'../../<(jpegdir)/libjpeg.gyp:libjpeg',
'../../<(pngdir)/libpng.gyp:libpng',
'../../<(zlibdir)/zlib.gyp:zlib',
- '../build/libs.gyp:cg_libs',
'../compiler/technique/technique.gyp:o3dTechnique',
],
'sources': [
@@ -50,6 +49,16 @@
'cross/zip_archive.h',
],
+ 'conditions' :[
+ ['renderer != "cairo"',
+ {
+ 'dependencies': [
+ '../build/libs.gyp:cg_libs',
+ ],
+ },
+ ],
+ ],
+
'conditions' : [
['OS == "win"',
{
diff --git a/o3d/plugin/idl/client.idl b/o3d/plugin/idl/client.idl
index 5b1634f..d492c96 100644
--- a/o3d/plugin/idl/client.idl
+++ b/o3d/plugin/idl/client.idl
@@ -156,6 +156,11 @@ class ClientInfo {
True if shaders need to be GLSL instead of Cg/HLSL.
%]
[getter] bool glsl;
+
+ %[
+ True if rendering in 2d mode
+ %]
+ [getter] bool render_2d;
};
%[
diff --git a/o3d/tests/common/linux/testing_common.cc b/o3d/tests/common/linux/testing_common.cc
index d563ce6..1fe628d 100644
--- a/o3d/tests/common/linux/testing_common.cc
+++ b/o3d/tests/common/linux/testing_common.cc
@@ -55,11 +55,14 @@ o3d::DisplayWindow* g_display_window = NULL;
Display *g_display = NULL;
Window g_window = 0;
+#if !defined(RENDERER_CAIRO)
static char kOffScreenRenderer[] = "O3D_D3D9_OFF_SCREEN";
+#endif
extern int test_main(int argc, char **argv);
int main(int argc, char *argv[]) {
+#if !defined(RENDERER_CAIRO)
std::string error;
if (!o3d::RendererInstallCheck(&error)) {
return false;
@@ -168,4 +171,7 @@ int main(int argc, char *argv[]) {
::XCloseDisplay(g_display);
return ret;
+#else
+ return 1;
+#endif
}