diff options
author | halliwell <halliwell@chromium.org> | 2015-04-28 09:59:41 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-04-28 17:01:18 +0000 |
commit | 3da8f19ab50e6416f0691f34fe45b007dd886e59 (patch) | |
tree | 15753085b1360defdd83724f983eebd9ff28f2ac | |
parent | df0e26664beb1101a3325ead9174cffcd0d33f72 (diff) | |
download | chromium_src-3da8f19ab50e6416f0691f34fe45b007dd886e59.zip chromium_src-3da8f19ab50e6416f0691f34fe45b007dd886e59.tar.gz chromium_src-3da8f19ab50e6416f0691f34fe45b007dd886e59.tar.bz2 |
Adds public API and loads Cast OSD plane implementation from shared lib
BUG=
Review URL: https://codereview.chromium.org/1104853002
Cr-Commit-Position: refs/heads/master@{#327306}
-rw-r--r-- | chromecast/chromecast.gyp | 15 | ||||
-rw-r--r-- | chromecast/graphics/osd_plane_default.cc | 73 | ||||
-rw-r--r-- | chromecast/public/cast_egl_platform.h | 8 | ||||
-rw-r--r-- | chromecast/public/graphics_types.h | 30 | ||||
-rw-r--r-- | chromecast/public/osd_plane.h | 40 | ||||
-rw-r--r-- | chromecast/public/osd_plane_shlib.h | 25 | ||||
-rw-r--r-- | chromecast/public/osd_surface.h | 56 | ||||
-rw-r--r-- | ui/ozone/platform/cast/surface_factory_cast.cc | 7 |
8 files changed, 238 insertions, 16 deletions
diff --git a/chromecast/chromecast.gyp b/chromecast/chromecast.gyp index 5c2e49c..a9892ab 100644 --- a/chromecast/chromecast.gyp +++ b/chromecast/chromecast.gyp @@ -40,7 +40,11 @@ 'public/cast_egl_platform_shlib.h', 'public/cast_sys_info.h', 'public/chromecast_export.h', - 'public/graphics_properties_shlib.h' + 'public/graphics_properties_shlib.h', + 'public/graphics_types.h', + 'public/osd_plane.h', + 'public/osd_plane_shlib.h', + 'public/osd_surface.h', ], }, # TODO(gunsch): Remove this fake target once it's either added or no @@ -578,11 +582,7 @@ 'media/media.gyp:cast_media', ], 'conditions': [ - ['chromecast_branding=="Chrome"', { - 'dependencies': [ - 'internal/chromecast_internal.gyp:cast_gfx_internal', - ], - }, { + ['chromecast_branding!="Chrome"', { 'dependencies': [ '../ui/ozone/ozone.gyp:eglplatform_shim_x11', ], @@ -621,7 +621,8 @@ ], 'sources': [ 'graphics/cast_egl_platform_default.cc', - 'graphics/graphics_properties_default.cc' + 'graphics/graphics_properties_default.cc', + 'graphics/osd_plane_default.cc' ], } ] diff --git a/chromecast/graphics/osd_plane_default.cc b/chromecast/graphics/osd_plane_default.cc new file mode 100644 index 0000000..2c73edc --- /dev/null +++ b/chromecast/graphics/osd_plane_default.cc @@ -0,0 +1,73 @@ +// Copyright 2015 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 "base/memory/scoped_ptr.h" +#include "chromecast/public/graphics_types.h" +#include "chromecast/public/osd_plane.h" +#include "chromecast/public/osd_plane_shlib.h" +#include "chromecast/public/osd_surface.h" + +namespace chromecast { +namespace { + +// Default no-op OsdSurface implementation +class OsdSurfaceDefault : public OsdSurface { + public: + OsdSurfaceDefault(const Size& size) : size_(size) {} + + // OsdSurface implementation: + void Blit(OsdSurface* src_surface, + const Rect& src_rect, + const Point& dst_point) override {} + void Composite(OsdSurface* src_surface, + const Rect& src_rect, + const Point& dst_point) override {} + void CopyBitmap(char* src_bitmap, + const Rect& src_rect, + const Rect& damage_rect, + const Point& dst_point) override {} + void Fill(const Rect& rect, int argb) override {} + + const Size& size() const override { return size_; } + + private: + const Size size_; + + DISALLOW_COPY_AND_ASSIGN(OsdSurfaceDefault); +}; + +// Default no-op OsdPlane implementation +class OsdPlaneDefault : public OsdPlane { + public: + OsdPlaneDefault() : size_(0, 0) {} + + // OsdPlane implementation: + OsdSurface* CreateSurface(const Size& size) override { + return new OsdSurfaceDefault(size); + } + void SetClipRectangle(const Rect& rect) override { + size_ = Size(rect.width, rect.height); + } + OsdSurface* GetBackBuffer() override { + if (!back_buffer_) + back_buffer_.reset(new OsdSurfaceDefault(size_)); + return back_buffer_.get(); + } + + void Flip() override {} + + private: + scoped_ptr<OsdSurface> back_buffer_; + Size size_; + + DISALLOW_COPY_AND_ASSIGN(OsdPlaneDefault); +}; + +} // namespace + +OsdPlane* OsdPlaneShlib::Create(const std::vector<std::string>& argv) { + return new OsdPlaneDefault; +} + +} // namespace chromecast diff --git a/chromecast/public/cast_egl_platform.h b/chromecast/public/cast_egl_platform.h index c93bd0f..c1350f69 100644 --- a/chromecast/public/cast_egl_platform.h +++ b/chromecast/public/cast_egl_platform.h @@ -7,17 +7,13 @@ namespace chromecast { +struct Size; + // Interface representing all the hardware-specific elements of an Ozone // implementation for Cast. Supply an implementation of this interface // to OzonePlatformCast to create a complete Ozone implementation. class CastEglPlatform { public: - struct Size { - Size(int w, int h) : width(w), height(h) {} - const int width; - const int height; - }; - typedef void* (*GLGetProcAddressProc)(const char* name); typedef void* NativeDisplayType; typedef void* NativeWindowType; diff --git a/chromecast/public/graphics_types.h b/chromecast/public/graphics_types.h new file mode 100644 index 0000000..09ac12b --- /dev/null +++ b/chromecast/public/graphics_types.h @@ -0,0 +1,30 @@ +// Copyright (c) 2015 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. + +#ifndef CHROMECAST_PUBLIC_GRAPHICS_TYPES_H_ +#define CHROMECAST_PUBLIC_GRAPHICS_TYPES_H_ + +namespace chromecast { + +struct Rect { + Rect(int w, int h) : x(0), y(0), width(w), height(h) {} + Rect(int arg_x, int arg_y, int w, int h) + : x(arg_x), y(arg_y), width(w), height(h) {} + + int x; + int y; + int width; + int height; +}; + +struct Size { + Size(int w, int h) : width(w), height(h) {} + + int width; + int height; +}; + +} // namespace chromecast + +#endif // CHROMECAST_PUBLIC_GRAPHICS_TYPES_H_ diff --git a/chromecast/public/osd_plane.h b/chromecast/public/osd_plane.h new file mode 100644 index 0000000..d689cba --- /dev/null +++ b/chromecast/public/osd_plane.h @@ -0,0 +1,40 @@ +// Copyright (c) 2015 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. + +#ifndef CHROMECAST_PUBLIC_OSD_PLANE_H_ +#define CHROMECAST_PUBLIC_OSD_PLANE_H_ + +namespace chromecast { + +class OsdSurface; +struct Rect; +struct Size; + +// Abstract graphics plane for OSD, to be implemented in platform-specific way. +// Platform must composite this plane on top of main (GL-based) graphics plane. +class OsdPlane { + public: + virtual ~OsdPlane() {} + + // Creates a surface for offscreen drawing. + virtual OsdSurface* CreateSurface(const Size& size) = 0; + + // Sets a clip rectangle, client should call before drawing to back buffer + // to specify the area they intend to draw on. Platforms may reduce memory + // usage by only allocating back buffer to cover this area. Areas outside + // clip rectangle must display as fully transparent. In particular, setting + // an empty clip rectangle and calling Flip should clear the plane. + virtual void SetClipRectangle(const Rect& rect) = 0; + + // Gets the current back buffer surface. Valid until next call to Flip or + // SetClipRectangle. + virtual OsdSurface* GetBackBuffer() = 0; + + // Presents current back buffer to screen. + virtual void Flip() = 0; +}; + +} // namespace chromecast + +#endif // CHROMECAST_PUBLIC_OSD_PLANE_H diff --git a/chromecast/public/osd_plane_shlib.h b/chromecast/public/osd_plane_shlib.h new file mode 100644 index 0000000..0ee170b --- /dev/null +++ b/chromecast/public/osd_plane_shlib.h @@ -0,0 +1,25 @@ +// Copyright 2015 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. + +#ifndef CHROMECAST_PUBLIC_OSD_PLANE_SHLIB_H_ +#define CHROMECAST_PUBLIC_OSD_PLANE_SHLIB_H_ + +#include <string> +#include <vector> + +#include "chromecast_export.h" + +namespace chromecast { + +class OsdPlane; + +// Entry point for loading OsdPlane from shared library. +class CHROMECAST_EXPORT OsdPlaneShlib { + public: + static OsdPlane* Create(const std::vector<std::string>& argv); +}; + +} // namespace chromecast + +#endif // CHROMECAST_PUBLIC_OSD_PLANE_SHLIB_H_ diff --git a/chromecast/public/osd_surface.h b/chromecast/public/osd_surface.h new file mode 100644 index 0000000..c83c065 --- /dev/null +++ b/chromecast/public/osd_surface.h @@ -0,0 +1,56 @@ +// Copyright (c) 2015 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. + +#ifndef CHROMECAST_PUBLIC_OSD_SURFACE_H_ +#define CHROMECAST_PUBLIC_OSD_SURFACE_H_ + +namespace chromecast { + +struct Rect; +struct Size; + +// Provides simple API (copy bitmap, blit, composite and fill) for drawing +// OSD graphics on OsdPlane. Hardware-specific implementation should be +// instantiated by OsdPlane. +class OsdSurface { + public: + struct Point { + Point(int arg_x, int arg_y) : x(arg_x), y(arg_y) {} + + const int x; + const int y; + }; + + virtual ~OsdSurface() {} + + // Blits(fast copy) bitmap from a surface. Copies |src_rect| area of surface + // |dst_point| of this surface. + virtual void Blit(OsdSurface* src_surface, + const Rect& src_rect, + const Point& dst_point) = 0; + + // Composites ARGB values of |src_surface| on top of this surface. It is NOT + // copy. Used when displaying OSD images on same plane. + virtual void Composite(OsdSurface* src_surface, + const Rect& src_rect, + const Point& dst_point) = 0; + + // Copies |damage_rect| area of src bitmap into |dst_point| of this surface. + // It is similar to Blit() except that it accepts arbitrary bitmap pointer + // instead of surface. + virtual void CopyBitmap(char* src_bitmap, + const Rect& src_rect, + const Rect& damage_rect, + const Point& dst_point) = 0; + + // Fills |rect| area of surface with |argb| value. + virtual void Fill(const Rect& rect, int argb) = 0; + + // Returns the dimensions of the surface. + virtual const Size& size() const = 0; +}; + +} // namespace chromecast + +#endif // CHROMECAST_PUBLIC_OSD_SURFACE_H_ diff --git a/ui/ozone/platform/cast/surface_factory_cast.cc b/ui/ozone/platform/cast/surface_factory_cast.cc index 35b1890..6fdd7ef 100644 --- a/ui/ozone/platform/cast/surface_factory_cast.cc +++ b/ui/ozone/platform/cast/surface_factory_cast.cc @@ -6,14 +6,15 @@ #include "base/callback_helpers.h" #include "chromecast/public/cast_egl_platform.h" +#include "chromecast/public/graphics_types.h" #include "ui/ozone/platform/cast/surface_ozone_egl_cast.h" using chromecast::CastEglPlatform; namespace ui { namespace { -CastEglPlatform::Size FromGfxSize(const gfx::Size& size) { - return CastEglPlatform::Size(size.width(), size.height()); +chromecast::Size FromGfxSize(const gfx::Size& size) { + return chromecast::Size(size.width(), size.height()); } // Hard lower bound on display resolution @@ -75,7 +76,7 @@ void SurfaceFactoryCast::CreateDisplayTypeAndWindowIfNeeded() { } DCHECK_EQ(state_, kInitialized); if (!have_display_type_) { - CastEglPlatform::Size create_size = FromGfxSize(display_size_); + chromecast::Size create_size = FromGfxSize(display_size_); display_type_ = egl_platform_->CreateDisplayType(create_size); have_display_type_ = true; window_ = egl_platform_->CreateWindow(display_type_, create_size); |