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/geometry/rect_conversions.h"
31 #include "ui/gfx/skia_util.h"
32 #include "ui/gfx/transform.h"
37 static inline bool IsScalarNearlyInteger(SkScalar scalar
) {
38 return SkScalarNearlyZero(scalar
- SkScalarRoundToScalar(scalar
));
41 bool IsScaleAndIntegerTranslate(const SkMatrix
& matrix
) {
42 return IsScalarNearlyInteger(matrix
[SkMatrix::kMTransX
]) &&
43 IsScalarNearlyInteger(matrix
[SkMatrix::kMTransY
]) &&
44 SkScalarNearlyZero(matrix
[SkMatrix::kMSkewX
]) &&
45 SkScalarNearlyZero(matrix
[SkMatrix::kMSkewY
]) &&
46 SkScalarNearlyZero(matrix
[SkMatrix::kMPersp0
]) &&
47 SkScalarNearlyZero(matrix
[SkMatrix::kMPersp1
]) &&
48 SkScalarNearlyZero(matrix
[SkMatrix::kMPersp2
] - 1.0f
);
51 static SkShader::TileMode
WrapModeToTileMode(GLint wrap_mode
) {
54 return SkShader::kRepeat_TileMode
;
55 case GL_CLAMP_TO_EDGE
:
56 return SkShader::kClamp_TileMode
;
59 return SkShader::kClamp_TileMode
;
62 } // anonymous namespace
64 scoped_ptr
<SoftwareRenderer
> SoftwareRenderer::Create(
65 RendererClient
* client
,
66 const LayerTreeSettings
* settings
,
67 OutputSurface
* output_surface
,
68 ResourceProvider
* resource_provider
) {
69 return make_scoped_ptr(new SoftwareRenderer(
70 client
, settings
, output_surface
, resource_provider
));
73 SoftwareRenderer::SoftwareRenderer(RendererClient
* client
,
74 const LayerTreeSettings
* settings
,
75 OutputSurface
* output_surface
,
76 ResourceProvider
* resource_provider
)
77 : DirectRenderer(client
, settings
, output_surface
, resource_provider
),
78 is_scissor_enabled_(false),
79 is_backbuffer_discarded_(false),
80 output_device_(output_surface
->software_device()),
81 current_canvas_(NULL
) {
82 if (resource_provider_
) {
83 capabilities_
.max_texture_size
= resource_provider_
->max_texture_size();
84 capabilities_
.best_texture_format
=
85 resource_provider_
->best_texture_format();
87 // The updater can access bitmaps while the SoftwareRenderer is using them.
88 capabilities_
.allow_partial_texture_updates
= true;
89 capabilities_
.using_partial_swap
= true;
91 capabilities_
.using_shared_memory_resources
= true;
93 capabilities_
.allow_rasterize_on_demand
= true;
96 SoftwareRenderer::~SoftwareRenderer() {}
98 const RendererCapabilitiesImpl
& SoftwareRenderer::Capabilities() const {
102 void SoftwareRenderer::BeginDrawingFrame(DrawingFrame
* frame
) {
103 TRACE_EVENT0("cc", "SoftwareRenderer::BeginDrawingFrame");
104 root_canvas_
= output_device_
->BeginPaint(
105 gfx::ToEnclosingRect(frame
->root_damage_rect
));
108 void SoftwareRenderer::FinishDrawingFrame(DrawingFrame
* frame
) {
109 TRACE_EVENT0("cc", "SoftwareRenderer::FinishDrawingFrame");
110 current_framebuffer_lock_
= nullptr;
111 current_canvas_
= NULL
;
114 current_frame_data_
.reset(new SoftwareFrameData
);
115 output_device_
->EndPaint(current_frame_data_
.get());
118 void SoftwareRenderer::SwapBuffers(const CompositorFrameMetadata
& metadata
) {
119 TRACE_EVENT0("cc,benchmark", "SoftwareRenderer::SwapBuffers");
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 SkISize size
= current_canvas_
->getDeviceSize();
146 SetClipRect(gfx::Rect(size
.width(), size
.height()));
149 void SoftwareRenderer::Finish() {}
151 void SoftwareRenderer::BindFramebufferToOutputSurface(DrawingFrame
* frame
) {
152 DCHECK(!output_surface_
->HasExternalStencilTest());
153 current_framebuffer_lock_
= nullptr;
154 current_canvas_
= root_canvas_
;
157 bool SoftwareRenderer::BindFramebufferToTexture(
159 const ScopedResource
* texture
,
160 const gfx::Rect
& target_rect
) {
161 current_framebuffer_lock_
= make_scoped_ptr(
162 new ResourceProvider::ScopedWriteLockSoftware(
163 resource_provider_
, texture
->id()));
164 current_canvas_
= current_framebuffer_lock_
->sk_canvas();
165 InitializeViewport(frame
,
167 gfx::Rect(target_rect
.size()),
172 void SoftwareRenderer::SetScissorTestRect(const gfx::Rect
& scissor_rect
) {
173 is_scissor_enabled_
= true;
174 scissor_rect_
= scissor_rect
;
175 SetClipRect(scissor_rect
);
178 void SoftwareRenderer::SetClipRect(const gfx::Rect
& rect
) {
179 // Skia applies the current matrix to clip rects so we reset it temporary.
180 SkMatrix current_matrix
= current_canvas_
->getTotalMatrix();
181 current_canvas_
->resetMatrix();
182 current_canvas_
->clipRect(gfx::RectToSkRect(rect
), SkRegion::kReplace_Op
);
183 current_canvas_
->setMatrix(current_matrix
);
186 void SoftwareRenderer::ClearCanvas(SkColor color
) {
187 // SkCanvas::clear doesn't respect the current clipping region
188 // so we SkCanvas::drawColor instead if scissoring is active.
189 if (is_scissor_enabled_
)
190 current_canvas_
->drawColor(color
, SkXfermode::kSrc_Mode
);
192 current_canvas_
->clear(color
);
195 void SoftwareRenderer::DiscardPixels(bool has_external_stencil_test
,
196 bool draw_rect_covers_full_surface
) {}
198 void SoftwareRenderer::ClearFramebuffer(DrawingFrame
* frame
,
199 bool has_external_stencil_test
) {
200 if (frame
->current_render_pass
->has_transparent_background
) {
201 ClearCanvas(SkColorSetARGB(0, 0, 0, 0));
204 // On DEBUG builds, opaque render passes are cleared to blue
205 // to easily see regions that were not drawn on the screen.
206 ClearCanvas(SkColorSetARGB(255, 0, 0, 255));
211 void SoftwareRenderer::SetDrawViewport(
212 const gfx::Rect
& window_space_viewport
) {}
214 bool SoftwareRenderer::IsSoftwareResource(
215 ResourceProvider::ResourceId resource_id
) const {
216 switch (resource_provider_
->GetResourceType(resource_id
)) {
217 case ResourceProvider::GLTexture
:
219 case ResourceProvider::Bitmap
:
221 case ResourceProvider::InvalidType
:
225 LOG(FATAL
) << "Invalid resource type.";
229 void SoftwareRenderer::DoDrawQuad(DrawingFrame
* frame
, const DrawQuad
* quad
) {
230 TRACE_EVENT0("cc", "SoftwareRenderer::DoDrawQuad");
231 gfx::Transform quad_rect_matrix
;
232 QuadRectTransform(&quad_rect_matrix
, quad
->quadTransform(), quad
->rect
);
233 gfx::Transform contents_device_transform
=
234 frame
->window_matrix
* frame
->projection_matrix
* quad_rect_matrix
;
235 contents_device_transform
.FlattenTo2d();
236 SkMatrix sk_device_matrix
;
237 gfx::TransformToFlattenedSkMatrix(contents_device_transform
,
239 current_canvas_
->setMatrix(sk_device_matrix
);
241 current_paint_
.reset();
242 if (!IsScaleAndIntegerTranslate(sk_device_matrix
)) {
243 // TODO(danakj): Until we can enable AA only on exterior edges of the
244 // layer, disable AA if any interior edges are present. crbug.com/248175
245 bool all_four_edges_are_exterior
= quad
->IsTopEdge() &&
246 quad
->IsLeftEdge() &&
247 quad
->IsBottomEdge() &&
249 if (settings_
->allow_antialiasing
&& all_four_edges_are_exterior
)
250 current_paint_
.setAntiAlias(true);
251 current_paint_
.setFilterLevel(SkPaint::kLow_FilterLevel
);
254 if (quad
->ShouldDrawWithBlending() ||
255 quad
->shared_quad_state
->blend_mode
!= SkXfermode::kSrcOver_Mode
) {
256 current_paint_
.setAlpha(quad
->opacity() * 255);
257 current_paint_
.setXfermodeMode(quad
->shared_quad_state
->blend_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");
351 quad
->picture_pile
->RasterDirect(
352 current_canvas_
, quad
->content_rect
, quad
->contents_scale
, NULL
);
354 current_canvas_
->setDrawFilter(NULL
);
357 void SoftwareRenderer::DrawSolidColorQuad(const DrawingFrame
* frame
,
358 const SolidColorDrawQuad
* quad
) {
359 gfx::RectF visible_quad_vertex_rect
= MathUtil::ScaleRectProportional(
360 QuadVertexRect(), quad
->rect
, quad
->visible_rect
);
361 current_paint_
.setColor(quad
->color
);
362 current_paint_
.setAlpha(quad
->opacity() * SkColorGetA(quad
->color
));
363 current_canvas_
->drawRect(gfx::RectFToSkRect(visible_quad_vertex_rect
),
367 void SoftwareRenderer::DrawTextureQuad(const DrawingFrame
* frame
,
368 const TextureDrawQuad
* quad
) {
369 if (!IsSoftwareResource(quad
->resource_id
)) {
370 DrawUnsupportedQuad(frame
, quad
);
374 // TODO(skaslev): Add support for non-premultiplied alpha.
375 ResourceProvider::ScopedReadLockSoftware
lock(resource_provider_
,
379 const SkBitmap
* bitmap
= lock
.sk_bitmap();
380 gfx::RectF uv_rect
= gfx::ScaleRect(gfx::BoundingRect(quad
->uv_top_left
,
381 quad
->uv_bottom_right
),
384 gfx::RectF visible_uv_rect
=
385 MathUtil::ScaleRectProportional(uv_rect
, quad
->rect
, quad
->visible_rect
);
386 SkRect sk_uv_rect
= gfx::RectFToSkRect(visible_uv_rect
);
387 gfx::RectF visible_quad_vertex_rect
= MathUtil::ScaleRectProportional(
388 QuadVertexRect(), quad
->rect
, quad
->visible_rect
);
389 SkRect quad_rect
= gfx::RectFToSkRect(visible_quad_vertex_rect
);
392 current_canvas_
->scale(1, -1);
394 bool blend_background
= quad
->background_color
!= SK_ColorTRANSPARENT
&&
396 bool needs_layer
= blend_background
&& (current_paint_
.getAlpha() != 0xFF);
398 current_canvas_
->saveLayerAlpha(&quad_rect
, current_paint_
.getAlpha());
399 current_paint_
.setAlpha(0xFF);
401 if (blend_background
) {
402 SkPaint background_paint
;
403 background_paint
.setColor(quad
->background_color
);
404 current_canvas_
->drawRect(quad_rect
, background_paint
);
406 SkShader::TileMode tile_mode
= WrapModeToTileMode(lock
.wrap_mode());
407 if (tile_mode
!= SkShader::kClamp_TileMode
) {
409 matrix
.setRectToRect(sk_uv_rect
, quad_rect
, SkMatrix::kFill_ScaleToFit
);
410 skia::RefPtr
<SkShader
> shader
= skia::AdoptRef(
411 SkShader::CreateBitmapShader(*bitmap
, tile_mode
, tile_mode
, &matrix
));
413 paint
.setStyle(SkPaint::kFill_Style
);
414 paint
.setShader(shader
.get());
415 current_canvas_
->drawRect(quad_rect
, paint
);
417 current_canvas_
->drawBitmapRectToRect(*bitmap
,
424 current_canvas_
->restore();
427 void SoftwareRenderer::DrawTileQuad(const DrawingFrame
* frame
,
428 const TileDrawQuad
* quad
) {
429 // |resource_provider_| can be NULL in resourceless software draws, which
430 // should never produce tile quads in the first place.
431 DCHECK(resource_provider_
);
432 DCHECK(IsSoftwareResource(quad
->resource_id
));
434 ResourceProvider::ScopedReadLockSoftware
lock(resource_provider_
,
438 DCHECK_EQ(GL_CLAMP_TO_EDGE
, lock
.wrap_mode());
440 gfx::RectF visible_tex_coord_rect
= MathUtil::ScaleRectProportional(
441 quad
->tex_coord_rect
, quad
->rect
, quad
->visible_rect
);
442 gfx::RectF visible_quad_vertex_rect
= MathUtil::ScaleRectProportional(
443 QuadVertexRect(), quad
->rect
, quad
->visible_rect
);
445 SkRect uv_rect
= gfx::RectFToSkRect(visible_tex_coord_rect
);
446 current_paint_
.setFilterLevel(SkPaint::kLow_FilterLevel
);
447 current_canvas_
->drawBitmapRectToRect(
450 gfx::RectFToSkRect(visible_quad_vertex_rect
),
454 void SoftwareRenderer::DrawRenderPassQuad(const DrawingFrame
* frame
,
455 const RenderPassDrawQuad
* quad
) {
456 ScopedResource
* content_texture
=
457 render_pass_textures_
.get(quad
->render_pass_id
);
458 if (!content_texture
|| !content_texture
->id())
461 DCHECK(IsSoftwareResource(content_texture
->id()));
462 ResourceProvider::ScopedReadLockSoftware
lock(resource_provider_
,
463 content_texture
->id());
466 SkShader::TileMode content_tile_mode
= WrapModeToTileMode(lock
.wrap_mode());
468 SkRect dest_rect
= gfx::RectFToSkRect(QuadVertexRect());
469 SkRect dest_visible_rect
= gfx::RectFToSkRect(MathUtil::ScaleRectProportional(
470 QuadVertexRect(), quad
->rect
, quad
->visible_rect
));
471 SkRect content_rect
= SkRect::MakeWH(quad
->rect
.width(), quad
->rect
.height());
473 SkMatrix content_mat
;
474 content_mat
.setRectToRect(content_rect
, dest_rect
,
475 SkMatrix::kFill_ScaleToFit
);
477 const SkBitmap
* content
= lock
.sk_bitmap();
479 SkBitmap filter_bitmap
;
480 if (!quad
->filters
.IsEmpty()) {
481 skia::RefPtr
<SkImageFilter
> filter
= RenderSurfaceFilters::BuildImageFilter(
482 quad
->filters
, content_texture
->size());
483 // TODO(ajuma): Apply the filter in the same pass as the content where
484 // possible (e.g. when there's no origin offset). See crbug.com/308201.
486 SkImageInfo info
= SkImageInfo::MakeN32Premul(
487 content_texture
->size().width(), content_texture
->size().height());
488 if (filter_bitmap
.tryAllocPixels(info
)) {
489 SkCanvas
canvas(filter_bitmap
);
491 paint
.setImageFilter(filter
.get());
492 canvas
.clear(SK_ColorTRANSPARENT
);
493 canvas
.translate(SkIntToScalar(-quad
->rect
.origin().x()),
494 SkIntToScalar(-quad
->rect
.origin().y()));
495 canvas
.scale(quad
->filters_scale
.x(), quad
->filters_scale
.y());
496 canvas
.drawSprite(*content
, 0, 0, &paint
);
501 skia::RefPtr
<SkShader
> shader
;
502 if (filter_bitmap
.isNull()) {
503 shader
= skia::AdoptRef(SkShader::CreateBitmapShader(
504 *content
, content_tile_mode
, content_tile_mode
, &content_mat
));
506 shader
= skia::AdoptRef(SkShader::CreateBitmapShader(
507 filter_bitmap
, content_tile_mode
, content_tile_mode
, &content_mat
));
509 current_paint_
.setShader(shader
.get());
511 if (quad
->mask_resource_id
) {
512 ResourceProvider::ScopedReadLockSoftware
mask_lock(resource_provider_
,
513 quad
->mask_resource_id
);
516 SkShader::TileMode mask_tile_mode
= WrapModeToTileMode(
517 mask_lock
.wrap_mode());
519 const SkBitmap
* mask
= mask_lock
.sk_bitmap();
521 SkRect mask_rect
= SkRect::MakeXYWH(
522 quad
->mask_uv_rect
.x() * mask
->width(),
523 quad
->mask_uv_rect
.y() * mask
->height(),
524 quad
->mask_uv_rect
.width() * mask
->width(),
525 quad
->mask_uv_rect
.height() * mask
->height());
528 mask_mat
.setRectToRect(mask_rect
, dest_rect
, SkMatrix::kFill_ScaleToFit
);
530 skia::RefPtr
<SkShader
> mask_shader
=
531 skia::AdoptRef(SkShader::CreateBitmapShader(
532 *mask
, mask_tile_mode
, mask_tile_mode
, &mask_mat
));
535 mask_paint
.setShader(mask_shader
.get());
537 SkLayerRasterizer::Builder builder
;
538 builder
.addLayer(mask_paint
);
540 skia::RefPtr
<SkLayerRasterizer
> mask_rasterizer
=
541 skia::AdoptRef(builder
.detachRasterizer());
543 current_paint_
.setRasterizer(mask_rasterizer
.get());
544 current_canvas_
->drawRect(dest_visible_rect
, current_paint_
);
546 // TODO(skaslev): Apply background filters
547 current_canvas_
->drawRect(dest_visible_rect
, current_paint_
);
551 void SoftwareRenderer::DrawUnsupportedQuad(const DrawingFrame
* frame
,
552 const DrawQuad
* quad
) {
554 current_paint_
.setColor(SK_ColorWHITE
);
556 current_paint_
.setColor(SK_ColorMAGENTA
);
558 current_paint_
.setAlpha(quad
->opacity() * 255);
559 current_canvas_
->drawRect(gfx::RectFToSkRect(QuadVertexRect()),
563 void SoftwareRenderer::CopyCurrentRenderPassToBitmap(
565 scoped_ptr
<CopyOutputRequest
> request
) {
566 gfx::Rect copy_rect
= frame
->current_render_pass
->output_rect
;
567 if (request
->has_area())
568 copy_rect
.Intersect(request
->area());
569 gfx::Rect window_copy_rect
= MoveFromDrawToWindowSpace(copy_rect
);
571 scoped_ptr
<SkBitmap
> bitmap(new SkBitmap
);
572 bitmap
->setInfo(SkImageInfo::MakeN32Premul(window_copy_rect
.width(),
573 window_copy_rect
.height()));
574 current_canvas_
->readPixels(
575 bitmap
.get(), window_copy_rect
.x(), window_copy_rect
.y());
577 request
->SendBitmapResult(bitmap
.Pass());
580 void SoftwareRenderer::DiscardBackbuffer() {
581 if (is_backbuffer_discarded_
)
584 output_surface_
->DiscardBackbuffer();
586 is_backbuffer_discarded_
= true;
588 // Damage tracker needs a full reset every time framebuffer is discarded.
589 client_
->SetFullRootLayerDamage();
592 void SoftwareRenderer::EnsureBackbuffer() {
593 if (!is_backbuffer_discarded_
)
596 output_surface_
->EnsureBackbuffer();
597 is_backbuffer_discarded_
= false;
600 void SoftwareRenderer::DidChangeVisibility() {