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_window_manager.h" | 5 #include "ui/ozone/platform/caca/caca_window_manager.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "base/trace_event/trace_event.h" | 10 #include "base/trace_event/trace_event.h" |
11 #include "third_party/skia/include/core/SkCanvas.h" | 11 #include "third_party/skia/include/core/SkCanvas.h" |
| 12 #include "third_party/skia/include/core/SkRefCnt.h" |
12 #include "third_party/skia/include/core/SkSurface.h" | 13 #include "third_party/skia/include/core/SkSurface.h" |
13 #include "ui/gfx/skia_util.h" | 14 #include "ui/gfx/skia_util.h" |
14 #include "ui/gfx/vsync_provider.h" | 15 #include "ui/gfx/vsync_provider.h" |
15 #include "ui/ozone/platform/caca/caca_window.h" | 16 #include "ui/ozone/platform/caca/caca_window.h" |
16 #include "ui/ozone/platform/caca/scoped_caca_types.h" | 17 #include "ui/ozone/platform/caca/scoped_caca_types.h" |
17 #include "ui/ozone/public/surface_ozone_canvas.h" | 18 #include "ui/ozone/public/surface_ozone_canvas.h" |
18 | 19 |
19 namespace ui { | 20 namespace ui { |
20 | 21 |
21 namespace { | 22 namespace { |
22 | 23 |
23 class CacaSurface : public ui::SurfaceOzoneCanvas { | 24 class CacaSurface : public ui::SurfaceOzoneCanvas { |
24 public: | 25 public: |
25 CacaSurface(CacaWindow* window); | 26 CacaSurface(CacaWindow* window); |
26 ~CacaSurface() override; | 27 ~CacaSurface() override; |
27 | 28 |
28 bool Initialize(); | 29 bool Initialize(); |
29 | 30 |
30 // ui::SurfaceOzoneCanvas overrides: | 31 // ui::SurfaceOzoneCanvas overrides: |
31 skia::RefPtr<SkSurface> GetSurface() override; | 32 sk_sp<SkSurface> GetSurface() override; |
32 void ResizeCanvas(const gfx::Size& viewport_size) override; | 33 void ResizeCanvas(const gfx::Size& viewport_size) override; |
33 void PresentCanvas(const gfx::Rect& damage) override; | 34 void PresentCanvas(const gfx::Rect& damage) override; |
34 std::unique_ptr<gfx::VSyncProvider> CreateVSyncProvider() override; | 35 std::unique_ptr<gfx::VSyncProvider> CreateVSyncProvider() override; |
35 | 36 |
36 private: | 37 private: |
37 CacaWindow* window_; // Not owned. | 38 CacaWindow* window_; // Not owned. |
38 | 39 |
39 ScopedCacaDither dither_; | 40 ScopedCacaDither dither_; |
40 | 41 |
41 skia::RefPtr<SkSurface> surface_; | 42 sk_sp<SkSurface> surface_; |
42 | 43 |
43 DISALLOW_COPY_AND_ASSIGN(CacaSurface); | 44 DISALLOW_COPY_AND_ASSIGN(CacaSurface); |
44 }; | 45 }; |
45 | 46 |
46 CacaSurface::CacaSurface(CacaWindow* window) : window_(window) { | 47 CacaSurface::CacaSurface(CacaWindow* window) : window_(window) { |
47 } | 48 } |
48 | 49 |
49 CacaSurface::~CacaSurface() { | 50 CacaSurface::~CacaSurface() { |
50 } | 51 } |
51 | 52 |
52 bool CacaSurface::Initialize() { | 53 bool CacaSurface::Initialize() { |
53 ResizeCanvas(window_->bitmap_size()); | 54 ResizeCanvas(window_->bitmap_size()); |
54 return true; | 55 return true; |
55 } | 56 } |
56 | 57 |
57 skia::RefPtr<SkSurface> CacaSurface::GetSurface() { | 58 sk_sp<SkSurface> CacaSurface::GetSurface() { |
58 return surface_; | 59 return surface_; |
59 } | 60 } |
60 | 61 |
61 void CacaSurface::ResizeCanvas(const gfx::Size& viewport_size) { | 62 void CacaSurface::ResizeCanvas(const gfx::Size& viewport_size) { |
62 TRACE_EVENT0("ozone", "CacaSurface::ResizeCanvas"); | 63 TRACE_EVENT0("ozone", "CacaSurface::ResizeCanvas"); |
63 | 64 |
64 VLOG(2) << "creating libcaca surface with from window " << (void*)window_; | 65 VLOG(2) << "creating libcaca surface with from window " << (void*)window_; |
65 | 66 |
66 SkImageInfo info = SkImageInfo::Make(window_->bitmap_size().width(), | 67 SkImageInfo info = SkImageInfo::Make(window_->bitmap_size().width(), |
67 window_->bitmap_size().height(), | 68 window_->bitmap_size().height(), |
68 kN32_SkColorType, | 69 kN32_SkColorType, |
69 kPremul_SkAlphaType); | 70 kPremul_SkAlphaType); |
70 | 71 |
71 surface_ = skia::AdoptRef(SkSurface::NewRaster(info)); | 72 surface_ = SkSurface::MakeRaster(info); |
72 if (!surface_) | 73 if (!surface_) |
73 LOG(ERROR) << "Failed to create SkSurface"; | 74 LOG(ERROR) << "Failed to create SkSurface"; |
74 | 75 |
75 dither_.reset(caca_create_dither(info.bytesPerPixel() * 8, | 76 dither_.reset(caca_create_dither(info.bytesPerPixel() * 8, |
76 info.width(), | 77 info.width(), |
77 info.height(), | 78 info.height(), |
78 info.minRowBytes(), | 79 info.minRowBytes(), |
79 0x00ff0000, | 80 0x00ff0000, |
80 0x0000ff00, | 81 0x0000ff00, |
81 0x000000ff, | 82 0x000000ff, |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 CacaWindow* window = windows_.Lookup(widget); | 133 CacaWindow* window = windows_.Lookup(widget); |
133 DCHECK(window); | 134 DCHECK(window); |
134 | 135 |
135 std::unique_ptr<CacaSurface> canvas(new CacaSurface(window)); | 136 std::unique_ptr<CacaSurface> canvas(new CacaSurface(window)); |
136 bool initialized = canvas->Initialize(); | 137 bool initialized = canvas->Initialize(); |
137 DCHECK(initialized); | 138 DCHECK(initialized); |
138 return std::move(canvas); | 139 return std::move(canvas); |
139 } | 140 } |
140 | 141 |
141 } // namespace ui | 142 } // namespace ui |
OLD | NEW |