| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/ozone/platform/caca/caca_surface_factory.h" | 5 #include "ui/ozone/platform/caca/caca_surface_factory.h" |
| 6 | 6 |
| 7 #include "third_party/skia/include/core/SkBitmap.h" | 7 #include "third_party/skia/include/core/SkBitmap.h" |
| 8 #include "third_party/skia/include/core/SkCanvas.h" | 8 #include "third_party/skia/include/core/SkCanvas.h" |
| 9 #include "third_party/skia/include/core/SkSurface.h" | 9 #include "third_party/skia/include/core/SkSurface.h" |
| 10 #include "ui/gfx/ozone/surface_ozone_canvas.h" | 10 #include "ui/gfx/ozone/surface_ozone_canvas.h" |
| 11 #include "ui/gfx/skia_util.h" | 11 #include "ui/gfx/skia_util.h" |
| 12 #include "ui/gfx/vsync_provider.h" | 12 #include "ui/gfx/vsync_provider.h" |
| 13 #include "ui/ozone/platform/caca/caca_connection.h" | 13 #include "ui/ozone/platform/caca/caca_connection.h" |
| 14 | 14 |
| 15 namespace ui { | 15 namespace ui { |
| 16 | 16 |
| 17 namespace { | 17 namespace { |
| 18 | 18 |
| 19 const gfx::AcceleratedWidget kDefaultWidgetHandle = 1; | 19 const gfx::AcceleratedWidget kDefaultWidgetHandle = 1; |
| 20 | 20 |
| 21 class CacaSurface : public gfx::SurfaceOzoneCanvas { | 21 class CacaSurface : public gfx::SurfaceOzoneCanvas { |
| 22 public: | 22 public: |
| 23 CacaSurface(CacaConnection* connection); | 23 CacaSurface(CacaConnection* connection); |
| 24 virtual ~CacaSurface(); | 24 virtual ~CacaSurface(); |
| 25 | 25 |
| 26 bool Initialize(); | 26 bool Initialize(); |
| 27 | 27 |
| 28 // gfx::SurfaceOzoneCanvas overrides: | 28 // gfx::SurfaceOzoneCanvas overrides: |
| 29 virtual skia::RefPtr<SkCanvas> GetCanvas() OVERRIDE; | 29 virtual skia::RefPtr<SkCanvas> GetCanvas() OVERRIDE; |
| 30 virtual bool ResizeCanvas(const gfx::Size& viewport_size) OVERRIDE; | 30 virtual void ResizeCanvas(const gfx::Size& viewport_size) OVERRIDE; |
| 31 virtual bool PresentCanvas() OVERRIDE; | 31 virtual void PresentCanvas(const gfx::Rect& damage) OVERRIDE; |
| 32 virtual scoped_ptr<gfx::VSyncProvider> CreateVSyncProvider() OVERRIDE; | 32 virtual scoped_ptr<gfx::VSyncProvider> CreateVSyncProvider() OVERRIDE; |
| 33 | 33 |
| 34 private: | 34 private: |
| 35 CacaConnection* connection_; // Not owned. | 35 CacaConnection* connection_; // Not owned. |
| 36 | 36 |
| 37 caca_dither_t* dither_; | 37 caca_dither_t* dither_; |
| 38 | 38 |
| 39 skia::RefPtr<SkSurface> surface_; | 39 skia::RefPtr<SkSurface> surface_; |
| 40 | 40 |
| 41 DISALLOW_COPY_AND_ASSIGN(CacaSurface); | 41 DISALLOW_COPY_AND_ASSIGN(CacaSurface); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 70 0x000000ff, | 70 0x000000ff, |
| 71 0xff000000); | 71 0xff000000); |
| 72 | 72 |
| 73 return true; | 73 return true; |
| 74 } | 74 } |
| 75 | 75 |
| 76 skia::RefPtr<SkCanvas> CacaSurface::GetCanvas() { | 76 skia::RefPtr<SkCanvas> CacaSurface::GetCanvas() { |
| 77 return skia::SharePtr<SkCanvas>(surface_->getCanvas()); | 77 return skia::SharePtr<SkCanvas>(surface_->getCanvas()); |
| 78 } | 78 } |
| 79 | 79 |
| 80 bool CacaSurface::ResizeCanvas(const gfx::Size& viewport_size) { | 80 void CacaSurface::ResizeCanvas(const gfx::Size& viewport_size) { |
| 81 NOTIMPLEMENTED(); | 81 NOTIMPLEMENTED(); |
| 82 return false; | |
| 83 } | 82 } |
| 84 | 83 |
| 85 bool CacaSurface::PresentCanvas() { | 84 void CacaSurface::PresentCanvas(const gfx::Rect& damage) { |
| 86 SkImageInfo info; | 85 SkImageInfo info; |
| 87 size_t row_bytes; | 86 size_t row_bytes; |
| 88 const void* pixels = surface_->peekPixels(&info, &row_bytes); | 87 const void* pixels = surface_->peekPixels(&info, &row_bytes); |
| 89 | 88 |
| 90 caca_canvas_t* canvas = caca_get_canvas(connection_->display()); | 89 caca_canvas_t* canvas = caca_get_canvas(connection_->display()); |
| 91 caca_dither_bitmap(canvas, 0, 0, | 90 caca_dither_bitmap(canvas, 0, 0, |
| 92 caca_get_canvas_width(canvas), | 91 caca_get_canvas_width(canvas), |
| 93 caca_get_canvas_height(canvas), | 92 caca_get_canvas_height(canvas), |
| 94 dither_, | 93 dither_, |
| 95 static_cast<const uint8_t*>(pixels)); | 94 static_cast<const uint8_t*>(pixels)); |
| 96 caca_refresh_display(connection_->display()); | 95 caca_refresh_display(connection_->display()); |
| 97 | |
| 98 return true; | |
| 99 } | 96 } |
| 100 | 97 |
| 101 scoped_ptr<gfx::VSyncProvider> CacaSurface::CreateVSyncProvider() { | 98 scoped_ptr<gfx::VSyncProvider> CacaSurface::CreateVSyncProvider() { |
| 102 return scoped_ptr<gfx::VSyncProvider>(); | 99 return scoped_ptr<gfx::VSyncProvider>(); |
| 103 } | 100 } |
| 104 | 101 |
| 105 } // namespace | 102 } // namespace |
| 106 | 103 |
| 107 CacaSurfaceFactory::CacaSurfaceFactory(CacaConnection* connection) | 104 CacaSurfaceFactory::CacaSurfaceFactory(CacaConnection* connection) |
| 108 : state_(UNINITIALIZED), | 105 : state_(UNINITIALIZED), |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 gfx::AcceleratedWidget widget) { | 138 gfx::AcceleratedWidget widget) { |
| 142 CHECK_EQ(INITIALIZED, state_); | 139 CHECK_EQ(INITIALIZED, state_); |
| 143 CHECK_EQ(kDefaultWidgetHandle, widget); | 140 CHECK_EQ(kDefaultWidgetHandle, widget); |
| 144 | 141 |
| 145 scoped_ptr<CacaSurface> canvas(new CacaSurface(connection_)); | 142 scoped_ptr<CacaSurface> canvas(new CacaSurface(connection_)); |
| 146 CHECK(canvas->Initialize()); | 143 CHECK(canvas->Initialize()); |
| 147 return canvas.PassAs<gfx::SurfaceOzoneCanvas>(); | 144 return canvas.PassAs<gfx::SurfaceOzoneCanvas>(); |
| 148 } | 145 } |
| 149 | 146 |
| 150 } // namespace ui | 147 } // namespace ui |
| OLD | NEW |