| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "content/browser/compositor/software_output_device_mus.h" | |
| 6 | |
| 7 #include <stddef.h> | |
| 8 #include <utility> | |
| 9 | |
| 10 #include "services/ui/public/cpp/bitmap_uploader.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 | |
| 16 #if !defined(OFFICIAL_BUILD) | |
| 17 #include "base/threading/thread_restrictions.h" | |
| 18 #endif | |
| 19 | |
| 20 namespace content { | |
| 21 | |
| 22 SoftwareOutputDeviceMus::SoftwareOutputDeviceMus(ui::Compositor* compositor) | |
| 23 : compositor_(compositor) {} | |
| 24 | |
| 25 void SoftwareOutputDeviceMus::EndPaint() { | |
| 26 SoftwareOutputDevice::EndPaint(); | |
| 27 #if !defined(OFFICIAL_BUILD) | |
| 28 base::ThreadRestrictions::ScopedAllowWait wait; | |
| 29 #endif | |
| 30 | |
| 31 if (!surface_) | |
| 32 return; | |
| 33 | |
| 34 gfx::Rect rect = damage_rect_; | |
| 35 rect.Intersect(gfx::Rect(viewport_pixel_size_)); | |
| 36 if (rect.IsEmpty()) | |
| 37 return; | |
| 38 | |
| 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; | |
| 46 surface_->peekPixels(&pixmap); | |
| 47 | |
| 48 if (!pixmap.addr()) { | |
| 49 LOG(WARNING) << "SoftwareOutputDeviceMus: skia surface did not provide us " | |
| 50 "with pixels"; | |
| 51 return; | |
| 52 } | |
| 53 | |
| 54 const unsigned char* pixels = static_cast<const unsigned char*>( | |
| 55 pixmap.addr()); | |
| 56 | |
| 57 // TODO(rjkroege): This makes an additional copy. Improve the | |
| 58 // bitmap_uploader API to remove. | |
| 59 std::unique_ptr<std::vector<unsigned char>> data( | |
| 60 new std::vector<unsigned char>( | |
| 61 pixels, pixels + pixmap.rowBytes() * viewport_pixel_size_.height())); | |
| 62 uploader->SetBitmap(viewport_pixel_size_.width(), | |
| 63 viewport_pixel_size_.height(), std::move(data), | |
| 64 ui::BitmapUploader::BGRA); | |
| 65 } | |
| 66 | |
| 67 } // namespace content | |
| OLD | NEW |