1 // Copyright 2013 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 "cc/output/software_output_device.h" 6 7 #include "base/logging.h" 8 #include "cc/output/software_frame_data.h" 9 #include "third_party/skia/include/core/SkCanvas.h" 10 #include "ui/gfx/skia_util.h" 11 #include "ui/gfx/vsync_provider.h" 12 13 namespace cc { 14 15 SoftwareOutputDevice::SoftwareOutputDevice() : scale_factor_(1.f) { 16 } 17 18 SoftwareOutputDevice::~SoftwareOutputDevice() {} 19 20 void SoftwareOutputDevice::Resize(const gfx::Size& viewport_pixel_size, 21 float scale_factor) { 22 scale_factor_ = scale_factor; 23 24 if (viewport_pixel_size_ == viewport_pixel_size) 25 return; 26 27 SkImageInfo info = SkImageInfo::MakeN32(viewport_pixel_size.width(), 28 viewport_pixel_size.height(), 29 kOpaque_SkAlphaType); 30 viewport_pixel_size_ = viewport_pixel_size; 31 canvas_ = skia::AdoptRef(SkCanvas::NewRaster(info)); 32 } 33 34 SkCanvas* SoftwareOutputDevice::BeginPaint(const gfx::Rect& damage_rect) { 35 DCHECK(canvas_); 36 damage_rect_ = damage_rect; 37 return canvas_.get(); 38 } 39 40 void SoftwareOutputDevice::EndPaint(SoftwareFrameData* frame_data) { 41 DCHECK(frame_data); 42 frame_data->id = 0; 43 frame_data->size = viewport_pixel_size_; 44 frame_data->damage_rect = damage_rect_; 45 } 46 47 void SoftwareOutputDevice::CopyToPixels(const gfx::Rect& rect, void* pixels) { 48 DCHECK(canvas_); 49 SkImageInfo info = SkImageInfo::MakeN32Premul(rect.width(), rect.height()); 50 canvas_->readPixels(info, pixels, info.minRowBytes(), rect.x(), rect.y()); 51 } 52 53 void SoftwareOutputDevice::Scroll(const gfx::Vector2d& delta, 54 const gfx::Rect& clip_rect) { 55 NOTIMPLEMENTED(); 56 } 57 58 void SoftwareOutputDevice::ReclaimSoftwareFrame(unsigned id) { 59 NOTIMPLEMENTED(); 60 } 61 62 gfx::VSyncProvider* SoftwareOutputDevice::GetVSyncProvider() { 63 return vsync_provider_.get(); 64 } 65 66 } // namespace cc 67