Chromium Code Reviews| 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 "base/threading/thread_restrictions.h" | |
| 8 #include "components/bitmap_uploader/bitmap_uploader.h" | |
| 9 #include "third_party/skia/include/core/SkBitmap.h" | |
| 10 #include "third_party/skia/include/core/SkDevice.h" | |
| 11 #include "ui/base/view_prop.h" | |
| 12 #include "ui/compositor/compositor.h" | |
| 13 #include "ui/gfx/skia_util.h" | |
| 14 #include "ui/gfx/vsync_provider.h" | |
|
Fady Samuel
2015/11/13 07:57:34
nit: is this necessary?
rjkroege
2015/11/13 23:00:11
Done.
| |
| 15 | |
| 16 namespace content { | |
| 17 | |
| 18 SoftwareOutputDeviceMus::SoftwareOutputDeviceMus(ui::Compositor* compositor) | |
| 19 : compositor_(compositor) {} | |
| 20 | |
| 21 void SoftwareOutputDeviceMus::EndPaint() { | |
| 22 SoftwareOutputDevice::EndPaint(); | |
| 23 base::ThreadRestrictions::ScopedAllowWait wait; | |
| 24 | |
| 25 if (!surface_) | |
| 26 return; | |
| 27 | |
| 28 gfx::Rect rect = damage_rect_; | |
| 29 rect.Intersect(gfx::Rect(viewport_pixel_size_)); | |
| 30 if (rect.IsEmpty()) | |
| 31 return; | |
| 32 | |
| 33 gfx::AcceleratedWidget widget = compositor_->widget(); | |
| 34 bitmap_uploader::BitmapUploader* uploader = | |
| 35 reinterpret_cast<bitmap_uploader::BitmapUploader*>(ui::ViewProp::GetValue( | |
| 36 widget, bitmap_uploader::kBitmapUploaderForAcceleratedWidget)); | |
| 37 DCHECK(uploader); | |
| 38 | |
| 39 SkImageInfo info; | |
| 40 size_t rowBytes; | |
| 41 const void* addr = surface_->peekPixels(&info, &rowBytes); | |
| 42 | |
| 43 if (!addr) { | |
| 44 LOG(WARNING) << "SoftwareOutputDeviceMus: skia surface did not provide us " | |
| 45 "with pixels"; | |
| 46 return; | |
| 47 } | |
| 48 | |
| 49 const unsigned char* pixels = static_cast<const unsigned char*>(addr); | |
| 50 | |
| 51 // TODO(rjkroege): This makes an additional copy. Improve the | |
| 52 // bitmap_uploader API to remove. | |
| 53 scoped_ptr<std::vector<unsigned char>> data(new std::vector<unsigned char>( | |
| 54 pixels, pixels + rowBytes * viewport_pixel_size_.height())); | |
| 55 uploader->SetBitmap(viewport_pixel_size_.width(), | |
| 56 viewport_pixel_size_.height(), data.Pass(), | |
| 57 bitmap_uploader::BitmapUploader::BGRA); | |
| 58 } | |
| 59 | |
| 60 } // namespace content | |
| OLD | NEW |