Add a FrameHostMsg_BeginNavigation IPC
[chromium-blink-merge.git] / ui / ozone / platform / caca / caca_surface_factory.cc
blob1535d49631bf3a1cef30b4fd068091c7b728248d
1 // Copyright 2014 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.
5 #include "ui/ozone/platform/caca/caca_surface_factory.h"
7 #include "third_party/skia/include/core/SkBitmap.h"
8 #include "third_party/skia/include/core/SkCanvas.h"
9 #include "third_party/skia/include/core/SkSurface.h"
10 #include "ui/gfx/skia_util.h"
11 #include "ui/gfx/vsync_provider.h"
12 #include "ui/ozone/platform/caca/caca_connection.h"
13 #include "ui/ozone/public/surface_ozone_canvas.h"
15 namespace ui {
17 namespace {
19 const gfx::AcceleratedWidget kDefaultWidgetHandle = 1;
21 class CacaSurface : public ui::SurfaceOzoneCanvas {
22 public:
23 CacaSurface(CacaConnection* connection);
24 virtual ~CacaSurface();
26 bool Initialize();
28 // ui::SurfaceOzoneCanvas overrides:
29 virtual skia::RefPtr<SkCanvas> GetCanvas() OVERRIDE;
30 virtual void ResizeCanvas(const gfx::Size& viewport_size) OVERRIDE;
31 virtual void PresentCanvas(const gfx::Rect& damage) OVERRIDE;
32 virtual scoped_ptr<gfx::VSyncProvider> CreateVSyncProvider() OVERRIDE;
34 private:
35 CacaConnection* connection_; // Not owned.
37 caca_dither_t* dither_;
39 skia::RefPtr<SkSurface> surface_;
41 DISALLOW_COPY_AND_ASSIGN(CacaSurface);
44 CacaSurface::CacaSurface(CacaConnection* connection)
45 : connection_(connection) {}
47 CacaSurface::~CacaSurface() {
48 caca_free_dither(dither_);
51 bool CacaSurface::Initialize() {
52 SkImageInfo info = SkImageInfo::Make(connection_->bitmap_size().width(),
53 connection_->bitmap_size().height(),
54 kN32_SkColorType,
55 kPremul_SkAlphaType);
57 surface_ = skia::AdoptRef(SkSurface::NewRaster(info));
58 if (!surface_) {
59 LOG(ERROR) << "Failed to create SkCanvas";
60 return false;
63 dither_ = caca_create_dither(
64 info.bytesPerPixel() * 8,
65 info.width(),
66 info.height(),
67 info.minRowBytes(),
68 0x00ff0000,
69 0x0000ff00,
70 0x000000ff,
71 0xff000000);
73 return true;
76 skia::RefPtr<SkCanvas> CacaSurface::GetCanvas() {
77 return skia::SharePtr<SkCanvas>(surface_->getCanvas());
80 void CacaSurface::ResizeCanvas(const gfx::Size& viewport_size) {
81 NOTIMPLEMENTED();
84 void CacaSurface::PresentCanvas(const gfx::Rect& damage) {
85 SkImageInfo info;
86 size_t row_bytes;
87 const void* pixels = surface_->peekPixels(&info, &row_bytes);
89 caca_canvas_t* canvas = caca_get_canvas(connection_->display());
90 caca_dither_bitmap(canvas, 0, 0,
91 caca_get_canvas_width(canvas),
92 caca_get_canvas_height(canvas),
93 dither_,
94 static_cast<const uint8_t*>(pixels));
95 caca_refresh_display(connection_->display());
98 scoped_ptr<gfx::VSyncProvider> CacaSurface::CreateVSyncProvider() {
99 return scoped_ptr<gfx::VSyncProvider>();
102 } // namespace
104 CacaSurfaceFactory::CacaSurfaceFactory(CacaConnection* connection)
105 : state_(UNINITIALIZED),
106 connection_(connection) {
109 CacaSurfaceFactory::~CacaSurfaceFactory() {
110 if (state_ == INITIALIZED)
111 ShutdownHardware();
114 ui::SurfaceFactoryOzone::HardwareState
115 CacaSurfaceFactory::InitializeHardware() {
116 connection_->Initialize();
117 state_ = INITIALIZED;
118 return state_;
121 void CacaSurfaceFactory::ShutdownHardware() {
122 CHECK_EQ(INITIALIZED, state_);
123 state_ = UNINITIALIZED;
126 gfx::AcceleratedWidget CacaSurfaceFactory::GetAcceleratedWidget() {
127 return kDefaultWidgetHandle;
130 bool CacaSurfaceFactory::LoadEGLGLES2Bindings(
131 AddGLLibraryCallback add_gl_library,
132 SetGLGetProcAddressProcCallback set_gl_get_proc_address) {
133 NOTREACHED();
134 return false;
137 scoped_ptr<ui::SurfaceOzoneCanvas> CacaSurfaceFactory::CreateCanvasForWidget(
138 gfx::AcceleratedWidget widget) {
139 CHECK_EQ(INITIALIZED, state_);
140 CHECK_EQ(kDefaultWidgetHandle, widget);
142 scoped_ptr<CacaSurface> canvas(new CacaSurface(connection_));
143 CHECK(canvas->Initialize());
144 return canvas.PassAs<ui::SurfaceOzoneCanvas>();
147 } // namespace ui