Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "cc/resources/gpu_rasterizer.h" | |
| 6 | |
| 7 #include <algorithm> | |
| 8 | |
| 9 #include "base/bind.h" | |
| 10 #include "base/debug/trace_event.h" | |
| 11 #include "base/metrics/histogram.h" | |
| 12 #include "cc/debug/devtools_instrumentation.h" | |
| 13 #include "cc/debug/frame_viewer_instrumentation.h" | |
| 14 #include "cc/output/context_provider.h" | |
| 15 #include "cc/resources/raster_buffer.h" | |
| 16 #include "cc/resources/raster_source.h" | |
| 17 #include "cc/resources/resource.h" | |
| 18 #include "cc/resources/resource_provider.h" | |
| 19 #include "cc/resources/scoped_gpu_raster.h" | |
| 20 #include "cc/resources/tile_manager.h" | |
| 21 #include "gpu/command_buffer/client/gles2_interface.h" | |
| 22 #include "third_party/skia/include/core/SkMultiPictureDraw.h" | |
| 23 #include "third_party/skia/include/core/SkPictureRecorder.h" | |
| 24 #include "third_party/skia/include/core/SkSurface.h" | |
| 25 #include "third_party/skia/include/gpu/GrContext.h" | |
| 26 | |
| 27 namespace cc { | |
| 28 namespace { | |
| 29 | |
| 30 // Flag to indicate whether we should try and detect that | |
| 31 // a tile is of solid color. | |
| 32 const bool kUseColorEstimator = true; | |
|
vmpstr
2014/12/23 09:51:02
I know we have this elsewhere, but can you remove
hendrikw
2014/12/23 18:10:33
Sure, do you want me to remove the one in tilemana
| |
| 33 | |
| 34 } // namespace | |
| 35 | |
| 36 // static | |
| 37 scoped_ptr<GpuRasterizer> GpuRasterizer::Create( | |
| 38 ContextProvider* context_provider, | |
| 39 ResourceProvider* resource_provider, | |
| 40 bool use_distance_field_text, | |
| 41 bool tile_prepare_enabled) { | |
| 42 return make_scoped_ptr<GpuRasterizer>( | |
| 43 new GpuRasterizer(context_provider, resource_provider, | |
| 44 use_distance_field_text, tile_prepare_enabled)); | |
| 45 } | |
| 46 | |
| 47 GpuRasterizer::GpuRasterizer(ContextProvider* context_provider, | |
| 48 ResourceProvider* resource_provider, | |
| 49 bool use_distance_field_text, | |
| 50 bool tile_prepare_enabled) | |
| 51 : context_provider_(context_provider), | |
| 52 resource_provider_(resource_provider), | |
| 53 use_distance_field_text_(use_distance_field_text), | |
| 54 tile_prepare_enabled_(tile_prepare_enabled) { | |
| 55 DCHECK(context_provider_); | |
| 56 } | |
| 57 | |
| 58 GpuRasterizer::~GpuRasterizer() { | |
| 59 } | |
| 60 | |
| 61 PrepareTilesMode GpuRasterizer::GetPrepareTilesMode() { | |
| 62 return tile_prepare_enabled_ ? PrepareTilesMode::PREPARE_PRIORITIZED_TILES | |
|
vmpstr
2014/12/23 09:51:02
It feels a bit awkward to pass this bool, since we
hendrikw
2014/12/23 18:10:33
I don't know what the plans for this are, I though
vmiura
2014/12/23 18:33:13
In my patch it's turned on by a "--enable-tile-pre
| |
| 63 : PrepareTilesMode::PREPARE_NONE; | |
| 64 } | |
| 65 | |
| 66 void GpuRasterizer::RasterizeTiles(const TileVector& tiles, | |
| 67 ResourcePool* resource_pool, | |
| 68 TileManager* tile_manager) { | |
|
vmpstr
2014/12/23 09:51:02
:\ I'm not really a fan of rasterizer being owned
hendrikw
2014/12/23 18:10:33
Not a fan? We do this _EVERYWHERE_! :)
Sure, I'
| |
| 69 ScopedGpuRaster gpu_raster(context_provider_); | |
| 70 | |
| 71 for (auto tile : tiles) { | |
| 72 scoped_ptr<ScopedResource> resource = | |
| 73 resource_pool->AcquireResource(tile->size()); | |
| 74 const ScopedResource* const_resource = resource.get(); | |
| 75 | |
| 76 RasterSource::SolidColorAnalysis analysis; | |
| 77 | |
| 78 if (tile->use_picture_analysis()) | |
| 79 Analyze(tile, &analysis); | |
| 80 | |
| 81 if (!analysis.is_solid_color) | |
| 82 Raster(tile, const_resource); | |
|
vmpstr
2014/12/23 09:51:02
Should this be called something like "AppendToMult
hendrikw
2014/12/23 18:10:33
Yes!
I'll also rename Analyze to PerformSolidColo
| |
| 83 | |
| 84 tile_manager->CompleteRasterTask(tile->id(), resource.Pass(), analysis); | |
| 85 } | |
| 86 | |
| 87 multi_picture_draw_.draw(); | |
| 88 } | |
| 89 | |
| 90 void GpuRasterizer::Analyze(const Tile* tile, | |
| 91 RasterSource::SolidColorAnalysis* analysis) { | |
| 92 const void* tile_id = static_cast<const void*>(tile); | |
| 93 frame_viewer_instrumentation::ScopedAnalyzeTask analyze_task( | |
| 94 tile_id, tile->combined_priority().resolution, | |
| 95 tile->source_frame_number(), tile->layer_id()); | |
| 96 | |
| 97 DCHECK(tile->raster_source()); | |
| 98 | |
| 99 tile->raster_source()->PerformSolidColorAnalysis( | |
| 100 tile->content_rect(), tile->contents_scale(), analysis); | |
| 101 | |
| 102 // Record the solid color prediction. | |
| 103 UMA_HISTOGRAM_BOOLEAN("Renderer4.SolidColorTilesAnalyzed", | |
| 104 analysis->is_solid_color); | |
| 105 | |
| 106 // Clear the flag if we're not using the estimator. | |
| 107 analysis->is_solid_color &= kUseColorEstimator; | |
| 108 } | |
| 109 | |
| 110 void GpuRasterizer::Raster(const Tile* tile, const ScopedResource* resource) { | |
| 111 const void* tile_id = static_cast<const void*>(tile); | |
| 112 frame_viewer_instrumentation::ScopedRasterTask raster_task( | |
| 113 tile_id, tile->combined_priority().resolution, | |
| 114 tile->source_frame_number(), tile->layer_id()); | |
| 115 | |
| 116 DCHECK(tile->raster_source()); | |
| 117 | |
| 118 ResourceProvider::ScopedWriteLockGr lock(resource_provider_, resource->id()); | |
| 119 | |
| 120 // Turn on distance fields for layers that have ever animated. | |
| 121 bool use_distance_field_text = | |
| 122 use_distance_field_text_ || | |
| 123 tile->raster_source()->ShouldAttemptToUseDistanceFieldText(); | |
| 124 SkSurface* sk_surface = lock.GetSkSurface( | |
| 125 use_distance_field_text, tile->raster_source()->CanUseLCDText()); | |
| 126 | |
| 127 if (!sk_surface) | |
| 128 return; | |
| 129 | |
| 130 SkPictureRecorder recorder; | |
| 131 gfx::Size size = resource->size(); | |
| 132 const int flags = SkPictureRecorder::kComputeSaveLayerInfo_RecordFlag; | |
| 133 skia::RefPtr<SkCanvas> canvas = skia::SharePtr( | |
| 134 recorder.beginRecording(size.width(), size.height(), NULL, flags)); | |
| 135 | |
| 136 canvas->save(); | |
| 137 tile->raster_source()->PlaybackToCanvas(canvas.get(), tile->content_rect(), | |
| 138 tile->contents_scale()); | |
| 139 canvas->restore(); | |
| 140 | |
| 141 // Add the canvas and recorded picture to |multi_picture_draw_|. | |
| 142 skia::RefPtr<SkPicture> picture = skia::AdoptRef(recorder.endRecording()); | |
| 143 multi_picture_draw_.add(sk_surface->getCanvas(), picture.get()); | |
| 144 } | |
| 145 | |
| 146 } // namespace cc | |
| OLD | NEW |