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/trace_event/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 RendererSettings
* 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 RendererSettings
* 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_framebuffer_canvas_
.clear();
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 TRACE_EVENT0("cc,benchmark", "SoftwareRenderer::SwapBuffers");
121 CompositorFrame compositor_frame
;
122 compositor_frame
.metadata
= metadata
;
123 compositor_frame
.software_frame_data
= current_frame_data_
.Pass();
124 output_surface_
->SwapBuffers(&compositor_frame
);
127 void SoftwareRenderer::ReceiveSwapBuffersAck(const CompositorFrameAck
& ack
) {
128 output_device_
->ReclaimSoftwareFrame(ack
.last_software_frame_id
);
131 bool SoftwareRenderer::FlippedFramebuffer(const DrawingFrame
* frame
) const {
135 void SoftwareRenderer::EnsureScissorTestEnabled() {
136 is_scissor_enabled_
= true;
137 SetClipRect(scissor_rect_
);
140 void SoftwareRenderer::EnsureScissorTestDisabled() {
141 // There is no explicit notion of enabling/disabling scissoring in software
142 // rendering, but the underlying effect we want is to clear any existing
143 // clipRect on the current SkCanvas. This is done by setting clipRect to
144 // the viewport's dimensions.
145 is_scissor_enabled_
= false;
146 SkISize size
= current_canvas_
->getDeviceSize();
147 SetClipRect(gfx::Rect(size
.width(), size
.height()));
150 void SoftwareRenderer::Finish() {}
152 void SoftwareRenderer::BindFramebufferToOutputSurface(DrawingFrame
* frame
) {
153 DCHECK(!output_surface_
->HasExternalStencilTest());
154 current_framebuffer_lock_
= nullptr;
155 current_framebuffer_canvas_
.clear();
156 current_canvas_
= root_canvas_
;
159 bool SoftwareRenderer::BindFramebufferToTexture(
161 const ScopedResource
* texture
,
162 const gfx::Rect
& target_rect
) {
163 DCHECK(texture
->id());
165 // Explicitly release lock, otherwise we can crash when try to lock
166 // same texture again.
167 current_framebuffer_lock_
= nullptr;
168 current_framebuffer_lock_
= make_scoped_ptr(
169 new ResourceProvider::ScopedWriteLockSoftware(
170 resource_provider_
, texture
->id()));
171 current_framebuffer_canvas_
=
172 skia::AdoptRef(new SkCanvas(current_framebuffer_lock_
->sk_bitmap()));
173 current_canvas_
= current_framebuffer_canvas_
.get();
174 InitializeViewport(frame
,
176 gfx::Rect(target_rect
.size()),
181 void SoftwareRenderer::SetScissorTestRect(const gfx::Rect
& scissor_rect
) {
182 is_scissor_enabled_
= true;
183 scissor_rect_
= scissor_rect
;
184 SetClipRect(scissor_rect
);
187 void SoftwareRenderer::SetClipRect(const gfx::Rect
& rect
) {
188 // Skia applies the current matrix to clip rects so we reset it temporary.
189 SkMatrix current_matrix
= current_canvas_
->getTotalMatrix();
190 current_canvas_
->resetMatrix();
191 current_canvas_
->clipRect(gfx::RectToSkRect(rect
), SkRegion::kReplace_Op
);
192 current_canvas_
->setMatrix(current_matrix
);
195 void SoftwareRenderer::ClearCanvas(SkColor color
) {
196 // SkCanvas::clear doesn't respect the current clipping region
197 // so we SkCanvas::drawColor instead if scissoring is active.
198 if (is_scissor_enabled_
)
199 current_canvas_
->drawColor(color
, SkXfermode::kSrc_Mode
);
201 current_canvas_
->clear(color
);
204 void SoftwareRenderer::DiscardPixels(bool has_external_stencil_test
,
205 bool draw_rect_covers_full_surface
) {}
207 void SoftwareRenderer::ClearFramebuffer(DrawingFrame
* frame
,
208 bool has_external_stencil_test
) {
209 if (frame
->current_render_pass
->has_transparent_background
) {
210 ClearCanvas(SkColorSetARGB(0, 0, 0, 0));
213 // On DEBUG builds, opaque render passes are cleared to blue
214 // to easily see regions that were not drawn on the screen.
215 ClearCanvas(SkColorSetARGB(255, 0, 0, 255));
220 void SoftwareRenderer::SetDrawViewport(
221 const gfx::Rect
& window_space_viewport
) {}
223 bool SoftwareRenderer::IsSoftwareResource(
224 ResourceProvider::ResourceId resource_id
) const {
225 switch (resource_provider_
->GetResourceType(resource_id
)) {
226 case ResourceProvider::GLTexture
:
228 case ResourceProvider::Bitmap
:
230 case ResourceProvider::InvalidType
:
234 LOG(FATAL
) << "Invalid resource type.";
238 void SoftwareRenderer::DoDrawQuad(DrawingFrame
* frame
, const DrawQuad
* quad
) {
239 TRACE_EVENT0("cc", "SoftwareRenderer::DoDrawQuad");
240 gfx::Transform quad_rect_matrix
;
241 QuadRectTransform(&quad_rect_matrix
, quad
->quadTransform(), quad
->rect
);
242 gfx::Transform contents_device_transform
=
243 frame
->window_matrix
* frame
->projection_matrix
* quad_rect_matrix
;
244 contents_device_transform
.FlattenTo2d();
245 SkMatrix sk_device_matrix
;
246 gfx::TransformToFlattenedSkMatrix(contents_device_transform
,
248 current_canvas_
->setMatrix(sk_device_matrix
);
250 current_paint_
.reset();
251 if (settings_
->force_antialiasing
||
252 !IsScaleAndIntegerTranslate(sk_device_matrix
)) {
253 // TODO(danakj): Until we can enable AA only on exterior edges of the
254 // layer, disable AA if any interior edges are present. crbug.com/248175
255 bool all_four_edges_are_exterior
= quad
->IsTopEdge() &&
256 quad
->IsLeftEdge() &&
257 quad
->IsBottomEdge() &&
259 if (settings_
->allow_antialiasing
&&
260 (settings_
->force_antialiasing
|| all_four_edges_are_exterior
))
261 current_paint_
.setAntiAlias(true);
262 current_paint_
.setFilterLevel(SkPaint::kLow_FilterLevel
);
265 if (quad
->ShouldDrawWithBlending() ||
266 quad
->shared_quad_state
->blend_mode
!= SkXfermode::kSrcOver_Mode
) {
267 current_paint_
.setAlpha(quad
->opacity() * 255);
268 current_paint_
.setXfermodeMode(quad
->shared_quad_state
->blend_mode
);
270 current_paint_
.setXfermodeMode(SkXfermode::kSrc_Mode
);
273 switch (quad
->material
) {
274 case DrawQuad::CHECKERBOARD
:
275 DrawCheckerboardQuad(frame
, CheckerboardDrawQuad::MaterialCast(quad
));
277 case DrawQuad::DEBUG_BORDER
:
278 DrawDebugBorderQuad(frame
, DebugBorderDrawQuad::MaterialCast(quad
));
280 case DrawQuad::PICTURE_CONTENT
:
281 DrawPictureQuad(frame
, PictureDrawQuad::MaterialCast(quad
));
283 case DrawQuad::RENDER_PASS
:
284 DrawRenderPassQuad(frame
, RenderPassDrawQuad::MaterialCast(quad
));
286 case DrawQuad::SOLID_COLOR
:
287 DrawSolidColorQuad(frame
, SolidColorDrawQuad::MaterialCast(quad
));
289 case DrawQuad::TEXTURE_CONTENT
:
290 DrawTextureQuad(frame
, TextureDrawQuad::MaterialCast(quad
));
292 case DrawQuad::TILED_CONTENT
:
293 DrawTileQuad(frame
, TileDrawQuad::MaterialCast(quad
));
295 case DrawQuad::SURFACE_CONTENT
:
296 // Surface content should be fully resolved to other quad types before
297 // reaching a direct renderer.
300 case DrawQuad::INVALID
:
301 case DrawQuad::IO_SURFACE_CONTENT
:
302 case DrawQuad::YUV_VIDEO_CONTENT
:
303 case DrawQuad::STREAM_VIDEO_CONTENT
:
304 DrawUnsupportedQuad(frame
, quad
);
309 current_canvas_
->resetMatrix();
312 void SoftwareRenderer::DrawCheckerboardQuad(const DrawingFrame
* frame
,
313 const CheckerboardDrawQuad
* quad
) {
314 gfx::RectF visible_quad_vertex_rect
= MathUtil::ScaleRectProportional(
315 QuadVertexRect(), quad
->rect
, quad
->visible_rect
);
316 current_paint_
.setColor(quad
->color
);
317 current_paint_
.setAlpha(quad
->opacity() * SkColorGetA(quad
->color
));
318 current_canvas_
->drawRect(gfx::RectFToSkRect(visible_quad_vertex_rect
),
322 void SoftwareRenderer::DrawDebugBorderQuad(const DrawingFrame
* frame
,
323 const DebugBorderDrawQuad
* quad
) {
324 // We need to apply the matrix manually to have pixel-sized stroke width.
326 gfx::RectFToSkRect(QuadVertexRect()).toQuad(vertices
);
327 SkPoint transformed_vertices
[4];
328 current_canvas_
->getTotalMatrix().mapPoints(transformed_vertices
,
331 current_canvas_
->resetMatrix();
333 current_paint_
.setColor(quad
->color
);
334 current_paint_
.setAlpha(quad
->opacity() * SkColorGetA(quad
->color
));
335 current_paint_
.setStyle(SkPaint::kStroke_Style
);
336 current_paint_
.setStrokeWidth(quad
->width
);
337 current_canvas_
->drawPoints(SkCanvas::kPolygon_PointMode
,
338 4, transformed_vertices
, current_paint_
);
341 void SoftwareRenderer::DrawPictureQuad(const DrawingFrame
* frame
,
342 const PictureDrawQuad
* quad
) {
343 SkMatrix content_matrix
;
344 content_matrix
.setRectToRect(
345 gfx::RectFToSkRect(quad
->tex_coord_rect
),
346 gfx::RectFToSkRect(QuadVertexRect()),
347 SkMatrix::kFill_ScaleToFit
);
348 current_canvas_
->concat(content_matrix
);
350 // TODO(aelias): This isn't correct in all cases. We should detect these
351 // cases and fall back to a persistent bitmap backing
352 // (http://crbug.com/280374).
353 skia::RefPtr
<SkDrawFilter
> opacity_filter
=
354 skia::AdoptRef(new skia::OpacityDrawFilter(
355 quad
->opacity(), frame
->disable_picture_quad_image_filtering
||
356 quad
->nearest_neighbor
));
357 DCHECK(!current_canvas_
->getDrawFilter());
358 current_canvas_
->setDrawFilter(opacity_filter
.get());
361 "SoftwareRenderer::DrawPictureQuad");
363 quad
->raster_source
->PlaybackToSharedCanvas(
364 current_canvas_
, quad
->content_rect
, quad
->contents_scale
);
366 current_canvas_
->setDrawFilter(NULL
);
369 void SoftwareRenderer::DrawSolidColorQuad(const DrawingFrame
* frame
,
370 const SolidColorDrawQuad
* quad
) {
371 gfx::RectF visible_quad_vertex_rect
= MathUtil::ScaleRectProportional(
372 QuadVertexRect(), quad
->rect
, quad
->visible_rect
);
373 current_paint_
.setColor(quad
->color
);
374 current_paint_
.setAlpha(quad
->opacity() * SkColorGetA(quad
->color
));
375 current_canvas_
->drawRect(gfx::RectFToSkRect(visible_quad_vertex_rect
),
379 void SoftwareRenderer::DrawTextureQuad(const DrawingFrame
* frame
,
380 const TextureDrawQuad
* quad
) {
381 if (!IsSoftwareResource(quad
->resource_id
)) {
382 DrawUnsupportedQuad(frame
, quad
);
386 // TODO(skaslev): Add support for non-premultiplied alpha.
387 ResourceProvider::ScopedReadLockSoftware
lock(resource_provider_
,
391 const SkBitmap
* bitmap
= lock
.sk_bitmap();
392 gfx::RectF uv_rect
= gfx::ScaleRect(gfx::BoundingRect(quad
->uv_top_left
,
393 quad
->uv_bottom_right
),
396 gfx::RectF visible_uv_rect
=
397 MathUtil::ScaleRectProportional(uv_rect
, quad
->rect
, quad
->visible_rect
);
398 SkRect sk_uv_rect
= gfx::RectFToSkRect(visible_uv_rect
);
399 gfx::RectF visible_quad_vertex_rect
= MathUtil::ScaleRectProportional(
400 QuadVertexRect(), quad
->rect
, quad
->visible_rect
);
401 SkRect quad_rect
= gfx::RectFToSkRect(visible_quad_vertex_rect
);
404 current_canvas_
->scale(1, -1);
406 bool blend_background
= quad
->background_color
!= SK_ColorTRANSPARENT
&&
408 bool needs_layer
= blend_background
&& (current_paint_
.getAlpha() != 0xFF);
410 current_canvas_
->saveLayerAlpha(&quad_rect
, current_paint_
.getAlpha());
411 current_paint_
.setAlpha(0xFF);
413 if (blend_background
) {
414 SkPaint background_paint
;
415 background_paint
.setColor(quad
->background_color
);
416 current_canvas_
->drawRect(quad_rect
, background_paint
);
418 SkShader::TileMode tile_mode
= WrapModeToTileMode(lock
.wrap_mode());
419 if (tile_mode
!= SkShader::kClamp_TileMode
) {
421 matrix
.setRectToRect(sk_uv_rect
, quad_rect
, SkMatrix::kFill_ScaleToFit
);
422 skia::RefPtr
<SkShader
> shader
= skia::AdoptRef(
423 SkShader::CreateBitmapShader(*bitmap
, tile_mode
, tile_mode
, &matrix
));
425 paint
.setStyle(SkPaint::kFill_Style
);
426 paint
.setShader(shader
.get());
427 current_canvas_
->drawRect(quad_rect
, paint
);
429 current_canvas_
->drawBitmapRectToRect(*bitmap
,
436 current_canvas_
->restore();
439 void SoftwareRenderer::DrawTileQuad(const DrawingFrame
* frame
,
440 const TileDrawQuad
* quad
) {
441 // |resource_provider_| can be NULL in resourceless software draws, which
442 // should never produce tile quads in the first place.
443 DCHECK(resource_provider_
);
444 DCHECK(IsSoftwareResource(quad
->resource_id
));
446 ResourceProvider::ScopedReadLockSoftware
lock(resource_provider_
,
450 DCHECK_EQ(GL_CLAMP_TO_EDGE
, lock
.wrap_mode());
452 gfx::RectF visible_tex_coord_rect
= MathUtil::ScaleRectProportional(
453 quad
->tex_coord_rect
, quad
->rect
, quad
->visible_rect
);
454 gfx::RectF visible_quad_vertex_rect
= MathUtil::ScaleRectProportional(
455 QuadVertexRect(), quad
->rect
, quad
->visible_rect
);
457 SkRect uv_rect
= gfx::RectFToSkRect(visible_tex_coord_rect
);
458 current_paint_
.setFilterLevel(quad
->nearest_neighbor
459 ? SkPaint::kNone_FilterLevel
460 : SkPaint::kLow_FilterLevel
);
461 current_canvas_
->drawBitmapRectToRect(
464 gfx::RectFToSkRect(visible_quad_vertex_rect
),
468 void SoftwareRenderer::DrawRenderPassQuad(const DrawingFrame
* frame
,
469 const RenderPassDrawQuad
* quad
) {
470 ScopedResource
* content_texture
=
471 render_pass_textures_
.get(quad
->render_pass_id
);
472 if (!content_texture
|| !content_texture
->id())
475 DCHECK(IsSoftwareResource(content_texture
->id()));
476 ResourceProvider::ScopedReadLockSoftware
lock(resource_provider_
,
477 content_texture
->id());
480 SkShader::TileMode content_tile_mode
= WrapModeToTileMode(lock
.wrap_mode());
482 SkRect dest_rect
= gfx::RectFToSkRect(QuadVertexRect());
483 SkRect dest_visible_rect
= gfx::RectFToSkRect(MathUtil::ScaleRectProportional(
484 QuadVertexRect(), quad
->rect
, quad
->visible_rect
));
485 SkRect content_rect
= SkRect::MakeWH(quad
->rect
.width(), quad
->rect
.height());
487 SkMatrix content_mat
;
488 content_mat
.setRectToRect(content_rect
, dest_rect
,
489 SkMatrix::kFill_ScaleToFit
);
491 const SkBitmap
* content
= lock
.sk_bitmap();
493 SkBitmap filter_bitmap
;
494 if (!quad
->filters
.IsEmpty()) {
495 skia::RefPtr
<SkImageFilter
> filter
= RenderSurfaceFilters::BuildImageFilter(
496 quad
->filters
, content_texture
->size());
497 // TODO(ajuma): Apply the filter in the same pass as the content where
498 // possible (e.g. when there's no origin offset). See crbug.com/308201.
500 SkImageInfo info
= SkImageInfo::MakeN32Premul(
501 content_texture
->size().width(), content_texture
->size().height());
502 if (filter_bitmap
.tryAllocPixels(info
)) {
503 SkCanvas
canvas(filter_bitmap
);
505 paint
.setImageFilter(filter
.get());
506 canvas
.clear(SK_ColorTRANSPARENT
);
507 canvas
.translate(SkIntToScalar(-quad
->rect
.origin().x()),
508 SkIntToScalar(-quad
->rect
.origin().y()));
509 canvas
.scale(quad
->filters_scale
.x(), quad
->filters_scale
.y());
510 canvas
.drawSprite(*content
, 0, 0, &paint
);
515 skia::RefPtr
<SkShader
> shader
;
516 if (filter_bitmap
.isNull()) {
517 shader
= skia::AdoptRef(SkShader::CreateBitmapShader(
518 *content
, content_tile_mode
, content_tile_mode
, &content_mat
));
520 shader
= skia::AdoptRef(SkShader::CreateBitmapShader(
521 filter_bitmap
, content_tile_mode
, content_tile_mode
, &content_mat
));
523 current_paint_
.setShader(shader
.get());
525 if (quad
->mask_resource_id
) {
526 ResourceProvider::ScopedReadLockSoftware
mask_lock(resource_provider_
,
527 quad
->mask_resource_id
);
530 SkShader::TileMode mask_tile_mode
= WrapModeToTileMode(
531 mask_lock
.wrap_mode());
533 const SkBitmap
* mask
= mask_lock
.sk_bitmap();
535 // Scale normalized uv rect into absolute texel coordinates.
537 gfx::RectFToSkRect(gfx::ScaleRect(quad
->MaskUVRect(),
538 quad
->mask_texture_size
.width(),
539 quad
->mask_texture_size
.height()));
542 mask_mat
.setRectToRect(mask_rect
, dest_rect
, SkMatrix::kFill_ScaleToFit
);
544 skia::RefPtr
<SkShader
> mask_shader
=
545 skia::AdoptRef(SkShader::CreateBitmapShader(
546 *mask
, mask_tile_mode
, mask_tile_mode
, &mask_mat
));
549 mask_paint
.setShader(mask_shader
.get());
551 SkLayerRasterizer::Builder builder
;
552 builder
.addLayer(mask_paint
);
554 skia::RefPtr
<SkLayerRasterizer
> mask_rasterizer
=
555 skia::AdoptRef(builder
.detachRasterizer());
557 current_paint_
.setRasterizer(mask_rasterizer
.get());
558 current_canvas_
->drawRect(dest_visible_rect
, current_paint_
);
560 // TODO(skaslev): Apply background filters
561 current_canvas_
->drawRect(dest_visible_rect
, current_paint_
);
565 void SoftwareRenderer::DrawUnsupportedQuad(const DrawingFrame
* frame
,
566 const DrawQuad
* quad
) {
568 current_paint_
.setColor(SK_ColorWHITE
);
570 current_paint_
.setColor(SK_ColorMAGENTA
);
572 current_paint_
.setAlpha(quad
->opacity() * 255);
573 current_canvas_
->drawRect(gfx::RectFToSkRect(QuadVertexRect()),
577 void SoftwareRenderer::CopyCurrentRenderPassToBitmap(
579 scoped_ptr
<CopyOutputRequest
> request
) {
580 gfx::Rect copy_rect
= frame
->current_render_pass
->output_rect
;
581 if (request
->has_area())
582 copy_rect
.Intersect(request
->area());
583 gfx::Rect window_copy_rect
= MoveFromDrawToWindowSpace(frame
, copy_rect
);
585 scoped_ptr
<SkBitmap
> bitmap(new SkBitmap
);
586 bitmap
->setInfo(SkImageInfo::MakeN32Premul(window_copy_rect
.width(),
587 window_copy_rect
.height()));
588 current_canvas_
->readPixels(
589 bitmap
.get(), window_copy_rect
.x(), window_copy_rect
.y());
591 request
->SendBitmapResult(bitmap
.Pass());
594 void SoftwareRenderer::DiscardBackbuffer() {
595 if (is_backbuffer_discarded_
)
598 output_surface_
->DiscardBackbuffer();
600 is_backbuffer_discarded_
= true;
602 // Damage tracker needs a full reset every time framebuffer is discarded.
603 client_
->SetFullRootLayerDamage();
606 void SoftwareRenderer::EnsureBackbuffer() {
607 if (!is_backbuffer_discarded_
)
610 output_surface_
->EnsureBackbuffer();
611 is_backbuffer_discarded_
= false;
614 void SoftwareRenderer::DidChangeVisibility() {