OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #include "ui/ozone/platform/caca/caca_window_manager.h" |
| 6 |
| 7 #include "base/debug/trace_event.h" |
| 8 #include "third_party/skia/include/core/SkBitmap.h" |
| 9 #include "third_party/skia/include/core/SkCanvas.h" |
| 10 #include "third_party/skia/include/core/SkSurface.h" |
| 11 #include "ui/gfx/skia_util.h" |
| 12 #include "ui/gfx/vsync_provider.h" |
| 13 #include "ui/ozone/platform/caca/caca_window.h" |
| 14 #include "ui/ozone/platform/caca/scoped_caca_types.h" |
| 15 #include "ui/ozone/public/surface_ozone_canvas.h" |
| 16 |
| 17 namespace ui { |
| 18 |
| 19 namespace { |
| 20 |
| 21 const gfx::AcceleratedWidget kDefaultWidgetHandle = 1; |
| 22 |
| 23 class CacaSurface : public ui::SurfaceOzoneCanvas { |
| 24 public: |
| 25 CacaSurface(CacaWindow* window); |
| 26 virtual ~CacaSurface(); |
| 27 |
| 28 bool Initialize(); |
| 29 |
| 30 // ui::SurfaceOzoneCanvas overrides: |
| 31 virtual skia::RefPtr<SkCanvas> GetCanvas() OVERRIDE; |
| 32 virtual void ResizeCanvas(const gfx::Size& viewport_size) OVERRIDE; |
| 33 virtual void PresentCanvas(const gfx::Rect& damage) OVERRIDE; |
| 34 virtual scoped_ptr<gfx::VSyncProvider> CreateVSyncProvider() OVERRIDE; |
| 35 |
| 36 private: |
| 37 CacaWindow* window_; // Not owned. |
| 38 |
| 39 ScopedCacaDither dither_; |
| 40 |
| 41 skia::RefPtr<SkSurface> surface_; |
| 42 |
| 43 DISALLOW_COPY_AND_ASSIGN(CacaSurface); |
| 44 }; |
| 45 |
| 46 CacaSurface::CacaSurface(CacaWindow* window) : window_(window) { |
| 47 } |
| 48 |
| 49 CacaSurface::~CacaSurface() { |
| 50 } |
| 51 |
| 52 bool CacaSurface::Initialize() { |
| 53 ResizeCanvas(window_->bitmap_size()); |
| 54 return true; |
| 55 } |
| 56 |
| 57 skia::RefPtr<SkCanvas> CacaSurface::GetCanvas() { |
| 58 return skia::SharePtr<SkCanvas>(surface_->getCanvas()); |
| 59 } |
| 60 |
| 61 void CacaSurface::ResizeCanvas(const gfx::Size& viewport_size) { |
| 62 TRACE_EVENT0("ozone", "CacaSurface::ResizeCanvas"); |
| 63 |
| 64 VLOG(2) << "creating libcaca surface with from window " << (void*)window_; |
| 65 |
| 66 SkImageInfo info = SkImageInfo::Make(window_->bitmap_size().width(), |
| 67 window_->bitmap_size().height(), |
| 68 kN32_SkColorType, |
| 69 kPremul_SkAlphaType); |
| 70 |
| 71 surface_ = skia::AdoptRef(SkSurface::NewRaster(info)); |
| 72 if (!surface_) |
| 73 LOG(ERROR) << "Failed to create SkSurface"; |
| 74 |
| 75 dither_.reset(caca_create_dither(info.bytesPerPixel() * 8, |
| 76 info.width(), |
| 77 info.height(), |
| 78 info.minRowBytes(), |
| 79 0x00ff0000, |
| 80 0x0000ff00, |
| 81 0x000000ff, |
| 82 0xff000000)); |
| 83 if (!dither_) |
| 84 LOG(ERROR) << "failed to create dither"; |
| 85 } |
| 86 |
| 87 void CacaSurface::PresentCanvas(const gfx::Rect& damage) { |
| 88 TRACE_EVENT0("ozone", "CacaSurface::PresentCanvas"); |
| 89 |
| 90 SkImageInfo info; |
| 91 size_t row_bytes; |
| 92 const void* pixels = surface_->peekPixels(&info, &row_bytes); |
| 93 |
| 94 caca_canvas_t* canvas = caca_get_canvas(window_->display()); |
| 95 caca_dither_bitmap(canvas, |
| 96 0, |
| 97 0, |
| 98 caca_get_canvas_width(canvas), |
| 99 caca_get_canvas_height(canvas), |
| 100 dither_.get(), |
| 101 static_cast<const uint8_t*>(pixels)); |
| 102 caca_refresh_display(window_->display()); |
| 103 } |
| 104 |
| 105 scoped_ptr<gfx::VSyncProvider> CacaSurface::CreateVSyncProvider() { |
| 106 return scoped_ptr<gfx::VSyncProvider>(); |
| 107 } |
| 108 |
| 109 } // namespace |
| 110 |
| 111 CacaWindowManager::CacaWindowManager() { |
| 112 } |
| 113 |
| 114 int32_t CacaWindowManager::AddWindow(CacaWindow* window) { |
| 115 return windows_.Add(window); |
| 116 } |
| 117 |
| 118 void CacaWindowManager::RemoveWindow(int window_id, CacaWindow* window) { |
| 119 DCHECK_EQ(window, windows_.Lookup(window_id)); |
| 120 windows_.Remove(window_id); |
| 121 } |
| 122 |
| 123 CacaWindowManager::~CacaWindowManager() { |
| 124 } |
| 125 |
| 126 ui::SurfaceFactoryOzone::HardwareState CacaWindowManager::InitializeHardware() { |
| 127 return INITIALIZED; |
| 128 } |
| 129 |
| 130 void CacaWindowManager::ShutdownHardware() { |
| 131 } |
| 132 |
| 133 gfx::AcceleratedWidget CacaWindowManager::GetAcceleratedWidget() { |
| 134 NOTREACHED(); |
| 135 return gfx::kNullAcceleratedWidget; |
| 136 } |
| 137 |
| 138 bool CacaWindowManager::LoadEGLGLES2Bindings( |
| 139 AddGLLibraryCallback add_gl_library, |
| 140 SetGLGetProcAddressProcCallback set_gl_get_proc_address) { |
| 141 NOTREACHED(); |
| 142 return false; |
| 143 } |
| 144 |
| 145 scoped_ptr<ui::SurfaceOzoneCanvas> CacaWindowManager::CreateCanvasForWidget( |
| 146 gfx::AcceleratedWidget widget) { |
| 147 CacaWindow* window = windows_.Lookup(widget); |
| 148 DCHECK(window); |
| 149 |
| 150 scoped_ptr<CacaSurface> canvas(new CacaSurface(window)); |
| 151 CHECK(canvas->Initialize()); |
| 152 return canvas.PassAs<ui::SurfaceOzoneCanvas>(); |
| 153 } |
| 154 |
| 155 } // namespace ui |
OLD | NEW |