| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "content/browser/compositor/software_output_device_mus.h" | 5 #include "services/ui/public/cpp/software_output_device.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "services/ui/public/cpp/bitmap_uploader.h" | 10 #include "services/ui/public/cpp/bitmap_uploader.h" |
| 11 #include "third_party/skia/include/core/SkImageInfo.h" | 11 #include "third_party/skia/include/core/SkImageInfo.h" |
| 12 #include "ui/base/view_prop.h" | |
| 13 #include "ui/compositor/compositor.h" | |
| 14 #include "ui/gfx/skia_util.h" | |
| 15 | 12 |
| 16 #if !defined(OFFICIAL_BUILD) | 13 namespace ui { |
| 17 #include "base/threading/thread_restrictions.h" | |
| 18 #endif | |
| 19 | 14 |
| 20 namespace content { | 15 SoftwareOutputDevice::SoftwareOutputDevice(Window* window) |
| 16 : uploader_(new BitmapUploader(window)) { |
| 17 uploader_->Init(); |
| 18 } |
| 21 | 19 |
| 22 SoftwareOutputDeviceMus::SoftwareOutputDeviceMus(ui::Compositor* compositor) | 20 SoftwareOutputDevice::~SoftwareOutputDevice() {} |
| 23 : compositor_(compositor) {} | |
| 24 | 21 |
| 25 void SoftwareOutputDeviceMus::EndPaint() { | 22 void SoftwareOutputDevice::EndPaint() { |
| 26 SoftwareOutputDevice::EndPaint(); | |
| 27 #if !defined(OFFICIAL_BUILD) | |
| 28 base::ThreadRestrictions::ScopedAllowWait wait; | |
| 29 #endif | |
| 30 | |
| 31 if (!surface_) | 23 if (!surface_) |
| 32 return; | 24 return; |
| 33 | 25 |
| 34 gfx::Rect rect = damage_rect_; | 26 gfx::Rect rect = damage_rect_; |
| 35 rect.Intersect(gfx::Rect(viewport_pixel_size_)); | 27 rect.Intersect(gfx::Rect(viewport_pixel_size_)); |
| 36 if (rect.IsEmpty()) | 28 if (rect.IsEmpty()) |
| 37 return; | 29 return; |
| 38 | 30 |
| 39 gfx::AcceleratedWidget widget = compositor_->widget(); | |
| 40 ui::BitmapUploader* uploader = | |
| 41 reinterpret_cast<ui::BitmapUploader*>(ui::ViewProp::GetValue( | |
| 42 widget, ui::kBitmapUploaderForAcceleratedWidget)); | |
| 43 DCHECK(uploader); | |
| 44 | |
| 45 SkPixmap pixmap; | 31 SkPixmap pixmap; |
| 46 surface_->peekPixels(&pixmap); | 32 surface_->peekPixels(&pixmap); |
| 47 | 33 |
| 48 if (!pixmap.addr()) { | 34 if (!pixmap.addr()) { |
| 49 LOG(WARNING) << "SoftwareOutputDeviceMus: skia surface did not provide us " | 35 LOG(WARNING) << "SoftwareOutputDevice: skia surface did not provide us " |
| 50 "with pixels"; | 36 "with pixels"; |
| 51 return; | 37 return; |
| 52 } | 38 } |
| 53 | 39 |
| 54 const unsigned char* pixels = static_cast<const unsigned char*>( | 40 const unsigned char* pixels = |
| 55 pixmap.addr()); | 41 static_cast<const unsigned char*>(pixmap.addr()); |
| 56 | 42 |
| 57 // TODO(rjkroege): This makes an additional copy. Improve the | 43 // TODO(rjkroege): This makes an additional copy. Improve the |
| 58 // bitmap_uploader API to remove. | 44 // bitmap_uploader API to remove. |
| 59 std::unique_ptr<std::vector<unsigned char>> data( | 45 std::unique_ptr<std::vector<unsigned char>> data( |
| 60 new std::vector<unsigned char>( | 46 new std::vector<unsigned char>( |
| 61 pixels, pixels + pixmap.rowBytes() * viewport_pixel_size_.height())); | 47 pixels, pixels + pixmap.rowBytes() * viewport_pixel_size_.height())); |
| 62 uploader->SetBitmap(viewport_pixel_size_.width(), | 48 uploader_->SetBitmap(viewport_pixel_size_.width(), |
| 63 viewport_pixel_size_.height(), std::move(data), | 49 viewport_pixel_size_.height(), std::move(data), |
| 64 ui::BitmapUploader::BGRA); | 50 ui::BitmapUploader::BGRA); |
| 65 } | 51 } |
| 66 | 52 |
| 67 } // namespace content | 53 } // namespace ui |
| OLD | NEW |