| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "cc/output/software_renderer.h" | 5 #include "cc/output/skia_renderer.h" |
| 6 | 6 |
| 7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
| 8 #include "base/trace_event/trace_event.h" | 8 #include "base/trace_event/trace_event.h" |
| 9 #include "cc/base/math_util.h" | 9 #include "cc/base/math_util.h" |
| 10 #include "cc/output/compositor_frame.h" | 10 #include "cc/output/compositor_frame.h" |
| 11 #include "cc/output/compositor_frame_ack.h" | 11 #include "cc/output/compositor_frame_ack.h" |
| 12 #include "cc/output/compositor_frame_metadata.h" | 12 #include "cc/output/compositor_frame_metadata.h" |
| 13 #include "cc/output/copy_output_request.h" | 13 #include "cc/output/copy_output_request.h" |
| 14 #include "cc/output/output_surface.h" | 14 #include "cc/output/output_surface.h" |
| 15 #include "cc/output/render_surface_filters.h" | 15 #include "cc/output/render_surface_filters.h" |
| 16 #include "cc/output/software_output_device.h" | 16 #include "cc/output/software_output_device.h" |
| 17 #include "cc/quads/debug_border_draw_quad.h" | 17 #include "cc/quads/debug_border_draw_quad.h" |
| 18 #include "cc/quads/picture_draw_quad.h" | 18 #include "cc/quads/picture_draw_quad.h" |
| 19 #include "cc/quads/render_pass_draw_quad.h" | 19 #include "cc/quads/render_pass_draw_quad.h" |
| 20 #include "cc/quads/solid_color_draw_quad.h" | 20 #include "cc/quads/solid_color_draw_quad.h" |
| 21 #include "cc/quads/texture_draw_quad.h" | 21 #include "cc/quads/texture_draw_quad.h" |
| 22 #include "cc/quads/tile_draw_quad.h" | 22 #include "cc/quads/tile_draw_quad.h" |
| 23 #include "gpu/command_buffer/client/gles2_interface.h" |
| 23 #include "skia/ext/opacity_filter_canvas.h" | 24 #include "skia/ext/opacity_filter_canvas.h" |
| 24 #include "third_party/skia/include/core/SkCanvas.h" | 25 #include "third_party/skia/include/core/SkCanvas.h" |
| 25 #include "third_party/skia/include/core/SkColor.h" | 26 #include "third_party/skia/include/core/SkColor.h" |
| 26 #include "third_party/skia/include/core/SkImageFilter.h" | 27 #include "third_party/skia/include/core/SkImageFilter.h" |
| 27 #include "third_party/skia/include/core/SkMatrix.h" | 28 #include "third_party/skia/include/core/SkMatrix.h" |
| 28 #include "third_party/skia/include/core/SkPath.h" | 29 #include "third_party/skia/include/core/SkPath.h" |
| 29 #include "third_party/skia/include/core/SkPoint.h" | 30 #include "third_party/skia/include/core/SkPoint.h" |
| 30 #include "third_party/skia/include/core/SkShader.h" | 31 #include "third_party/skia/include/core/SkShader.h" |
| 31 #include "third_party/skia/include/effects/SkLayerRasterizer.h" | 32 #include "third_party/skia/include/effects/SkLayerRasterizer.h" |
| 33 #include "third_party/skia/include/gpu/GrContext.h" |
| 32 #include "ui/gfx/geometry/rect_conversions.h" | 34 #include "ui/gfx/geometry/rect_conversions.h" |
| 33 #include "ui/gfx/skia_util.h" | 35 #include "ui/gfx/skia_util.h" |
| 34 #include "ui/gfx/transform.h" | 36 #include "ui/gfx/transform.h" |
| 35 | 37 |
| 36 namespace cc { | 38 namespace cc { |
| 37 namespace { | 39 namespace { |
| 38 | 40 |
| 39 static inline bool IsScalarNearlyInteger(SkScalar scalar) { | 41 static inline bool IsScalarNearlyInteger(SkScalar scalar) { |
| 40 return SkScalarNearlyZero(scalar - SkScalarRoundToScalar(scalar)); | 42 return SkScalarNearlyZero(scalar - SkScalarRoundToScalar(scalar)); |
| 41 } | 43 } |
| 42 | 44 |
| 43 bool IsScaleAndIntegerTranslate(const SkMatrix& matrix) { | 45 bool IsScaleAndIntegerTranslate(const SkMatrix& matrix) { |
| 44 return IsScalarNearlyInteger(matrix[SkMatrix::kMTransX]) && | 46 return IsScalarNearlyInteger(matrix[SkMatrix::kMTransX]) && |
| 45 IsScalarNearlyInteger(matrix[SkMatrix::kMTransY]) && | 47 IsScalarNearlyInteger(matrix[SkMatrix::kMTransY]) && |
| 46 SkScalarNearlyZero(matrix[SkMatrix::kMSkewX]) && | 48 SkScalarNearlyZero(matrix[SkMatrix::kMSkewX]) && |
| 47 SkScalarNearlyZero(matrix[SkMatrix::kMSkewY]) && | 49 SkScalarNearlyZero(matrix[SkMatrix::kMSkewY]) && |
| 48 SkScalarNearlyZero(matrix[SkMatrix::kMPersp0]) && | 50 SkScalarNearlyZero(matrix[SkMatrix::kMPersp0]) && |
| 49 SkScalarNearlyZero(matrix[SkMatrix::kMPersp1]) && | 51 SkScalarNearlyZero(matrix[SkMatrix::kMPersp1]) && |
| 50 SkScalarNearlyZero(matrix[SkMatrix::kMPersp2] - 1.0f); | 52 SkScalarNearlyZero(matrix[SkMatrix::kMPersp2] - 1.0f); |
| 51 } | 53 } |
| 52 | 54 |
| 53 } // anonymous namespace | 55 } // anonymous namespace |
| 54 | 56 |
| 55 std::unique_ptr<SoftwareRenderer> SoftwareRenderer::Create( | 57 std::unique_ptr<SkiaRenderer> SkiaRenderer::Create( |
| 56 RendererClient* client, | 58 RendererClient* client, |
| 57 const RendererSettings* settings, | 59 const RendererSettings* settings, |
| 58 OutputSurface* output_surface, | 60 OutputSurface* output_surface, |
| 59 ResourceProvider* resource_provider, | 61 ResourceProvider* resource_provider, |
| 60 bool use_image_hijack_canvas) { | 62 bool use_image_hijack_canvas) { |
| 61 return base::WrapUnique(new SoftwareRenderer(client, settings, output_surface, | 63 return base::WrapUnique(new SkiaRenderer(client, settings, output_surface, |
| 62 resource_provider, | 64 resource_provider, |
| 63 use_image_hijack_canvas)); | 65 use_image_hijack_canvas)); |
| 64 } | 66 } |
| 65 | 67 |
| 66 SoftwareRenderer::SoftwareRenderer(RendererClient* client, | 68 SkiaRenderer::SkiaRenderer(RendererClient* client, |
| 67 const RendererSettings* settings, | 69 const RendererSettings* settings, |
| 68 OutputSurface* output_surface, | 70 OutputSurface* output_surface, |
| 69 ResourceProvider* resource_provider, | 71 ResourceProvider* resource_provider, |
| 70 bool use_image_hijack_canvas) | 72 bool use_image_hijack_canvas) |
| 71 : DirectRenderer(client, settings, output_surface, resource_provider), | 73 : DirectRenderer(client, settings, output_surface, resource_provider), |
| 72 is_scissor_enabled_(false), | 74 is_scissor_enabled_(false), |
| 73 is_backbuffer_discarded_(false), | 75 is_backbuffer_discarded_(false), |
| 74 output_device_(output_surface->software_device()), | |
| 75 current_canvas_(nullptr), | 76 current_canvas_(nullptr), |
| 76 use_image_hijack_canvas_(use_image_hijack_canvas) { | 77 use_image_hijack_canvas_(use_image_hijack_canvas) { |
| 77 if (resource_provider_) { | 78 if (resource_provider_) { |
| 78 capabilities_.max_texture_size = resource_provider_->max_texture_size(); | 79 capabilities_.max_texture_size = resource_provider_->max_texture_size(); |
| 79 capabilities_.best_texture_format = | 80 capabilities_.best_texture_format = |
| 80 resource_provider_->best_texture_format(); | 81 resource_provider_->best_texture_format(); |
| 81 } | 82 } |
| 82 // The updater can access bitmaps while the SoftwareRenderer is using them. | 83 // The updater can access bitmaps while the SkiaRenderer is using them. |
| 83 capabilities_.allow_partial_texture_updates = true; | 84 capabilities_.allow_partial_texture_updates = true; |
| 84 capabilities_.using_partial_swap = true; | 85 capabilities_.using_partial_swap = true; |
| 85 | 86 |
| 86 capabilities_.using_shared_memory_resources = true; | 87 capabilities_.using_shared_memory_resources = true; |
| 87 | 88 |
| 88 capabilities_.allow_rasterize_on_demand = true; | 89 capabilities_.allow_rasterize_on_demand = true; |
| 89 } | 90 } |
| 90 | 91 |
| 91 SoftwareRenderer::~SoftwareRenderer() {} | 92 SkiaRenderer::~SkiaRenderer() {} |
| 92 | 93 |
| 93 const RendererCapabilitiesImpl& SoftwareRenderer::Capabilities() const { | 94 const RendererCapabilitiesImpl& SkiaRenderer::Capabilities() const { |
| 94 return capabilities_; | 95 return capabilities_; |
| 95 } | 96 } |
| 96 | 97 |
| 97 void SoftwareRenderer::BeginDrawingFrame(DrawingFrame* frame) { | 98 void SkiaRenderer::BeginDrawingFrame(DrawingFrame* frame) { |
| 98 TRACE_EVENT0("cc", "SoftwareRenderer::BeginDrawingFrame"); | 99 TRACE_EVENT0("cc", "SkiaRenderer::BeginDrawingFrame"); |
| 99 root_canvas_ = output_device_->BeginPaint(frame->root_damage_rect); | 100 |
| 101 // ----- BEGIN COPYPASTA FROM GL RENDERER |
| 102 bool use_sync_query_ = false; |
| 103 scoped_refptr<ResourceProvider::Fence> read_lock_fence; |
| 104 if (use_sync_query_) { |
| 105 #if 0 |
| 106 // Block until oldest sync query has passed if the number of pending queries |
| 107 // ever reach kMaxPendingSyncQueries. |
| 108 if (pending_sync_queries_.size() >= kMaxPendingSyncQueries) { |
| 109 LOG(ERROR) << "Reached limit of pending sync queries."; |
| 110 |
| 111 pending_sync_queries_.front()->Wait(); |
| 112 DCHECK(!pending_sync_queries_.front()->IsPending()); |
| 113 } |
| 114 |
| 115 while (!pending_sync_queries_.empty()) { |
| 116 if (pending_sync_queries_.front()->IsPending()) |
| 117 break; |
| 118 |
| 119 available_sync_queries_.push_back(PopFront(&pending_sync_queries_)); |
| 120 } |
| 121 |
| 122 current_sync_query_ = available_sync_queries_.empty() |
| 123 ? base::WrapUnique(new SyncQuery(gl_)) |
| 124 : PopFront(&available_sync_queries_); |
| 125 |
| 126 read_lock_fence = current_sync_query_->Begin(); |
| 127 #endif |
| 128 } else { |
| 129 read_lock_fence = make_scoped_refptr(new ResourceProvider::SynchronousFence( |
| 130 output_surface_->context_provider()->ContextGL())); |
| 131 } |
| 132 resource_provider_->SetReadLockFence(read_lock_fence.get()); |
| 133 |
| 134 // Insert WaitSyncTokenCHROMIUM on quad resources prior to drawing the frame, |
| 135 // so that drawing can proceed without GL context switching interruptions. |
| 136 ResourceProvider* resource_provider = resource_provider_; |
| 137 for (const auto& pass : *frame->render_passes_in_draw_order) { |
| 138 for (const auto& quad : pass->quad_list) { |
| 139 for (ResourceId resource_id : quad->resources) |
| 140 resource_provider->WaitSyncTokenIfNeeded(resource_id); |
| 141 } |
| 142 } |
| 143 // ----- END COPYPASTA FROM GL RENDERER |
| 100 } | 144 } |
| 101 | 145 |
| 102 void SoftwareRenderer::FinishDrawingFrame(DrawingFrame* frame) { | 146 void SkiaRenderer::FinishDrawingFrame(DrawingFrame* frame) { |
| 103 TRACE_EVENT0("cc", "SoftwareRenderer::FinishDrawingFrame"); | 147 TRACE_EVENT0("cc", "SkiaRenderer::FinishDrawingFrame"); |
| 148 current_framebuffer_surface_lock_ = nullptr; |
| 104 current_framebuffer_lock_ = nullptr; | 149 current_framebuffer_lock_ = nullptr; |
| 105 current_framebuffer_canvas_.reset(); | 150 current_canvas_ = nullptr; |
| 106 current_canvas_ = NULL; | |
| 107 root_canvas_ = NULL; | |
| 108 | |
| 109 output_device_->EndPaint(); | |
| 110 } | 151 } |
| 111 | 152 |
| 112 void SoftwareRenderer::SwapBuffers(const CompositorFrameMetadata& metadata) { | 153 void SkiaRenderer::SwapBuffers(const CompositorFrameMetadata& metadata) { |
| 113 TRACE_EVENT0("cc,benchmark", "SoftwareRenderer::SwapBuffers"); | 154 TRACE_EVENT0("cc,benchmark", "SkiaRenderer::SwapBuffers"); |
| 114 CompositorFrame compositor_frame; | 155 CompositorFrame compositor_frame; |
| 115 compositor_frame.metadata = metadata; | 156 compositor_frame.metadata = metadata; |
| 157 |
| 158 compositor_frame.gl_frame_data = base::WrapUnique(new GLFrameData); |
| 159 gfx::Size surface_size = output_surface_->SurfaceSize(); |
| 160 // TODO(enne): add in partial swap stuff here from gl renderer |
| 161 compositor_frame.gl_frame_data->size = surface_size; |
| 162 compositor_frame.gl_frame_data->sub_buffer_rect = gfx::Rect(surface_size); |
| 163 |
| 116 output_surface_->SwapBuffers(&compositor_frame); | 164 output_surface_->SwapBuffers(&compositor_frame); |
| 117 } | 165 } |
| 118 | 166 |
| 119 bool SoftwareRenderer::FlippedFramebuffer(const DrawingFrame* frame) const { | 167 bool SkiaRenderer::FlippedFramebuffer(const DrawingFrame* frame) const { |
| 120 return false; | 168 return false; |
| 121 } | 169 } |
| 122 | 170 |
| 123 void SoftwareRenderer::EnsureScissorTestEnabled() { | 171 void SkiaRenderer::EnsureScissorTestEnabled() { |
| 124 is_scissor_enabled_ = true; | 172 is_scissor_enabled_ = true; |
| 125 SetClipRect(scissor_rect_); | 173 SetClipRect(scissor_rect_); |
| 126 } | 174 } |
| 127 | 175 |
| 128 void SoftwareRenderer::EnsureScissorTestDisabled() { | 176 void SkiaRenderer::EnsureScissorTestDisabled() { |
| 129 // There is no explicit notion of enabling/disabling scissoring in software | 177 // There is no explicit notion of enabling/disabling scissoring in software |
| 130 // rendering, but the underlying effect we want is to clear any existing | 178 // rendering, but the underlying effect we want is to clear any existing |
| 131 // clipRect on the current SkCanvas. This is done by setting clipRect to | 179 // clipRect on the current SkCanvas. This is done by setting clipRect to |
| 132 // the viewport's dimensions. | 180 // the viewport's dimensions. |
| 133 if (!current_canvas_) | 181 if (!current_canvas_) |
| 134 return; | 182 return; |
| 135 is_scissor_enabled_ = false; | 183 is_scissor_enabled_ = false; |
| 136 SkISize size = current_canvas_->getBaseLayerSize(); | 184 SkISize size = current_canvas_->getBaseLayerSize(); |
| 137 SetClipRect(gfx::Rect(size.width(), size.height())); | 185 SetClipRect(gfx::Rect(size.width(), size.height())); |
| 138 } | 186 } |
| 139 | 187 |
| 140 void SoftwareRenderer::Finish() {} | 188 void SkiaRenderer::Finish() {} |
| 141 | 189 |
| 142 void SoftwareRenderer::BindFramebufferToOutputSurface(DrawingFrame* frame) { | 190 void SkiaRenderer::BindFramebufferToOutputSurface(DrawingFrame* frame) { |
| 143 DCHECK(!output_surface_->HasExternalStencilTest()); | 191 DCHECK(!output_surface_->HasExternalStencilTest()); |
| 144 current_framebuffer_lock_ = nullptr; | 192 current_framebuffer_lock_ = nullptr; |
| 145 current_framebuffer_canvas_.reset(); | 193 |
| 194 // TODO(enne): Probably don't need to recreate this every frame? |
| 195 GrBackendRenderTargetDesc desc; |
| 196 desc.fWidth = frame->device_viewport_rect.width(); |
| 197 desc.fHeight = frame->device_viewport_rect.height(); |
| 198 desc.fConfig = kRGBA_8888_GrPixelConfig; |
| 199 desc.fOrigin = kBottomLeft_GrSurfaceOrigin; |
| 200 desc.fSampleCnt = 1; |
| 201 desc.fStencilBits = 8; |
| 202 desc.fRenderTargetHandle = 0; |
| 203 |
| 204 GrContext* gr_context = output_surface_->context_provider()->GrContext(); |
| 205 |
| 206 // Copypasta from resource_provider |
| 207 // Use unknown pixel geometry to disable LCD text. |
| 208 bool use_distance_field_text = false; |
| 209 bool can_use_lcd_text = true; |
| 210 uint32_t flags = |
| 211 use_distance_field_text ? SkSurfaceProps::kUseDistanceFieldFonts_Flag : 0; |
| 212 SkSurfaceProps surface_props(flags, kUnknown_SkPixelGeometry); |
| 213 if (can_use_lcd_text) { |
| 214 // LegacyFontHost will get LCD text and skia figures out what type to use. |
| 215 surface_props = |
| 216 SkSurfaceProps(flags, SkSurfaceProps::kLegacyFontHost_InitType); |
| 217 } |
| 218 root_surface_ = |
| 219 SkSurface::MakeFromBackendRenderTarget(gr_context, desc, &surface_props); |
| 220 root_canvas_ = root_surface_->getCanvas(); |
| 221 |
| 146 current_canvas_ = root_canvas_; | 222 current_canvas_ = root_canvas_; |
| 147 } | 223 } |
| 148 | 224 |
| 149 bool SoftwareRenderer::BindFramebufferToTexture( | 225 bool SkiaRenderer::BindFramebufferToTexture(DrawingFrame* frame, |
| 150 DrawingFrame* frame, | 226 const ScopedResource* texture) { |
| 151 const ScopedResource* texture) { | |
| 152 DCHECK(texture->id()); | 227 DCHECK(texture->id()); |
| 153 | 228 |
| 154 // Explicitly release lock, otherwise we can crash when try to lock | 229 // Explicitly release lock, otherwise we can crash when try to lock |
| 155 // same texture again. | 230 // same texture again. |
| 231 current_framebuffer_surface_lock_ = nullptr; |
| 156 current_framebuffer_lock_ = nullptr; | 232 current_framebuffer_lock_ = nullptr; |
| 157 current_framebuffer_lock_ = | 233 current_framebuffer_lock_ = |
| 158 base::WrapUnique(new ResourceProvider::ScopedWriteLockSoftware( | 234 base::WrapUnique(new ResourceProvider::ScopedWriteLockGL( |
| 159 resource_provider_, texture->id())); | 235 resource_provider_, texture->id(), false)); |
| 160 current_framebuffer_canvas_ = | 236 |
| 161 sk_make_sp<SkCanvas>(current_framebuffer_lock_->sk_bitmap()); | 237 current_framebuffer_surface_lock_ = |
| 162 current_canvas_ = current_framebuffer_canvas_.get(); | 238 base::WrapUnique(new ResourceProvider::ScopedSkSurfaceProvider( |
| 239 output_surface_->context_provider(), current_framebuffer_lock_.get(), |
| 240 false, false, true, 0)); |
| 241 |
| 242 current_canvas_ = |
| 243 current_framebuffer_surface_lock_->sk_surface()->getCanvas(); |
| 163 return true; | 244 return true; |
| 164 } | 245 } |
| 165 | 246 |
| 166 void SoftwareRenderer::SetScissorTestRect(const gfx::Rect& scissor_rect) { | 247 void SkiaRenderer::SetScissorTestRect(const gfx::Rect& scissor_rect) { |
| 167 is_scissor_enabled_ = true; | 248 is_scissor_enabled_ = true; |
| 168 scissor_rect_ = scissor_rect; | 249 scissor_rect_ = scissor_rect; |
| 169 SetClipRect(scissor_rect); | 250 SetClipRect(scissor_rect); |
| 170 } | 251 } |
| 171 | 252 |
| 172 void SoftwareRenderer::SetClipRect(const gfx::Rect& rect) { | 253 void SkiaRenderer::SetClipRect(const gfx::Rect& rect) { |
| 173 if (!current_canvas_) | 254 if (!current_canvas_) |
| 174 return; | 255 return; |
| 175 // Skia applies the current matrix to clip rects so we reset it temporary. | 256 // Skia applies the current matrix to clip rects so we reset it temporary. |
| 176 SkMatrix current_matrix = current_canvas_->getTotalMatrix(); | 257 SkMatrix current_matrix = current_canvas_->getTotalMatrix(); |
| 177 current_canvas_->resetMatrix(); | 258 current_canvas_->resetMatrix(); |
| 178 current_canvas_->clipRect(gfx::RectToSkRect(rect), SkRegion::kReplace_Op); | 259 current_canvas_->clipRect(gfx::RectToSkRect(rect), SkRegion::kReplace_Op); |
| 179 current_canvas_->setMatrix(current_matrix); | 260 current_canvas_->setMatrix(current_matrix); |
| 180 } | 261 } |
| 181 | 262 |
| 182 void SoftwareRenderer::ClearCanvas(SkColor color) { | 263 void SkiaRenderer::ClearCanvas(SkColor color) { |
| 183 if (!current_canvas_) | 264 if (!current_canvas_) |
| 184 return; | 265 return; |
| 185 // SkCanvas::clear doesn't respect the current clipping region | 266 // SkCanvas::clear doesn't respect the current clipping region |
| 186 // so we SkCanvas::drawColor instead if scissoring is active. | 267 // so we SkCanvas::drawColor instead if scissoring is active. |
| 187 if (is_scissor_enabled_) | 268 if (is_scissor_enabled_) |
| 188 current_canvas_->drawColor(color, SkXfermode::kSrc_Mode); | 269 current_canvas_->drawColor(color, SkXfermode::kSrc_Mode); |
| 189 else | 270 else |
| 190 current_canvas_->clear(color); | 271 current_canvas_->clear(color); |
| 191 } | 272 } |
| 192 | 273 |
| 193 void SoftwareRenderer::ClearFramebuffer(DrawingFrame* frame) { | 274 void SkiaRenderer::ClearFramebuffer(DrawingFrame* frame) { |
| 194 if (frame->current_render_pass->has_transparent_background) { | 275 if (frame->current_render_pass->has_transparent_background) { |
| 195 ClearCanvas(SkColorSetARGB(0, 0, 0, 0)); | 276 ClearCanvas(SkColorSetARGB(0, 0, 0, 0)); |
| 196 } else { | 277 } else { |
| 197 #ifndef NDEBUG | 278 #ifndef NDEBUG |
| 198 // On DEBUG builds, opaque render passes are cleared to blue | 279 // On DEBUG builds, opaque render passes are cleared to blue |
| 199 // to easily see regions that were not drawn on the screen. | 280 // to easily see regions that were not drawn on the screen. |
| 200 ClearCanvas(SkColorSetARGB(255, 0, 0, 255)); | 281 ClearCanvas(SkColorSetARGB(255, 0, 0, 255)); |
| 201 #endif | 282 #endif |
| 202 } | 283 } |
| 203 } | 284 } |
| 204 | 285 |
| 205 void SoftwareRenderer::PrepareSurfaceForPass( | 286 void SkiaRenderer::PrepareSurfaceForPass( |
| 206 DrawingFrame* frame, | 287 DrawingFrame* frame, |
| 207 SurfaceInitializationMode initialization_mode, | 288 SurfaceInitializationMode initialization_mode, |
| 208 const gfx::Rect& render_pass_scissor) { | 289 const gfx::Rect& render_pass_scissor) { |
| 209 switch (initialization_mode) { | 290 switch (initialization_mode) { |
| 210 case SURFACE_INITIALIZATION_MODE_PRESERVE: | 291 case SURFACE_INITIALIZATION_MODE_PRESERVE: |
| 211 EnsureScissorTestDisabled(); | 292 EnsureScissorTestDisabled(); |
| 212 return; | 293 return; |
| 213 case SURFACE_INITIALIZATION_MODE_FULL_SURFACE_CLEAR: | 294 case SURFACE_INITIALIZATION_MODE_FULL_SURFACE_CLEAR: |
| 214 EnsureScissorTestDisabled(); | 295 EnsureScissorTestDisabled(); |
| 215 ClearFramebuffer(frame); | 296 ClearFramebuffer(frame); |
| 216 break; | 297 break; |
| 217 case SURFACE_INITIALIZATION_MODE_SCISSORED_CLEAR: | 298 case SURFACE_INITIALIZATION_MODE_SCISSORED_CLEAR: |
| 218 SetScissorTestRect(render_pass_scissor); | 299 SetScissorTestRect(render_pass_scissor); |
| 219 ClearFramebuffer(frame); | 300 ClearFramebuffer(frame); |
| 220 break; | 301 break; |
| 221 } | 302 } |
| 222 } | 303 } |
| 223 | 304 |
| 224 bool SoftwareRenderer::IsSoftwareResource(ResourceId resource_id) const { | 305 // TODO(enne): doot dee doo |
| 306 bool SkiaRenderer::IsSoftwareResource(ResourceId resource_id) const { |
| 225 switch (resource_provider_->GetResourceType(resource_id)) { | 307 switch (resource_provider_->GetResourceType(resource_id)) { |
| 226 case ResourceProvider::RESOURCE_TYPE_GPU_MEMORY_BUFFER: | 308 case ResourceProvider::RESOURCE_TYPE_GPU_MEMORY_BUFFER: |
| 227 case ResourceProvider::RESOURCE_TYPE_GL_TEXTURE: | 309 case ResourceProvider::RESOURCE_TYPE_GL_TEXTURE: |
| 310 return true; |
| 311 case ResourceProvider::RESOURCE_TYPE_BITMAP: |
| 228 return false; | 312 return false; |
| 229 case ResourceProvider::RESOURCE_TYPE_BITMAP: | |
| 230 return true; | |
| 231 } | 313 } |
| 232 | 314 |
| 233 LOG(FATAL) << "Invalid resource type."; | 315 LOG(FATAL) << "Invalid resource type."; |
| 234 return false; | 316 return false; |
| 235 } | 317 } |
| 236 | 318 |
| 237 void SoftwareRenderer::DoDrawQuad(DrawingFrame* frame, | 319 void SkiaRenderer::DoDrawQuad(DrawingFrame* frame, |
| 238 const DrawQuad* quad, | 320 const DrawQuad* quad, |
| 239 const gfx::QuadF* draw_region) { | 321 const gfx::QuadF* draw_region) { |
| 240 if (!current_canvas_) | 322 if (!current_canvas_) |
| 241 return; | 323 return; |
| 242 if (draw_region) { | 324 if (draw_region) { |
| 243 current_canvas_->save(); | 325 current_canvas_->save(); |
| 244 } | 326 } |
| 245 | 327 |
| 246 TRACE_EVENT0("cc", "SoftwareRenderer::DoDrawQuad"); | 328 TRACE_EVENT0("cc", "SkiaRenderer::DoDrawQuad"); |
| 247 gfx::Transform quad_rect_matrix; | 329 gfx::Transform quad_rect_matrix; |
| 248 QuadRectTransform(&quad_rect_matrix, | 330 QuadRectTransform(&quad_rect_matrix, |
| 249 quad->shared_quad_state->quad_to_target_transform, | 331 quad->shared_quad_state->quad_to_target_transform, |
| 250 gfx::RectF(quad->rect)); | 332 gfx::RectF(quad->rect)); |
| 251 gfx::Transform contents_device_transform = | 333 gfx::Transform contents_device_transform = |
| 252 frame->window_matrix * frame->projection_matrix * quad_rect_matrix; | 334 frame->window_matrix * frame->projection_matrix * quad_rect_matrix; |
| 253 contents_device_transform.FlattenTo2d(); | 335 contents_device_transform.FlattenTo2d(); |
| 254 SkMatrix sk_device_matrix; | 336 SkMatrix sk_device_matrix; |
| 255 gfx::TransformToFlattenedSkMatrix(contents_device_transform, | 337 gfx::TransformToFlattenedSkMatrix(contents_device_transform, |
| 256 &sk_device_matrix); | 338 &sk_device_matrix); |
| 257 current_canvas_->setMatrix(sk_device_matrix); | 339 current_canvas_->setMatrix(sk_device_matrix); |
| 258 | 340 |
| 259 current_paint_.reset(); | 341 current_paint_.reset(); |
| 260 if (settings_->force_antialiasing || | 342 if (settings_->force_antialiasing || |
| 261 !IsScaleAndIntegerTranslate(sk_device_matrix)) { | 343 !IsScaleAndIntegerTranslate(sk_device_matrix)) { |
| 262 // TODO(danakj): Until we can enable AA only on exterior edges of the | 344 // TODO(danakj): Until we can enable AA only on exterior edges of the |
| 263 // layer, disable AA if any interior edges are present. crbug.com/248175 | 345 // layer, disable AA if any interior edges are present. crbug.com/248175 |
| 264 bool all_four_edges_are_exterior = quad->IsTopEdge() && | 346 bool all_four_edges_are_exterior = |
| 265 quad->IsLeftEdge() && | 347 quad->IsTopEdge() && quad->IsLeftEdge() && quad->IsBottomEdge() && |
| 266 quad->IsBottomEdge() && | 348 quad->IsRightEdge(); |
| 267 quad->IsRightEdge(); | |
| 268 if (settings_->allow_antialiasing && | 349 if (settings_->allow_antialiasing && |
| 269 (settings_->force_antialiasing || all_four_edges_are_exterior)) | 350 (settings_->force_antialiasing || all_four_edges_are_exterior)) |
| 270 current_paint_.setAntiAlias(true); | 351 current_paint_.setAntiAlias(true); |
| 271 current_paint_.setFilterQuality(kLow_SkFilterQuality); | 352 current_paint_.setFilterQuality(kLow_SkFilterQuality); |
| 272 } | 353 } |
| 273 | 354 |
| 274 if (quad->ShouldDrawWithBlending() || | 355 if (quad->ShouldDrawWithBlending() || |
| 275 quad->shared_quad_state->blend_mode != SkXfermode::kSrcOver_Mode) { | 356 quad->shared_quad_state->blend_mode != SkXfermode::kSrcOver_Mode) { |
| 276 current_paint_.setAlpha(quad->shared_quad_state->opacity * 255); | 357 current_paint_.setAlpha(quad->shared_quad_state->opacity * 255); |
| 277 current_paint_.setXfermodeMode(quad->shared_quad_state->blend_mode); | 358 current_paint_.setXfermodeMode(quad->shared_quad_state->blend_mode); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 327 NOTREACHED(); | 408 NOTREACHED(); |
| 328 break; | 409 break; |
| 329 } | 410 } |
| 330 | 411 |
| 331 current_canvas_->resetMatrix(); | 412 current_canvas_->resetMatrix(); |
| 332 if (draw_region) { | 413 if (draw_region) { |
| 333 current_canvas_->restore(); | 414 current_canvas_->restore(); |
| 334 } | 415 } |
| 335 } | 416 } |
| 336 | 417 |
| 337 void SoftwareRenderer::DrawDebugBorderQuad(const DrawingFrame* frame, | 418 void SkiaRenderer::DrawDebugBorderQuad(const DrawingFrame* frame, |
| 338 const DebugBorderDrawQuad* quad) { | 419 const DebugBorderDrawQuad* quad) { |
| 339 // We need to apply the matrix manually to have pixel-sized stroke width. | 420 // We need to apply the matrix manually to have pixel-sized stroke width. |
| 340 SkPoint vertices[4]; | 421 SkPoint vertices[4]; |
| 341 gfx::RectFToSkRect(QuadVertexRect()).toQuad(vertices); | 422 gfx::RectFToSkRect(QuadVertexRect()).toQuad(vertices); |
| 342 SkPoint transformed_vertices[4]; | 423 SkPoint transformed_vertices[4]; |
| 343 current_canvas_->getTotalMatrix().mapPoints(transformed_vertices, | 424 current_canvas_->getTotalMatrix().mapPoints(transformed_vertices, vertices, |
| 344 vertices, | |
| 345 4); | 425 4); |
| 346 current_canvas_->resetMatrix(); | 426 current_canvas_->resetMatrix(); |
| 347 | 427 |
| 348 current_paint_.setColor(quad->color); | 428 current_paint_.setColor(quad->color); |
| 349 current_paint_.setAlpha(quad->shared_quad_state->opacity * | 429 current_paint_.setAlpha(quad->shared_quad_state->opacity * |
| 350 SkColorGetA(quad->color)); | 430 SkColorGetA(quad->color)); |
| 351 current_paint_.setStyle(SkPaint::kStroke_Style); | 431 current_paint_.setStyle(SkPaint::kStroke_Style); |
| 352 current_paint_.setStrokeWidth(quad->width); | 432 current_paint_.setStrokeWidth(quad->width); |
| 353 current_canvas_->drawPoints(SkCanvas::kPolygon_PointMode, | 433 current_canvas_->drawPoints(SkCanvas::kPolygon_PointMode, 4, |
| 354 4, transformed_vertices, current_paint_); | 434 transformed_vertices, current_paint_); |
| 355 } | 435 } |
| 356 | 436 |
| 357 void SoftwareRenderer::DrawPictureQuad(const DrawingFrame* frame, | 437 void SkiaRenderer::DrawPictureQuad(const DrawingFrame* frame, |
| 358 const PictureDrawQuad* quad) { | 438 const PictureDrawQuad* quad) { |
| 359 SkMatrix content_matrix; | 439 SkMatrix content_matrix; |
| 360 content_matrix.setRectToRect( | 440 content_matrix.setRectToRect(gfx::RectFToSkRect(quad->tex_coord_rect), |
| 361 gfx::RectFToSkRect(quad->tex_coord_rect), | 441 gfx::RectFToSkRect(QuadVertexRect()), |
| 362 gfx::RectFToSkRect(QuadVertexRect()), | 442 SkMatrix::kFill_ScaleToFit); |
| 363 SkMatrix::kFill_ScaleToFit); | |
| 364 current_canvas_->concat(content_matrix); | 443 current_canvas_->concat(content_matrix); |
| 365 | 444 |
| 366 const bool needs_transparency = | 445 const bool needs_transparency = |
| 367 SkScalarRoundToInt(quad->shared_quad_state->opacity * 255) < 255; | 446 SkScalarRoundToInt(quad->shared_quad_state->opacity * 255) < 255; |
| 368 const bool disable_image_filtering = | 447 const bool disable_image_filtering = |
| 369 frame->disable_picture_quad_image_filtering || quad->nearest_neighbor; | 448 frame->disable_picture_quad_image_filtering || quad->nearest_neighbor; |
| 370 | 449 |
| 371 TRACE_EVENT0("cc", "SoftwareRenderer::DrawPictureQuad"); | 450 TRACE_EVENT0("cc", "SkiaRenderer::DrawPictureQuad"); |
| 372 | 451 |
| 373 RasterSource::PlaybackSettings playback_settings; | 452 RasterSource::PlaybackSettings playback_settings; |
| 374 playback_settings.playback_to_shared_canvas = true; | 453 playback_settings.playback_to_shared_canvas = true; |
| 375 playback_settings.use_image_hijack_canvas = use_image_hijack_canvas_; | 454 playback_settings.use_image_hijack_canvas = use_image_hijack_canvas_; |
| 376 if (needs_transparency || disable_image_filtering) { | 455 if (needs_transparency || disable_image_filtering) { |
| 377 // TODO(aelias): This isn't correct in all cases. We should detect these | 456 // TODO(aelias): This isn't correct in all cases. We should detect these |
| 378 // cases and fall back to a persistent bitmap backing | 457 // cases and fall back to a persistent bitmap backing |
| 379 // (http://crbug.com/280374). | 458 // (http://crbug.com/280374). |
| 380 // TODO(vmpstr): Fold this canvas into playback and have raster source | 459 // TODO(vmpstr): Fold this canvas into playback and have raster source |
| 381 // accept a set of settings on playback that will determine which canvas to | 460 // accept a set of settings on playback that will determine which canvas to |
| 382 // apply. (http://crbug.com/594679) | 461 // apply. (http://crbug.com/594679) |
| 383 skia::OpacityFilterCanvas filtered_canvas(current_canvas_, | 462 skia::OpacityFilterCanvas filtered_canvas(current_canvas_, |
| 384 quad->shared_quad_state->opacity, | 463 quad->shared_quad_state->opacity, |
| 385 disable_image_filtering); | 464 disable_image_filtering); |
| 386 quad->raster_source->PlaybackToCanvas( | 465 quad->raster_source->PlaybackToCanvas( |
| 387 &filtered_canvas, quad->content_rect, quad->content_rect, | 466 &filtered_canvas, quad->content_rect, quad->content_rect, |
| 388 quad->contents_scale, playback_settings); | 467 quad->contents_scale, playback_settings); |
| 389 } else { | 468 } else { |
| 390 quad->raster_source->PlaybackToCanvas( | 469 quad->raster_source->PlaybackToCanvas( |
| 391 current_canvas_, quad->content_rect, quad->content_rect, | 470 current_canvas_, quad->content_rect, quad->content_rect, |
| 392 quad->contents_scale, playback_settings); | 471 quad->contents_scale, playback_settings); |
| 393 } | 472 } |
| 394 } | 473 } |
| 395 | 474 |
| 396 void SoftwareRenderer::DrawSolidColorQuad(const DrawingFrame* frame, | 475 void SkiaRenderer::DrawSolidColorQuad(const DrawingFrame* frame, |
| 397 const SolidColorDrawQuad* quad) { | 476 const SolidColorDrawQuad* quad) { |
| 398 gfx::RectF visible_quad_vertex_rect = MathUtil::ScaleRectProportional( | 477 gfx::RectF visible_quad_vertex_rect = MathUtil::ScaleRectProportional( |
| 399 QuadVertexRect(), gfx::RectF(quad->rect), gfx::RectF(quad->visible_rect)); | 478 QuadVertexRect(), gfx::RectF(quad->rect), gfx::RectF(quad->visible_rect)); |
| 400 current_paint_.setColor(quad->color); | 479 current_paint_.setColor(quad->color); |
| 401 current_paint_.setAlpha(quad->shared_quad_state->opacity * | 480 current_paint_.setAlpha(quad->shared_quad_state->opacity * |
| 402 SkColorGetA(quad->color)); | 481 SkColorGetA(quad->color)); |
| 403 current_canvas_->drawRect(gfx::RectFToSkRect(visible_quad_vertex_rect), | 482 current_canvas_->drawRect(gfx::RectFToSkRect(visible_quad_vertex_rect), |
| 404 current_paint_); | 483 current_paint_); |
| 405 } | 484 } |
| 406 | 485 |
| 407 void SoftwareRenderer::DrawTextureQuad(const DrawingFrame* frame, | 486 void SkiaRenderer::DrawTextureQuad(const DrawingFrame* frame, |
| 408 const TextureDrawQuad* quad) { | 487 const TextureDrawQuad* quad) { |
| 409 if (!IsSoftwareResource(quad->resource_id())) { | 488 if (!IsSoftwareResource(quad->resource_id())) { |
| 410 DrawUnsupportedQuad(frame, quad); | 489 DrawUnsupportedQuad(frame, quad); |
| 411 return; | 490 return; |
| 412 } | 491 } |
| 413 | 492 |
| 414 // TODO(skaslev): Add support for non-premultiplied alpha. | 493 // TODO(skaslev): Add support for non-premultiplied alpha. |
| 415 ResourceProvider::ScopedReadLockSoftware lock(resource_provider_, | 494 ResourceProvider::ScopedReadLockSkImage lock(resource_provider_, |
| 416 quad->resource_id()); | 495 quad->resource_id()); |
| 417 if (!lock.valid()) | 496 const SkImage* image = lock.sk_image(); |
| 418 return; | 497 gfx::RectF uv_rect = gfx::ScaleRect( |
| 419 const SkBitmap* bitmap = lock.sk_bitmap(); | 498 gfx::BoundingRect(quad->uv_top_left, quad->uv_bottom_right), |
| 420 gfx::RectF uv_rect = gfx::ScaleRect(gfx::BoundingRect(quad->uv_top_left, | 499 image->width(), image->height()); |
| 421 quad->uv_bottom_right), | |
| 422 bitmap->width(), | |
| 423 bitmap->height()); | |
| 424 gfx::RectF visible_uv_rect = MathUtil::ScaleRectProportional( | 500 gfx::RectF visible_uv_rect = MathUtil::ScaleRectProportional( |
| 425 uv_rect, gfx::RectF(quad->rect), gfx::RectF(quad->visible_rect)); | 501 uv_rect, gfx::RectF(quad->rect), gfx::RectF(quad->visible_rect)); |
| 426 SkRect sk_uv_rect = gfx::RectFToSkRect(visible_uv_rect); | 502 SkRect sk_uv_rect = gfx::RectFToSkRect(visible_uv_rect); |
| 427 gfx::RectF visible_quad_vertex_rect = MathUtil::ScaleRectProportional( | 503 gfx::RectF visible_quad_vertex_rect = MathUtil::ScaleRectProportional( |
| 428 QuadVertexRect(), gfx::RectF(quad->rect), gfx::RectF(quad->visible_rect)); | 504 QuadVertexRect(), gfx::RectF(quad->rect), gfx::RectF(quad->visible_rect)); |
| 429 SkRect quad_rect = gfx::RectFToSkRect(visible_quad_vertex_rect); | 505 SkRect quad_rect = gfx::RectFToSkRect(visible_quad_vertex_rect); |
| 430 | 506 |
| 431 if (quad->y_flipped) | 507 if (quad->y_flipped) |
| 432 current_canvas_->scale(1, -1); | 508 current_canvas_->scale(1, -1); |
| 433 | 509 |
| 434 bool blend_background = quad->background_color != SK_ColorTRANSPARENT && | 510 bool blend_background = |
| 435 !bitmap->isOpaque(); | 511 quad->background_color != SK_ColorTRANSPARENT && !image->isOpaque(); |
| 436 bool needs_layer = blend_background && (current_paint_.getAlpha() != 0xFF); | 512 bool needs_layer = blend_background && (current_paint_.getAlpha() != 0xFF); |
| 437 if (needs_layer) { | 513 if (needs_layer) { |
| 438 current_canvas_->saveLayerAlpha(&quad_rect, current_paint_.getAlpha()); | 514 current_canvas_->saveLayerAlpha(&quad_rect, current_paint_.getAlpha()); |
| 439 current_paint_.setAlpha(0xFF); | 515 current_paint_.setAlpha(0xFF); |
| 440 } | 516 } |
| 441 if (blend_background) { | 517 if (blend_background) { |
| 442 SkPaint background_paint; | 518 SkPaint background_paint; |
| 443 background_paint.setColor(quad->background_color); | 519 background_paint.setColor(quad->background_color); |
| 444 current_canvas_->drawRect(quad_rect, background_paint); | 520 current_canvas_->drawRect(quad_rect, background_paint); |
| 445 } | 521 } |
| 446 current_paint_.setFilterQuality( | 522 current_paint_.setFilterQuality( |
| 447 quad->nearest_neighbor ? kNone_SkFilterQuality : kLow_SkFilterQuality); | 523 quad->nearest_neighbor ? kNone_SkFilterQuality : kLow_SkFilterQuality); |
| 448 current_canvas_->drawBitmapRect(*bitmap, sk_uv_rect, quad_rect, | 524 current_canvas_->drawImageRect(image, sk_uv_rect, quad_rect, ¤t_paint_); |
| 449 ¤t_paint_); | |
| 450 if (needs_layer) | 525 if (needs_layer) |
| 451 current_canvas_->restore(); | 526 current_canvas_->restore(); |
| 452 } | 527 } |
| 453 | 528 |
| 454 void SoftwareRenderer::DrawTileQuad(const DrawingFrame* frame, | 529 void SkiaRenderer::DrawTileQuad(const DrawingFrame* frame, |
| 455 const TileDrawQuad* quad) { | 530 const TileDrawQuad* quad) { |
| 456 // |resource_provider_| can be NULL in resourceless software draws, which | 531 // |resource_provider_| can be NULL in resourceless software draws, which |
| 457 // should never produce tile quads in the first place. | 532 // should never produce tile quads in the first place. |
| 458 DCHECK(resource_provider_); | 533 DCHECK(resource_provider_); |
| 459 DCHECK(IsSoftwareResource(quad->resource_id())); | 534 DCHECK(IsSoftwareResource(quad->resource_id())); |
| 460 | 535 |
| 461 ResourceProvider::ScopedReadLockSoftware lock(resource_provider_, | 536 ResourceProvider::ScopedReadLockSkImage lock(resource_provider_, |
| 462 quad->resource_id()); | 537 quad->resource_id()); |
| 463 if (!lock.valid()) | |
| 464 return; | |
| 465 | 538 |
| 466 gfx::RectF visible_tex_coord_rect = MathUtil::ScaleRectProportional( | 539 gfx::RectF visible_tex_coord_rect = MathUtil::ScaleRectProportional( |
| 467 quad->tex_coord_rect, gfx::RectF(quad->rect), | 540 quad->tex_coord_rect, gfx::RectF(quad->rect), |
| 468 gfx::RectF(quad->visible_rect)); | 541 gfx::RectF(quad->visible_rect)); |
| 469 gfx::RectF visible_quad_vertex_rect = MathUtil::ScaleRectProportional( | 542 gfx::RectF visible_quad_vertex_rect = MathUtil::ScaleRectProportional( |
| 470 QuadVertexRect(), gfx::RectF(quad->rect), gfx::RectF(quad->visible_rect)); | 543 QuadVertexRect(), gfx::RectF(quad->rect), gfx::RectF(quad->visible_rect)); |
| 471 | 544 |
| 472 SkRect uv_rect = gfx::RectFToSkRect(visible_tex_coord_rect); | 545 SkRect uv_rect = gfx::RectFToSkRect(visible_tex_coord_rect); |
| 473 current_paint_.setFilterQuality( | 546 current_paint_.setFilterQuality( |
| 474 quad->nearest_neighbor ? kNone_SkFilterQuality : kLow_SkFilterQuality); | 547 quad->nearest_neighbor ? kNone_SkFilterQuality : kLow_SkFilterQuality); |
| 475 current_canvas_->drawBitmapRect(*lock.sk_bitmap(), uv_rect, | 548 current_canvas_->drawImageRect(lock.sk_image(), uv_rect, |
| 476 gfx::RectFToSkRect(visible_quad_vertex_rect), | 549 gfx::RectFToSkRect(visible_quad_vertex_rect), |
| 477 ¤t_paint_); | 550 ¤t_paint_); |
| 478 } | 551 } |
| 479 | 552 |
| 480 void SoftwareRenderer::DrawRenderPassQuad(const DrawingFrame* frame, | 553 void SkiaRenderer::DrawRenderPassQuad(const DrawingFrame* frame, |
| 481 const RenderPassDrawQuad* quad) { | 554 const RenderPassDrawQuad* quad) { |
| 555 #if 0 |
| 482 ScopedResource* content_texture = | 556 ScopedResource* content_texture = |
| 483 render_pass_textures_[quad->render_pass_id].get(); | 557 render_pass_textures_[quad->render_pass_id].get(); |
| 484 DCHECK(content_texture); | 558 DCHECK(content_texture); |
| 485 DCHECK(content_texture->id()); | 559 DCHECK(content_texture->id()); |
| 486 DCHECK(IsSoftwareResource(content_texture->id())); | 560 DCHECK(IsSoftwareResource(content_texture->id())); |
| 487 | 561 |
| 488 ResourceProvider::ScopedReadLockSoftware lock(resource_provider_, | 562 ResourceProvider::ScopedReadLockGL lock(resource_provider_, |
| 489 content_texture->id()); | 563 content_texture->id()); |
| 490 if (!lock.valid()) | 564 if (!lock.valid()) |
| 491 return; | 565 return; |
| 492 | 566 |
| 493 SkRect dest_rect = gfx::RectFToSkRect(QuadVertexRect()); | 567 SkRect dest_rect = gfx::RectFToSkRect(QuadVertexRect()); |
| 494 SkRect dest_visible_rect = gfx::RectFToSkRect( | 568 SkRect dest_visible_rect = gfx::RectFToSkRect( |
| 495 MathUtil::ScaleRectProportional(QuadVertexRect(), gfx::RectF(quad->rect), | 569 MathUtil::ScaleRectProportional(QuadVertexRect(), gfx::RectF(quad->rect), |
| 496 gfx::RectF(quad->visible_rect))); | 570 gfx::RectF(quad->visible_rect))); |
| 497 SkRect content_rect = SkRect::MakeWH(quad->rect.width(), quad->rect.height()); | 571 SkRect content_rect = SkRect::MakeWH(quad->rect.width(), quad->rect.height()); |
| 498 | 572 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 529 sk_sp<SkShader> shader; | 603 sk_sp<SkShader> shader; |
| 530 if (!filter_image) { | 604 if (!filter_image) { |
| 531 shader = | 605 shader = |
| 532 SkShader::MakeBitmapShader(*content, SkShader::kClamp_TileMode, | 606 SkShader::MakeBitmapShader(*content, SkShader::kClamp_TileMode, |
| 533 SkShader::kClamp_TileMode, &content_mat); | 607 SkShader::kClamp_TileMode, &content_mat); |
| 534 } else { | 608 } else { |
| 535 shader = filter_image->makeShader(SkShader::kClamp_TileMode, | 609 shader = filter_image->makeShader(SkShader::kClamp_TileMode, |
| 536 SkShader::kClamp_TileMode, &content_mat); | 610 SkShader::kClamp_TileMode, &content_mat); |
| 537 } | 611 } |
| 538 | 612 |
| 539 std::unique_ptr<ResourceProvider::ScopedReadLockSoftware> mask_lock; | 613 std::unique_ptr<ResourceProvider::ScopedReadLockGL> mask_lock; |
| 540 if (quad->mask_resource_id()) { | 614 if (quad->mask_resource_id()) { |
| 541 mask_lock = std::unique_ptr<ResourceProvider::ScopedReadLockSoftware>( | 615 mask_lock = std::unique_ptr<ResourceProvider::ScopedReadLockGL>( |
| 542 new ResourceProvider::ScopedReadLockSoftware(resource_provider_, | 616 new ResourceProvider::ScopedReadLockGL(resource_provider_, |
| 543 quad->mask_resource_id())); | 617 quad->mask_resource_id())); |
| 544 | 618 |
| 545 if (!mask_lock->valid()) | 619 if (!mask_lock->valid()) |
| 546 return; | 620 return; |
| 547 | 621 |
| 548 const SkBitmap* mask = mask_lock->sk_bitmap(); | 622 const SkBitmap* mask = mask_lock->sk_bitmap(); |
| 549 | 623 |
| 550 // Scale normalized uv rect into absolute texel coordinates. | 624 // Scale normalized uv rect into absolute texel coordinates. |
| 551 SkRect mask_rect = | 625 SkRect mask_rect = |
| 552 gfx::RectFToSkRect(gfx::ScaleRect(quad->MaskUVRect(), | 626 gfx::RectFToSkRect(gfx::ScaleRect(quad->MaskUVRect(), |
| (...skipping 18 matching lines...) Expand all Loading... |
| 571 sk_sp<SkShader> background_filter_shader = | 645 sk_sp<SkShader> background_filter_shader = |
| 572 GetBackgroundFilterShader(frame, quad, SkShader::kClamp_TileMode); | 646 GetBackgroundFilterShader(frame, quad, SkShader::kClamp_TileMode); |
| 573 if (background_filter_shader) { | 647 if (background_filter_shader) { |
| 574 SkPaint paint; | 648 SkPaint paint; |
| 575 paint.setShader(std::move(background_filter_shader)); | 649 paint.setShader(std::move(background_filter_shader)); |
| 576 paint.setRasterizer(sk_ref_sp(current_paint_.getRasterizer())); | 650 paint.setRasterizer(sk_ref_sp(current_paint_.getRasterizer())); |
| 577 current_canvas_->drawRect(dest_visible_rect, paint); | 651 current_canvas_->drawRect(dest_visible_rect, paint); |
| 578 } | 652 } |
| 579 current_paint_.setShader(std::move(shader)); | 653 current_paint_.setShader(std::move(shader)); |
| 580 current_canvas_->drawRect(dest_visible_rect, current_paint_); | 654 current_canvas_->drawRect(dest_visible_rect, current_paint_); |
| 655 #endif |
| 581 } | 656 } |
| 582 | 657 |
| 583 void SoftwareRenderer::DrawUnsupportedQuad(const DrawingFrame* frame, | 658 void SkiaRenderer::DrawUnsupportedQuad(const DrawingFrame* frame, |
| 584 const DrawQuad* quad) { | 659 const DrawQuad* quad) { |
| 585 #ifdef NDEBUG | 660 #ifdef NDEBUG |
| 586 current_paint_.setColor(SK_ColorWHITE); | 661 current_paint_.setColor(SK_ColorWHITE); |
| 587 #else | 662 #else |
| 588 current_paint_.setColor(SK_ColorMAGENTA); | 663 current_paint_.setColor(SK_ColorMAGENTA); |
| 589 #endif | 664 #endif |
| 590 current_paint_.setAlpha(quad->shared_quad_state->opacity * 255); | 665 current_paint_.setAlpha(quad->shared_quad_state->opacity * 255); |
| 591 current_canvas_->drawRect(gfx::RectFToSkRect(QuadVertexRect()), | 666 current_canvas_->drawRect(gfx::RectFToSkRect(QuadVertexRect()), |
| 592 current_paint_); | 667 current_paint_); |
| 593 } | 668 } |
| 594 | 669 |
| 595 void SoftwareRenderer::CopyCurrentRenderPassToBitmap( | 670 void SkiaRenderer::CopyCurrentRenderPassToBitmap( |
| 596 DrawingFrame* frame, | 671 DrawingFrame* frame, |
| 597 std::unique_ptr<CopyOutputRequest> request) { | 672 std::unique_ptr<CopyOutputRequest> request) { |
| 673 #if 0 |
| 598 gfx::Rect copy_rect = frame->current_render_pass->output_rect; | 674 gfx::Rect copy_rect = frame->current_render_pass->output_rect; |
| 599 if (request->has_area()) | 675 if (request->has_area()) |
| 600 copy_rect.Intersect(request->area()); | 676 copy_rect.Intersect(request->area()); |
| 601 gfx::Rect window_copy_rect = MoveFromDrawToWindowSpace(frame, copy_rect); | 677 gfx::Rect window_copy_rect = MoveFromDrawToWindowSpace(frame, copy_rect); |
| 602 | 678 |
| 603 std::unique_ptr<SkBitmap> bitmap(new SkBitmap); | 679 std::unique_ptr<SkBitmap> bitmap(new SkBitmap); |
| 604 bitmap->setInfo(SkImageInfo::MakeN32Premul(window_copy_rect.width(), | 680 bitmap->setInfo(SkImageInfo::MakeN32Premul(window_copy_rect.width(), |
| 605 window_copy_rect.height())); | 681 window_copy_rect.height())); |
| 606 current_canvas_->readPixels( | 682 current_canvas_->readPixels( |
| 607 bitmap.get(), window_copy_rect.x(), window_copy_rect.y()); | 683 bitmap.get(), window_copy_rect.x(), window_copy_rect.y()); |
| 608 | 684 |
| 609 request->SendBitmapResult(std::move(bitmap)); | 685 request->SendBitmapResult(std::move(bitmap)); |
| 686 #endif |
| 610 } | 687 } |
| 611 | 688 |
| 612 void SoftwareRenderer::DiscardBackbuffer() { | 689 void SkiaRenderer::DiscardBackbuffer() { |
| 613 if (is_backbuffer_discarded_) | 690 if (is_backbuffer_discarded_) |
| 614 return; | 691 return; |
| 615 | 692 |
| 616 output_surface_->DiscardBackbuffer(); | 693 output_surface_->DiscardBackbuffer(); |
| 617 | 694 |
| 618 is_backbuffer_discarded_ = true; | 695 is_backbuffer_discarded_ = true; |
| 619 | 696 |
| 620 // Damage tracker needs a full reset every time framebuffer is discarded. | 697 // Damage tracker needs a full reset every time framebuffer is discarded. |
| 621 client_->SetFullRootLayerDamage(); | 698 client_->SetFullRootLayerDamage(); |
| 622 } | 699 } |
| 623 | 700 |
| 624 void SoftwareRenderer::EnsureBackbuffer() { | 701 void SkiaRenderer::EnsureBackbuffer() { |
| 625 if (!is_backbuffer_discarded_) | 702 if (!is_backbuffer_discarded_) |
| 626 return; | 703 return; |
| 627 | 704 |
| 628 output_surface_->EnsureBackbuffer(); | 705 output_surface_->EnsureBackbuffer(); |
| 629 is_backbuffer_discarded_ = false; | 706 is_backbuffer_discarded_ = false; |
| 630 } | 707 } |
| 631 | 708 |
| 632 void SoftwareRenderer::DidChangeVisibility() { | 709 void SkiaRenderer::DidChangeVisibility() { |
| 633 if (visible()) | 710 if (visible()) |
| 634 EnsureBackbuffer(); | 711 EnsureBackbuffer(); |
| 635 else | 712 else |
| 636 DiscardBackbuffer(); | 713 DiscardBackbuffer(); |
| 637 } | 714 } |
| 638 | 715 |
| 639 bool SoftwareRenderer::ShouldApplyBackgroundFilters( | 716 void SkiaRenderer::FinishDrawingQuadList() { |
| 717 current_canvas_->flush(); |
| 718 } |
| 719 |
| 720 bool SkiaRenderer::ShouldApplyBackgroundFilters( |
| 640 const RenderPassDrawQuad* quad) const { | 721 const RenderPassDrawQuad* quad) const { |
| 641 if (quad->background_filters.IsEmpty()) | 722 if (quad->background_filters.IsEmpty()) |
| 642 return false; | 723 return false; |
| 643 | 724 |
| 644 // TODO(hendrikw): Look into allowing background filters to see pixels from | 725 // TODO(hendrikw): Look into allowing background filters to see pixels from |
| 645 // other render targets. See crbug.com/314867. | 726 // other render targets. See crbug.com/314867. |
| 646 | 727 |
| 647 return true; | 728 return true; |
| 648 } | 729 } |
| 649 | 730 |
| 650 // If non-null, auto_bounds will be filled with the automatically-computed | 731 // If non-null, auto_bounds will be filled with the automatically-computed |
| 651 // destination bounds. If null, the output will be the same size as the | 732 // destination bounds. If null, the output will be the same size as the |
| 652 // input bitmap. | 733 // input bitmap. |
| 653 sk_sp<SkImage> SoftwareRenderer::ApplyImageFilter( | 734 sk_sp<SkImage> SkiaRenderer::ApplyImageFilter(SkImageFilter* filter, |
| 654 SkImageFilter* filter, | 735 const RenderPassDrawQuad* quad, |
| 655 const RenderPassDrawQuad* quad, | 736 const SkBitmap& to_filter, |
| 656 const SkBitmap& to_filter, | 737 SkIRect* auto_bounds) const { |
| 657 SkIRect* auto_bounds) const { | |
| 658 if (!filter) | 738 if (!filter) |
| 659 return nullptr; | 739 return nullptr; |
| 660 | 740 |
| 661 SkMatrix local_matrix; | 741 SkMatrix local_matrix; |
| 662 local_matrix.setScale(quad->filters_scale.x(), quad->filters_scale.y()); | 742 local_matrix.setScale(quad->filters_scale.x(), quad->filters_scale.y()); |
| 663 SkIRect dst_rect; | 743 SkIRect dst_rect; |
| 664 if (auto_bounds) { | 744 if (auto_bounds) { |
| 665 dst_rect = | 745 dst_rect = |
| 666 filter->filterBounds(gfx::RectToSkIRect(quad->rect), local_matrix, | 746 filter->filterBounds(gfx::RectToSkIRect(quad->rect), local_matrix, |
| 667 SkImageFilter::kForward_MapDirection); | 747 SkImageFilter::kForward_MapDirection); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 680 | 760 |
| 681 SkPaint paint; | 761 SkPaint paint; |
| 682 paint.setImageFilter(filter->makeWithLocalMatrix(local_matrix)); | 762 paint.setImageFilter(filter->makeWithLocalMatrix(local_matrix)); |
| 683 surface->getCanvas()->translate(-dst_rect.x(), -dst_rect.y()); | 763 surface->getCanvas()->translate(-dst_rect.x(), -dst_rect.y()); |
| 684 surface->getCanvas()->drawBitmap(to_filter, quad->rect.x(), quad->rect.y(), | 764 surface->getCanvas()->drawBitmap(to_filter, quad->rect.x(), quad->rect.y(), |
| 685 &paint); | 765 &paint); |
| 686 | 766 |
| 687 return surface->makeImageSnapshot(); | 767 return surface->makeImageSnapshot(); |
| 688 } | 768 } |
| 689 | 769 |
| 690 SkBitmap SoftwareRenderer::GetBackdropBitmap( | 770 SkBitmap SkiaRenderer::GetBackdropBitmap(const gfx::Rect& bounding_rect) const { |
| 691 const gfx::Rect& bounding_rect) const { | |
| 692 SkBitmap bitmap; | 771 SkBitmap bitmap; |
| 693 bitmap.setInfo(SkImageInfo::MakeN32Premul(bounding_rect.width(), | 772 bitmap.setInfo(SkImageInfo::MakeN32Premul(bounding_rect.width(), |
| 694 bounding_rect.height())); | 773 bounding_rect.height())); |
| 695 current_canvas_->readPixels(&bitmap, bounding_rect.x(), bounding_rect.y()); | 774 current_canvas_->readPixels(&bitmap, bounding_rect.x(), bounding_rect.y()); |
| 696 return bitmap; | 775 return bitmap; |
| 697 } | 776 } |
| 698 | 777 |
| 699 gfx::Rect SoftwareRenderer::GetBackdropBoundingBoxForRenderPassQuad( | 778 gfx::Rect SkiaRenderer::GetBackdropBoundingBoxForRenderPassQuad( |
| 700 const DrawingFrame* frame, | 779 const DrawingFrame* frame, |
| 701 const RenderPassDrawQuad* quad, | 780 const RenderPassDrawQuad* quad, |
| 702 const gfx::Transform& contents_device_transform) const { | 781 const gfx::Transform& contents_device_transform) const { |
| 703 DCHECK(ShouldApplyBackgroundFilters(quad)); | 782 DCHECK(ShouldApplyBackgroundFilters(quad)); |
| 704 gfx::Rect backdrop_rect = gfx::ToEnclosingRect( | 783 gfx::Rect backdrop_rect = gfx::ToEnclosingRect( |
| 705 MathUtil::MapClippedRect(contents_device_transform, QuadVertexRect())); | 784 MathUtil::MapClippedRect(contents_device_transform, QuadVertexRect())); |
| 706 | 785 |
| 707 int top, right, bottom, left; | 786 int top, right, bottom, left; |
| 708 quad->background_filters.GetOutsets(&top, &right, &bottom, &left); | 787 quad->background_filters.GetOutsets(&top, &right, &bottom, &left); |
| 709 backdrop_rect.Inset(-left, -top, -right, -bottom); | 788 backdrop_rect.Inset(-left, -top, -right, -bottom); |
| 710 | 789 |
| 711 backdrop_rect.Intersect(MoveFromDrawToWindowSpace( | 790 backdrop_rect.Intersect(MoveFromDrawToWindowSpace( |
| 712 frame, frame->current_render_pass->output_rect)); | 791 frame, frame->current_render_pass->output_rect)); |
| 713 | 792 |
| 714 return backdrop_rect; | 793 return backdrop_rect; |
| 715 } | 794 } |
| 716 | 795 |
| 717 sk_sp<SkShader> SoftwareRenderer::GetBackgroundFilterShader( | 796 sk_sp<SkShader> SkiaRenderer::GetBackgroundFilterShader( |
| 718 const DrawingFrame* frame, | 797 const DrawingFrame* frame, |
| 719 const RenderPassDrawQuad* quad, | 798 const RenderPassDrawQuad* quad, |
| 720 SkShader::TileMode content_tile_mode) const { | 799 SkShader::TileMode content_tile_mode) const { |
| 800 #if 0 |
| 721 if (!ShouldApplyBackgroundFilters(quad)) | 801 if (!ShouldApplyBackgroundFilters(quad)) |
| 722 return nullptr; | 802 return nullptr; |
| 723 | 803 |
| 724 gfx::Transform quad_rect_matrix; | 804 gfx::Transform quad_rect_matrix; |
| 725 QuadRectTransform(&quad_rect_matrix, | 805 QuadRectTransform(&quad_rect_matrix, |
| 726 quad->shared_quad_state->quad_to_target_transform, | 806 quad->shared_quad_state->quad_to_target_transform, |
| 727 gfx::RectF(quad->rect)); | 807 gfx::RectF(quad->rect)); |
| 728 gfx::Transform contents_device_transform = | 808 gfx::Transform contents_device_transform = |
| 729 frame->window_matrix * frame->projection_matrix * quad_rect_matrix; | 809 frame->window_matrix * frame->projection_matrix * quad_rect_matrix; |
| 730 contents_device_transform.FlattenTo2d(); | 810 contents_device_transform.FlattenTo2d(); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 748 quad->background_filters, | 828 quad->background_filters, |
| 749 gfx::SizeF(backdrop_bitmap.width(), backdrop_bitmap.height())); | 829 gfx::SizeF(backdrop_bitmap.width(), backdrop_bitmap.height())); |
| 750 sk_sp<SkImage> filter_backdrop_image = | 830 sk_sp<SkImage> filter_backdrop_image = |
| 751 ApplyImageFilter(filter.get(), quad, backdrop_bitmap, nullptr); | 831 ApplyImageFilter(filter.get(), quad, backdrop_bitmap, nullptr); |
| 752 | 832 |
| 753 if (!filter_backdrop_image) | 833 if (!filter_backdrop_image) |
| 754 return nullptr; | 834 return nullptr; |
| 755 | 835 |
| 756 return filter_backdrop_image->makeShader(content_tile_mode, content_tile_mode, | 836 return filter_backdrop_image->makeShader(content_tile_mode, content_tile_mode, |
| 757 &filter_backdrop_transform); | 837 &filter_backdrop_transform); |
| 838 #else |
| 839 return nullptr; |
| 840 #endif |
| 758 } | 841 } |
| 759 | 842 |
| 760 } // namespace cc | 843 } // namespace cc |
| OLD | NEW |