Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2013 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/ganesh_rasterizer.h" | |
| 6 | |
| 7 #include "base/logging.h" | |
| 8 #include "cc/output/context_provider.h" | |
| 9 #include "third_party/WebKit/public/platform/WebGraphicsContext3D.h" | |
| 10 #include "third_party/skia/include/core/SkCanvas.h" | |
| 11 #include "third_party/skia/include/gpu/GrContext.h" | |
| 12 #include "third_party/skia/include/gpu/SkGpuDevice.h" | |
| 13 #include "ui/gfx/size_conversions.h" | |
| 14 | |
| 15 namespace cc { | |
| 16 | |
| 17 scoped_ptr<GaneshRasterizer> GaneshRasterizer::Create( | |
| 18 ContextProvider* context_provider, | |
| 19 ResourceProvider* resource_provider) { | |
| 20 if (!context_provider || | |
|
vmpstr
2013/11/22 21:29:12
Should these just be dchecks? or is there a valid
slavi
2013/11/23 01:27:19
Done.
| |
| 21 !context_provider->Context3d() || | |
| 22 !context_provider->GrContext()) | |
| 23 return scoped_ptr<cc::GaneshRasterizer>(); | |
| 24 return make_scoped_ptr( | |
| 25 new GaneshRasterizer(context_provider, resource_provider)); | |
| 26 } | |
| 27 | |
| 28 GaneshRasterizer::GaneshRasterizer( | |
| 29 ContextProvider* context_provider, | |
| 30 ResourceProvider* resource_provider) | |
| 31 : client_(NULL), | |
| 32 context_provider_(context_provider), | |
| 33 resource_provider_(resource_provider) { | |
| 34 DCHECK(context_provider_->Context3d()); | |
| 35 DCHECK(context_provider_->GrContext()); | |
| 36 } | |
| 37 | |
| 38 GaneshRasterizer::~GaneshRasterizer() { | |
| 39 } | |
| 40 | |
| 41 void GaneshRasterizer::SetClient(GaneshRasterizerClient* client) { | |
| 42 DCHECK(client); | |
| 43 DCHECK(!client_); | |
|
vmpstr
2013/11/22 21:29:12
With these two dchecks, it seems that client shoul
slavi
2013/11/23 01:27:19
This class get's instantiated before TileManager (
| |
| 44 client_ = client; | |
| 45 } | |
| 46 | |
| 47 GaneshRasterizer::RasterTask* GaneshRasterizer::CreateRasterTask( | |
| 48 Tile* tile, scoped_ptr<ResourcePool::Resource> resource) { | |
| 49 return new RasterTask(tile, resource.Pass()); | |
| 50 } | |
| 51 | |
| 52 void GaneshRasterizer::Rasterize( | |
| 53 RasterTaskVector& tasks, | |
| 54 RenderingStatsInstrumentation* rendering_stats_instrumentation) { | |
| 55 TRACE_EVENT0("cc", "GaneshRasterizer::Rasterize"); | |
| 56 | |
| 57 DCHECK(client_); | |
| 58 | |
| 59 if (tasks.empty()) | |
| 60 return; | |
| 61 | |
| 62 blink::WebGraphicsContext3D* context = context_provider_->Context3d(); | |
| 63 GrContext* gr_context = context_provider_->GrContext(); | |
| 64 | |
| 65 context->makeContextCurrent(); | |
| 66 gr_context->resetContext(); | |
| 67 for (RasterTaskVector::iterator it = tasks.begin(); it != tasks.end(); ++it) { | |
| 68 RasterTask* task = *it; | |
| 69 Tile* tile = task->tile_; | |
| 70 ManagedTileState& mts = tile->managed_state(); | |
| 71 DCHECK(mts.raster_mode == GANESH_RASTER_MODE); | |
| 72 DCHECK_NE(task->resource_->id(), 0u); | |
| 73 { | |
| 74 ResourceProvider::ScopedWriteLockGL lock( | |
| 75 resource_provider_, task->resource_->id()); | |
| 76 | |
| 77 DCHECK_NE(lock.texture_id(), 0u); | |
| 78 GrBackendTextureDesc desc; | |
| 79 desc.fFlags = kRenderTarget_GrBackendTextureFlag; | |
| 80 desc.fWidth = tile->size().width(); | |
| 81 desc.fHeight = tile->size().height(); | |
| 82 desc.fConfig = kSkia8888_GrPixelConfig; | |
| 83 desc.fOrigin = kTopLeft_GrSurfaceOrigin; | |
| 84 desc.fTextureHandle = lock.texture_id(); | |
| 85 skia::RefPtr<GrTexture> texture = | |
| 86 skia::AdoptRef(gr_context->wrapBackendTexture(desc)); | |
| 87 skia::RefPtr<SkGpuDevice> device = | |
| 88 skia::AdoptRef(SkGpuDevice::Create(texture.get())); | |
| 89 CHECK(device); | |
| 90 skia::RefPtr<SkCanvas> canvas = | |
| 91 skia::AdoptRef(new SkCanvas(device.get())); | |
| 92 | |
| 93 if (tile->opaque_rect().IsEmpty()) | |
| 94 canvas->clear(SK_ColorTRANSPARENT); | |
| 95 | |
| 96 tile->picture_pile_->RasterDirect( | |
| 97 canvas.get(), tile->content_rect_, tile->contents_scale_, | |
| 98 rendering_stats_instrumentation); | |
| 99 | |
| 100 // TODO(skaslev) Remove this marker. | |
| 101 { | |
| 102 SkPaint paint; | |
| 103 paint.setColor(SkColorSetRGB(255, 127, 0)); | |
| 104 canvas->drawRect(SkRect::MakeXYWH(5, 5, 15, 15), paint); | |
| 105 } | |
| 106 } | |
| 107 | |
| 108 client_->OnGaneshRasterTaskCompleted(tile, task->resource_.Pass(), false); | |
| 109 } | |
| 110 gr_context->flush(); | |
| 111 } | |
| 112 | |
| 113 } // namespace cc | |
| OLD | NEW |