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