1 // Copyright 2012 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.
5 #include "cc/output/software_renderer.h"
7 #include "base/debug/trace_event.h"
8 #include "cc/base/math_util.h"
9 #include "cc/output/compositor_frame.h"
10 #include "cc/output/compositor_frame_ack.h"
11 #include "cc/output/compositor_frame_metadata.h"
12 #include "cc/output/copy_output_request.h"
13 #include "cc/output/output_surface.h"
14 #include "cc/output/render_surface_filters.h"
15 #include "cc/output/software_output_device.h"
16 #include "cc/quads/checkerboard_draw_quad.h"
17 #include "cc/quads/debug_border_draw_quad.h"
18 #include "cc/quads/picture_draw_quad.h"
19 #include "cc/quads/render_pass_draw_quad.h"
20 #include "cc/quads/solid_color_draw_quad.h"
21 #include "cc/quads/texture_draw_quad.h"
22 #include "cc/quads/tile_draw_quad.h"
23 #include "skia/ext/opacity_draw_filter.h"
24 #include "third_party/skia/include/core/SkCanvas.h"
25 #include "third_party/skia/include/core/SkColor.h"
26 #include "third_party/skia/include/core/SkImageFilter.h"
27 #include "third_party/skia/include/core/SkMatrix.h"
28 #include "third_party/skia/include/core/SkShader.h"
29 #include "third_party/skia/include/effects/SkLayerRasterizer.h"
30 #include "ui/gfx/rect_conversions.h"
31 #include "ui/gfx/skia_util.h"
32 #include "ui/gfx/transform.h"
38 static inline bool IsScalarNearlyInteger(SkScalar scalar
) {
39 return SkScalarNearlyZero(scalar
- SkScalarRoundToScalar(scalar
));
42 bool IsScaleAndIntegerTranslate(const SkMatrix
& matrix
) {
43 return IsScalarNearlyInteger(matrix
[SkMatrix::kMTransX
]) &&
44 IsScalarNearlyInteger(matrix
[SkMatrix::kMTransY
]) &&
45 SkScalarNearlyZero(matrix
[SkMatrix::kMSkewX
]) &&
46 SkScalarNearlyZero(matrix
[SkMatrix::kMSkewY
]) &&
47 SkScalarNearlyZero(matrix
[SkMatrix::kMPersp0
]) &&
48 SkScalarNearlyZero(matrix
[SkMatrix::kMPersp1
]) &&
49 SkScalarNearlyZero(matrix
[SkMatrix::kMPersp2
] - 1.0f
);
52 static SkShader::TileMode
WrapModeToTileMode(GLint wrap_mode
) {
55 return SkShader::kRepeat_TileMode
;
56 case GL_CLAMP_TO_EDGE
:
57 return SkShader::kClamp_TileMode
;
60 return SkShader::kClamp_TileMode
;
63 } // anonymous namespace
65 scoped_ptr
<SoftwareRenderer
> SoftwareRenderer::Create(
66 RendererClient
* client
,
67 const LayerTreeSettings
* settings
,
68 OutputSurface
* output_surface
,
69 ResourceProvider
* resource_provider
) {
70 return make_scoped_ptr(new SoftwareRenderer(
71 client
, settings
, output_surface
, resource_provider
));
74 SoftwareRenderer::SoftwareRenderer(RendererClient
* client
,
75 const LayerTreeSettings
* settings
,
76 OutputSurface
* output_surface
,
77 ResourceProvider
* resource_provider
)
78 : DirectRenderer(client
, settings
, output_surface
, resource_provider
),
80 is_scissor_enabled_(false),
81 is_backbuffer_discarded_(false),
82 output_device_(output_surface
->software_device()),
83 current_canvas_(NULL
) {
84 if (resource_provider_
) {
85 capabilities_
.max_texture_size
= resource_provider_
->max_texture_size();
86 capabilities_
.best_texture_format
=
87 resource_provider_
->best_texture_format();
89 // The updater can access bitmaps while the SoftwareRenderer is using them.
90 capabilities_
.allow_partial_texture_updates
= true;
91 capabilities_
.using_partial_swap
= true;
93 capabilities_
.using_map_image
= settings_
->use_map_image
;
94 capabilities_
.using_shared_memory_resources
= true;
97 SoftwareRenderer::~SoftwareRenderer() {}
99 const RendererCapabilitiesImpl
& SoftwareRenderer::Capabilities() const {
100 return capabilities_
;
103 void SoftwareRenderer::BeginDrawingFrame(DrawingFrame
* frame
) {
104 TRACE_EVENT0("cc", "SoftwareRenderer::BeginDrawingFrame");
105 root_canvas_
= output_device_
->BeginPaint(
106 gfx::ToEnclosingRect(frame
->root_damage_rect
));
109 void SoftwareRenderer::FinishDrawingFrame(DrawingFrame
* frame
) {
110 TRACE_EVENT0("cc", "SoftwareRenderer::FinishDrawingFrame");
111 current_framebuffer_lock_
.reset();
112 current_canvas_
= NULL
;
115 current_frame_data_
.reset(new SoftwareFrameData
);
116 output_device_
->EndPaint(current_frame_data_
.get());
119 void SoftwareRenderer::SwapBuffers(const CompositorFrameMetadata
& metadata
) {
120 CompositorFrame compositor_frame
;
121 compositor_frame
.metadata
= metadata
;
122 compositor_frame
.software_frame_data
= current_frame_data_
.Pass();
123 output_surface_
->SwapBuffers(&compositor_frame
);
126 void SoftwareRenderer::ReceiveSwapBuffersAck(const CompositorFrameAck
& ack
) {
127 output_device_
->ReclaimSoftwareFrame(ack
.last_software_frame_id
);
130 bool SoftwareRenderer::FlippedFramebuffer() const {
134 void SoftwareRenderer::EnsureScissorTestEnabled() {
135 is_scissor_enabled_
= true;
136 SetClipRect(scissor_rect_
);
139 void SoftwareRenderer::EnsureScissorTestDisabled() {
140 // There is no explicit notion of enabling/disabling scissoring in software
141 // rendering, but the underlying effect we want is to clear any existing
142 // clipRect on the current SkCanvas. This is done by setting clipRect to
143 // the viewport's dimensions.
144 is_scissor_enabled_
= false;
145 SkBaseDevice
* device
= current_canvas_
->getDevice();
146 SetClipRect(gfx::Rect(device
->width(), device
->height()));
149 void SoftwareRenderer::Finish() {}
151 void SoftwareRenderer::BindFramebufferToOutputSurface(DrawingFrame
* frame
) {
152 DCHECK(!output_surface_
->HasExternalStencilTest());
153 current_framebuffer_lock_
.reset();
154 current_canvas_
= root_canvas_
;
157 bool SoftwareRenderer::BindFramebufferToTexture(
159 const ScopedResource
* texture
,
160 const gfx::Rect
& target_rect
) {
161 current_framebuffer_lock_
.reset();
162 current_framebuffer_lock_
= make_scoped_ptr(
163 new ResourceProvider::ScopedWriteLockSoftware(
164 resource_provider_
, texture
->id()));
165 current_canvas_
= current_framebuffer_lock_
->sk_canvas();
166 InitializeViewport(frame
,
168 gfx::Rect(target_rect
.size()),
173 void SoftwareRenderer::SetScissorTestRect(const gfx::Rect
& scissor_rect
) {
174 is_scissor_enabled_
= true;
175 scissor_rect_
= scissor_rect
;
176 SetClipRect(scissor_rect
);
179 void SoftwareRenderer::SetClipRect(const gfx::Rect
& rect
) {
180 // Skia applies the current matrix to clip rects so we reset it temporary.
181 SkMatrix current_matrix
= current_canvas_
->getTotalMatrix();
182 current_canvas_
->resetMatrix();
183 current_canvas_
->clipRect(gfx::RectToSkRect(rect
), SkRegion::kReplace_Op
);
184 current_canvas_
->setMatrix(current_matrix
);
187 void SoftwareRenderer::ClearCanvas(SkColor color
) {
188 // SkCanvas::clear doesn't respect the current clipping region
189 // so we SkCanvas::drawColor instead if scissoring is active.
190 if (is_scissor_enabled_
)
191 current_canvas_
->drawColor(color
, SkXfermode::kSrc_Mode
);
193 current_canvas_
->clear(color
);
196 void SoftwareRenderer::DiscardPixels(bool has_external_stencil_test
,
197 bool draw_rect_covers_full_surface
) {}
199 void SoftwareRenderer::ClearFramebuffer(DrawingFrame
* frame
,
200 bool has_external_stencil_test
) {
201 if (frame
->current_render_pass
->has_transparent_background
) {
202 ClearCanvas(SkColorSetARGB(0, 0, 0, 0));
205 // On DEBUG builds, opaque render passes are cleared to blue
206 // to easily see regions that were not drawn on the screen.
207 ClearCanvas(SkColorSetARGB(255, 0, 0, 255));
212 void SoftwareRenderer::SetDrawViewport(
213 const gfx::Rect
& window_space_viewport
) {}
215 bool SoftwareRenderer::IsSoftwareResource(
216 ResourceProvider::ResourceId resource_id
) const {
217 switch (resource_provider_
->GetResourceType(resource_id
)) {
218 case ResourceProvider::GLTexture
:
220 case ResourceProvider::Bitmap
:
222 case ResourceProvider::InvalidType
:
226 LOG(FATAL
) << "Invalid resource type.";
230 void SoftwareRenderer::DoDrawQuad(DrawingFrame
* frame
, const DrawQuad
* quad
) {
231 TRACE_EVENT0("cc", "SoftwareRenderer::DoDrawQuad");
232 gfx::Transform quad_rect_matrix
;
233 QuadRectTransform(&quad_rect_matrix
, quad
->quadTransform(), quad
->rect
);
234 gfx::Transform contents_device_transform
=
235 frame
->window_matrix
* frame
->projection_matrix
* quad_rect_matrix
;
236 contents_device_transform
.FlattenTo2d();
237 SkMatrix sk_device_matrix
;
238 gfx::TransformToFlattenedSkMatrix(contents_device_transform
,
240 current_canvas_
->setMatrix(sk_device_matrix
);
242 current_paint_
.reset();
243 if (!IsScaleAndIntegerTranslate(sk_device_matrix
)) {
244 // TODO(danakj): Until we can enable AA only on exterior edges of the
245 // layer, disable AA if any interior edges are present. crbug.com/248175
246 bool all_four_edges_are_exterior
= quad
->IsTopEdge() &&
247 quad
->IsLeftEdge() &&
248 quad
->IsBottomEdge() &&
250 if (settings_
->allow_antialiasing
&& all_four_edges_are_exterior
)
251 current_paint_
.setAntiAlias(true);
252 current_paint_
.setFilterBitmap(true);
255 if (quad
->ShouldDrawWithBlending()) {
256 current_paint_
.setAlpha(quad
->opacity() * 255);
257 current_paint_
.setXfermodeMode(SkXfermode::kSrcOver_Mode
);
259 current_paint_
.setXfermodeMode(SkXfermode::kSrc_Mode
);
262 switch (quad
->material
) {
263 case DrawQuad::CHECKERBOARD
:
264 DrawCheckerboardQuad(frame
, CheckerboardDrawQuad::MaterialCast(quad
));
266 case DrawQuad::DEBUG_BORDER
:
267 DrawDebugBorderQuad(frame
, DebugBorderDrawQuad::MaterialCast(quad
));
269 case DrawQuad::PICTURE_CONTENT
:
270 DrawPictureQuad(frame
, PictureDrawQuad::MaterialCast(quad
));
272 case DrawQuad::RENDER_PASS
:
273 DrawRenderPassQuad(frame
, RenderPassDrawQuad::MaterialCast(quad
));
275 case DrawQuad::SOLID_COLOR
:
276 DrawSolidColorQuad(frame
, SolidColorDrawQuad::MaterialCast(quad
));
278 case DrawQuad::TEXTURE_CONTENT
:
279 DrawTextureQuad(frame
, TextureDrawQuad::MaterialCast(quad
));
281 case DrawQuad::TILED_CONTENT
:
282 DrawTileQuad(frame
, TileDrawQuad::MaterialCast(quad
));
284 case DrawQuad::SURFACE_CONTENT
:
285 // Surface content should be fully resolved to other quad types before
286 // reaching a direct renderer.
289 case DrawQuad::INVALID
:
290 case DrawQuad::IO_SURFACE_CONTENT
:
291 case DrawQuad::YUV_VIDEO_CONTENT
:
292 case DrawQuad::STREAM_VIDEO_CONTENT
:
293 DrawUnsupportedQuad(frame
, quad
);
298 current_canvas_
->resetMatrix();
301 void SoftwareRenderer::DrawCheckerboardQuad(const DrawingFrame
* frame
,
302 const CheckerboardDrawQuad
* quad
) {
303 gfx::RectF visible_quad_vertex_rect
= MathUtil::ScaleRectProportional(
304 QuadVertexRect(), quad
->rect
, quad
->visible_rect
);
305 current_paint_
.setColor(quad
->color
);
306 current_paint_
.setAlpha(quad
->opacity() * SkColorGetA(quad
->color
));
307 current_canvas_
->drawRect(gfx::RectFToSkRect(visible_quad_vertex_rect
),
311 void SoftwareRenderer::DrawDebugBorderQuad(const DrawingFrame
* frame
,
312 const DebugBorderDrawQuad
* quad
) {
313 // We need to apply the matrix manually to have pixel-sized stroke width.
315 gfx::RectFToSkRect(QuadVertexRect()).toQuad(vertices
);
316 SkPoint transformed_vertices
[4];
317 current_canvas_
->getTotalMatrix().mapPoints(transformed_vertices
,
320 current_canvas_
->resetMatrix();
322 current_paint_
.setColor(quad
->color
);
323 current_paint_
.setAlpha(quad
->opacity() * SkColorGetA(quad
->color
));
324 current_paint_
.setStyle(SkPaint::kStroke_Style
);
325 current_paint_
.setStrokeWidth(quad
->width
);
326 current_canvas_
->drawPoints(SkCanvas::kPolygon_PointMode
,
327 4, transformed_vertices
, current_paint_
);
330 void SoftwareRenderer::DrawPictureQuad(const DrawingFrame
* frame
,
331 const PictureDrawQuad
* quad
) {
332 SkMatrix content_matrix
;
333 content_matrix
.setRectToRect(
334 gfx::RectFToSkRect(quad
->tex_coord_rect
),
335 gfx::RectFToSkRect(QuadVertexRect()),
336 SkMatrix::kFill_ScaleToFit
);
337 current_canvas_
->concat(content_matrix
);
339 // TODO(aelias): This isn't correct in all cases. We should detect these
340 // cases and fall back to a persistent bitmap backing
341 // (http://crbug.com/280374).
342 skia::RefPtr
<SkDrawFilter
> opacity_filter
=
343 skia::AdoptRef(new skia::OpacityDrawFilter(
344 quad
->opacity(), frame
->disable_picture_quad_image_filtering
));
345 DCHECK(!current_canvas_
->getDrawFilter());
346 current_canvas_
->setDrawFilter(opacity_filter
.get());
349 "SoftwareRenderer::DrawPictureQuad");
350 quad
->picture_pile
->RasterDirect(
351 current_canvas_
, quad
->content_rect
, quad
->contents_scale
, NULL
);
353 current_canvas_
->setDrawFilter(NULL
);
356 void SoftwareRenderer::DrawSolidColorQuad(const DrawingFrame
* frame
,
357 const SolidColorDrawQuad
* quad
) {
358 gfx::RectF visible_quad_vertex_rect
= MathUtil::ScaleRectProportional(
359 QuadVertexRect(), quad
->rect
, quad
->visible_rect
);
360 current_paint_
.setColor(quad
->color
);
361 current_paint_
.setAlpha(quad
->opacity() * SkColorGetA(quad
->color
));
362 current_canvas_
->drawRect(gfx::RectFToSkRect(visible_quad_vertex_rect
),
366 void SoftwareRenderer::DrawTextureQuad(const DrawingFrame
* frame
,
367 const TextureDrawQuad
* quad
) {
368 if (!IsSoftwareResource(quad
->resource_id
)) {
369 DrawUnsupportedQuad(frame
, quad
);
373 // TODO(skaslev): Add support for non-premultiplied alpha.
374 ResourceProvider::ScopedReadLockSoftware
lock(resource_provider_
,
376 const SkBitmap
* bitmap
= lock
.sk_bitmap();
377 gfx::RectF uv_rect
= gfx::ScaleRect(gfx::BoundingRect(quad
->uv_top_left
,
378 quad
->uv_bottom_right
),
381 gfx::RectF visible_uv_rect
=
382 MathUtil::ScaleRectProportional(uv_rect
, quad
->rect
, quad
->visible_rect
);
383 SkRect sk_uv_rect
= gfx::RectFToSkRect(visible_uv_rect
);
384 gfx::RectF visible_quad_vertex_rect
= MathUtil::ScaleRectProportional(
385 QuadVertexRect(), quad
->rect
, quad
->visible_rect
);
386 SkRect quad_rect
= gfx::RectFToSkRect(visible_quad_vertex_rect
);
389 current_canvas_
->scale(1, -1);
391 bool blend_background
= quad
->background_color
!= SK_ColorTRANSPARENT
&&
393 bool needs_layer
= blend_background
&& (current_paint_
.getAlpha() != 0xFF);
395 current_canvas_
->saveLayerAlpha(&quad_rect
, current_paint_
.getAlpha());
396 current_paint_
.setAlpha(0xFF);
398 if (blend_background
) {
399 SkPaint background_paint
;
400 background_paint
.setColor(quad
->background_color
);
401 current_canvas_
->drawRect(quad_rect
, background_paint
);
403 SkShader::TileMode tile_mode
= WrapModeToTileMode(lock
.wrap_mode());
404 if (tile_mode
!= SkShader::kClamp_TileMode
) {
406 matrix
.setRectToRect(sk_uv_rect
, quad_rect
, SkMatrix::kFill_ScaleToFit
);
407 skia::RefPtr
<SkShader
> shader
= skia::AdoptRef(
408 SkShader::CreateBitmapShader(*bitmap
, tile_mode
, tile_mode
));
409 shader
->setLocalMatrix(matrix
);
411 paint
.setStyle(SkPaint::kFill_Style
);
412 paint
.setShader(shader
.get());
413 current_canvas_
->drawRect(quad_rect
, paint
);
415 current_canvas_
->drawBitmapRectToRect(*bitmap
,
422 current_canvas_
->restore();
425 void SoftwareRenderer::DrawTileQuad(const DrawingFrame
* frame
,
426 const TileDrawQuad
* quad
) {
427 DCHECK(!output_surface_
->ForcedDrawToSoftwareDevice());
428 DCHECK(IsSoftwareResource(quad
->resource_id
));
430 ResourceProvider::ScopedReadLockSoftware
lock(resource_provider_
,
432 DCHECK_EQ(GL_CLAMP_TO_EDGE
, lock
.wrap_mode());
434 gfx::RectF visible_tex_coord_rect
= MathUtil::ScaleRectProportional(
435 quad
->tex_coord_rect
, quad
->rect
, quad
->visible_rect
);
436 gfx::RectF visible_quad_vertex_rect
= MathUtil::ScaleRectProportional(
437 QuadVertexRect(), quad
->rect
, quad
->visible_rect
);
439 SkRect uv_rect
= gfx::RectFToSkRect(visible_tex_coord_rect
);
440 current_paint_
.setFilterBitmap(true);
441 current_canvas_
->drawBitmapRectToRect(
444 gfx::RectFToSkRect(visible_quad_vertex_rect
),
448 void SoftwareRenderer::DrawRenderPassQuad(const DrawingFrame
* frame
,
449 const RenderPassDrawQuad
* quad
) {
450 ScopedResource
* content_texture
=
451 render_pass_textures_
.get(quad
->render_pass_id
);
452 if (!content_texture
|| !content_texture
->id())
455 DCHECK(IsSoftwareResource(content_texture
->id()));
456 ResourceProvider::ScopedReadLockSoftware
lock(resource_provider_
,
457 content_texture
->id());
458 SkShader::TileMode content_tile_mode
= WrapModeToTileMode(lock
.wrap_mode());
460 SkRect dest_rect
= gfx::RectFToSkRect(QuadVertexRect());
461 SkRect dest_visible_rect
= gfx::RectFToSkRect(MathUtil::ScaleRectProportional(
462 QuadVertexRect(), quad
->rect
, quad
->visible_rect
));
463 SkRect content_rect
= SkRect::MakeWH(quad
->rect
.width(), quad
->rect
.height());
465 SkMatrix content_mat
;
466 content_mat
.setRectToRect(content_rect
, dest_rect
,
467 SkMatrix::kFill_ScaleToFit
);
469 const SkBitmap
* content
= lock
.sk_bitmap();
471 SkBitmap filter_bitmap
;
472 if (!quad
->filters
.IsEmpty()) {
473 skia::RefPtr
<SkImageFilter
> filter
= RenderSurfaceFilters::BuildImageFilter(
474 quad
->filters
, content_texture
->size());
475 // TODO(ajuma): In addition origin translation, the canvas should also be
476 // scaled to accomodate device pixel ratio and pinch zoom. See
477 // crbug.com/281516 and crbug.com/281518.
478 // TODO(ajuma): Apply the filter in the same pass as the content where
479 // possible (e.g. when there's no origin offset). See crbug.com/308201.
481 bool is_opaque
= false;
482 skia::RefPtr
<SkBaseDevice
> device
=
483 skia::AdoptRef(new SkBitmapDevice(SkBitmap::kARGB_8888_Config
,
484 content_texture
->size().width(),
485 content_texture
->size().height(),
487 SkCanvas
canvas(device
.get());
489 paint
.setImageFilter(filter
.get());
490 canvas
.clear(SK_ColorTRANSPARENT
);
491 canvas
.translate(SkIntToScalar(-quad
->rect
.origin().x()),
492 SkIntToScalar(-quad
->rect
.origin().y()));
493 canvas
.drawSprite(*content
, 0, 0, &paint
);
494 bool will_change_pixels
= false;
495 filter_bitmap
= device
->accessBitmap(will_change_pixels
);
499 skia::RefPtr
<SkShader
> shader
;
500 if (filter_bitmap
.isNull()) {
501 shader
= skia::AdoptRef(SkShader::CreateBitmapShader(
502 *content
, content_tile_mode
, content_tile_mode
));
504 shader
= skia::AdoptRef(SkShader::CreateBitmapShader(
505 filter_bitmap
, content_tile_mode
, content_tile_mode
));
507 shader
->setLocalMatrix(content_mat
);
508 current_paint_
.setShader(shader
.get());
510 if (quad
->mask_resource_id
) {
511 ResourceProvider::ScopedReadLockSoftware
mask_lock(resource_provider_
,
512 quad
->mask_resource_id
);
513 SkShader::TileMode mask_tile_mode
= WrapModeToTileMode(
514 mask_lock
.wrap_mode());
516 const SkBitmap
* mask
= mask_lock
.sk_bitmap();
518 SkRect mask_rect
= SkRect::MakeXYWH(
519 quad
->mask_uv_rect
.x() * mask
->width(),
520 quad
->mask_uv_rect
.y() * mask
->height(),
521 quad
->mask_uv_rect
.width() * mask
->width(),
522 quad
->mask_uv_rect
.height() * mask
->height());
525 mask_mat
.setRectToRect(mask_rect
, dest_rect
, SkMatrix::kFill_ScaleToFit
);
527 skia::RefPtr
<SkShader
> mask_shader
= skia::AdoptRef(
528 SkShader::CreateBitmapShader(*mask
, mask_tile_mode
, mask_tile_mode
));
529 mask_shader
->setLocalMatrix(mask_mat
);
532 mask_paint
.setShader(mask_shader
.get());
534 skia::RefPtr
<SkLayerRasterizer
> mask_rasterizer
=
535 skia::AdoptRef(new SkLayerRasterizer
);
536 mask_rasterizer
->addLayer(mask_paint
);
538 current_paint_
.setRasterizer(mask_rasterizer
.get());
539 current_canvas_
->drawRect(dest_visible_rect
, current_paint_
);
541 // TODO(skaslev): Apply background filters and blend with content
542 current_canvas_
->drawRect(dest_visible_rect
, current_paint_
);
546 void SoftwareRenderer::DrawUnsupportedQuad(const DrawingFrame
* frame
,
547 const DrawQuad
* quad
) {
549 current_paint_
.setColor(SK_ColorWHITE
);
551 current_paint_
.setColor(SK_ColorMAGENTA
);
553 current_paint_
.setAlpha(quad
->opacity() * 255);
554 current_canvas_
->drawRect(gfx::RectFToSkRect(QuadVertexRect()),
558 void SoftwareRenderer::CopyCurrentRenderPassToBitmap(
560 scoped_ptr
<CopyOutputRequest
> request
) {
561 gfx::Rect copy_rect
= frame
->current_render_pass
->output_rect
;
562 if (request
->has_area())
563 copy_rect
.Intersect(request
->area());
564 gfx::Rect window_copy_rect
= MoveFromDrawToWindowSpace(copy_rect
);
566 scoped_ptr
<SkBitmap
> bitmap(new SkBitmap
);
567 bitmap
->setConfig(SkBitmap::kARGB_8888_Config
,
568 window_copy_rect
.width(),
569 window_copy_rect
.height());
570 current_canvas_
->readPixels(
571 bitmap
.get(), window_copy_rect
.x(), window_copy_rect
.y());
573 request
->SendBitmapResult(bitmap
.Pass());
576 void SoftwareRenderer::DiscardBackbuffer() {
577 if (is_backbuffer_discarded_
)
580 output_surface_
->DiscardBackbuffer();
582 is_backbuffer_discarded_
= true;
584 // Damage tracker needs a full reset every time framebuffer is discarded.
585 client_
->SetFullRootLayerDamage();
588 void SoftwareRenderer::EnsureBackbuffer() {
589 if (!is_backbuffer_discarded_
)
592 output_surface_
->EnsureBackbuffer();
593 is_backbuffer_discarded_
= false;
596 void SoftwareRenderer::GetFramebufferPixels(void* pixels
,
597 const gfx::Rect
& rect
) {
598 TRACE_EVENT0("cc", "SoftwareRenderer::GetFramebufferPixels");
599 SkBitmap subset_bitmap
;
600 gfx::Rect
frame_rect(rect
);
601 frame_rect
+= current_viewport_rect_
.OffsetFromOrigin();
602 output_device_
->CopyToBitmap(frame_rect
, &subset_bitmap
);
603 subset_bitmap
.copyPixelsTo(pixels
,
604 4 * frame_rect
.width() * frame_rect
.height(),
605 4 * frame_rect
.width());
608 void SoftwareRenderer::SetVisible(bool visible
) {
609 if (visible_
== visible
)