| 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 class CacaSurface : public ui::SurfaceOzoneCanvas { | |
| 22 public: | |
| 23 CacaSurface(CacaWindow* window); | |
| 24 virtual ~CacaSurface(); | |
| 25 | |
| 26 bool Initialize(); | |
| 27 | |
| 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; | |
| 33 | |
| 34 private: | |
| 35 CacaWindow* window_; // Not owned. | |
| 36 | |
| 37 ScopedCacaDither dither_; | |
| 38 | |
| 39 skia::RefPtr<SkSurface> surface_; | |
| 40 | |
| 41 DISALLOW_COPY_AND_ASSIGN(CacaSurface); | |
| 42 }; | |
| 43 | |
| 44 CacaSurface::CacaSurface(CacaWindow* window) : window_(window) { | |
| 45 } | |
| 46 | |
| 47 CacaSurface::~CacaSurface() { | |
| 48 } | |
| 49 | |
| 50 bool CacaSurface::Initialize() { | |
| 51 ResizeCanvas(window_->bitmap_size()); | |
| 52 return true; | |
| 53 } | |
| 54 | |
| 55 skia::RefPtr<SkCanvas> CacaSurface::GetCanvas() { | |
| 56 return skia::SharePtr<SkCanvas>(surface_->getCanvas()); | |
| 57 } | |
| 58 | |
| 59 void CacaSurface::ResizeCanvas(const gfx::Size& viewport_size) { | |
| 60 TRACE_EVENT0("ozone", "CacaSurface::ResizeCanvas"); | |
| 61 | |
| 62 VLOG(2) << "creating libcaca surface with from window " << (void*)window_; | |
| 63 | |
| 64 SkImageInfo info = SkImageInfo::Make(window_->bitmap_size().width(), | |
| 65 window_->bitmap_size().height(), | |
| 66 kN32_SkColorType, | |
| 67 kPremul_SkAlphaType); | |
| 68 | |
| 69 surface_ = skia::AdoptRef(SkSurface::NewRaster(info)); | |
| 70 if (!surface_) | |
| 71 LOG(ERROR) << "Failed to create SkSurface"; | |
| 72 | |
| 73 dither_.reset(caca_create_dither(info.bytesPerPixel() * 8, | |
| 74 info.width(), | |
| 75 info.height(), | |
| 76 info.minRowBytes(), | |
| 77 0x00ff0000, | |
| 78 0x0000ff00, | |
| 79 0x000000ff, | |
| 80 0xff000000)); | |
| 81 if (!dither_) | |
| 82 LOG(ERROR) << "failed to create dither"; | |
| 83 } | |
| 84 | |
| 85 void CacaSurface::PresentCanvas(const gfx::Rect& damage) { | |
| 86 TRACE_EVENT0("ozone", "CacaSurface::PresentCanvas"); | |
| 87 | |
| 88 SkImageInfo info; | |
| 89 size_t row_bytes; | |
| 90 const void* pixels = surface_->peekPixels(&info, &row_bytes); | |
| 91 | |
| 92 caca_canvas_t* canvas = caca_get_canvas(window_->display()); | |
| 93 caca_dither_bitmap(canvas, | |
| 94 0, | |
| 95 0, | |
| 96 caca_get_canvas_width(canvas), | |
| 97 caca_get_canvas_height(canvas), | |
| 98 dither_.get(), | |
| 99 static_cast<const uint8_t*>(pixels)); | |
| 100 caca_refresh_display(window_->display()); | |
| 101 } | |
| 102 | |
| 103 scoped_ptr<gfx::VSyncProvider> CacaSurface::CreateVSyncProvider() { | |
| 104 return scoped_ptr<gfx::VSyncProvider>(); | |
| 105 } | |
| 106 | |
| 107 } // namespace | |
| 108 | |
| 109 CacaWindowManager::CacaWindowManager() { | |
| 110 } | |
| 111 | |
| 112 int32_t CacaWindowManager::AddWindow(CacaWindow* window) { | |
| 113 return windows_.Add(window); | |
| 114 } | |
| 115 | |
| 116 void CacaWindowManager::RemoveWindow(int window_id, CacaWindow* window) { | |
| 117 DCHECK_EQ(window, windows_.Lookup(window_id)); | |
| 118 windows_.Remove(window_id); | |
| 119 } | |
| 120 | |
| 121 CacaWindowManager::~CacaWindowManager() { | |
| 122 } | |
| 123 | |
| 124 bool CacaWindowManager::LoadEGLGLES2Bindings( | |
| 125 AddGLLibraryCallback add_gl_library, | |
| 126 SetGLGetProcAddressProcCallback set_gl_get_proc_address) { | |
| 127 return false; | |
| 128 } | |
| 129 | |
| 130 scoped_ptr<ui::SurfaceOzoneCanvas> CacaWindowManager::CreateCanvasForWidget( | |
| 131 gfx::AcceleratedWidget widget) { | |
| 132 CacaWindow* window = windows_.Lookup(widget); | |
| 133 DCHECK(window); | |
| 134 | |
| 135 scoped_ptr<CacaSurface> canvas(new CacaSurface(window)); | |
| 136 bool initialized = canvas->Initialize(); | |
| 137 DCHECK(initialized); | |
| 138 return canvas.Pass(); | |
| 139 } | |
| 140 | |
| 141 } // namespace ui | |
| OLD | NEW |