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/gpu_rasterizer.h" | |
| 6 | |
| 7 #include "base/logging.h" | |
| 8 #include "cc/output/context_provider.h" | |
| 9 #include "cc/resources/resource_format.h" | |
| 10 #include "third_party/WebKit/public/platform/WebGraphicsContext3D.h" | |
| 11 #include "third_party/skia/include/core/SkCanvas.h" | |
| 12 #include "third_party/skia/include/gpu/GrContext.h" | |
| 13 #include "third_party/skia/include/gpu/SkGpuDevice.h" | |
| 14 #include "ui/gfx/size_conversions.h" | |
| 15 | |
| 16 namespace cc { | |
| 17 | |
| 18 namespace { | |
| 19 | |
| 20 GrPixelConfig toGrFormat(ResourceFormat format) { | |
| 21 switch (format) { | |
| 22 case RGBA_8888: | |
| 23 return kRGBA_8888_GrPixelConfig; | |
| 24 case BGRA_8888: | |
| 25 return kBGRA_8888_GrPixelConfig; | |
| 26 case RGBA_4444: | |
| 27 return kRGBA_4444_GrPixelConfig; | |
| 28 default: | |
| 29 break; // If you break here, you're gonna have a bad time. | |
| 30 } | |
| 31 DCHECK(false) << "Unsupported resource format."; | |
| 32 return kSkia8888_GrPixelConfig; | |
| 33 } | |
| 34 | |
| 35 } // namespace | |
| 36 | |
| 37 GpuRasterizer::RasterTask::RasterTask( | |
| 38 Tile* tile, scoped_ptr<ResourcePool::Resource> resource) | |
| 39 : tile_(tile), resource_(resource.Pass()) { | |
| 40 } | |
| 41 | |
| 42 GpuRasterizer::RasterTask::~RasterTask() { | |
| 43 } | |
| 44 | |
| 45 scoped_ptr<GpuRasterizer> GpuRasterizer::Create( | |
| 46 ContextProvider* context_provider, | |
| 47 ResourceProvider* resource_provider) { | |
| 48 return make_scoped_ptr( | |
| 49 new GpuRasterizer(context_provider, resource_provider)); | |
| 50 } | |
| 51 | |
| 52 GpuRasterizer::GpuRasterizer( | |
| 53 ContextProvider* context_provider, | |
| 54 ResourceProvider* resource_provider) | |
| 55 : client_(NULL), | |
| 56 context_provider_(context_provider), | |
| 57 resource_provider_(resource_provider) { | |
| 58 } | |
| 59 | |
| 60 GpuRasterizer::~GpuRasterizer() { | |
| 61 } | |
| 62 | |
| 63 void GpuRasterizer::SetClient(GpuRasterizerClient* client) { | |
| 64 client_ = client; | |
| 65 } | |
| 66 | |
| 67 void GpuRasterizer::PushRasterTask( | |
| 68 Tile* tile, scoped_ptr<ResourcePool::Resource> resource) { | |
| 69 raster_tasks_.push_back(new RasterTask(tile, resource.Pass())); | |
| 70 } | |
| 71 | |
| 72 void GpuRasterizer::FlushRasterTasks( | |
| 73 RenderingStatsInstrumentation* rendering_stats_instrumentation) { | |
| 74 TRACE_EVENT0("cc", "GpuRasterizer::Rasterize"); | |
| 75 | |
| 76 if (raster_tasks_.empty()) | |
| 77 return; | |
| 78 | |
| 79 blink::WebGraphicsContext3D* context = context_provider_->Context3d(); | |
| 80 GrContext* gr_context = context_provider_->GrContext(); | |
| 81 DCHECK(context); | |
| 82 DCHECK(gr_context); | |
| 83 | |
| 84 context->makeContextCurrent(); | |
| 85 gr_context->resetContext(); | |
| 86 for (RasterTaskVector::iterator it = raster_tasks_.begin(); | |
| 87 it != raster_tasks_.end(); ++it) { | |
| 88 RasterTask* task = *it; | |
| 89 Tile* tile = task->tile_; | |
| 90 DCHECK_NE(task->resource_->id(), 0u); | |
| 91 { | |
| 92 ResourceProvider::ScopedWriteLockGL lock( | |
| 93 resource_provider_, task->resource_->id()); | |
| 94 | |
| 95 DCHECK_NE(lock.texture_id(), 0u); | |
| 96 GrBackendTextureDesc desc; | |
| 97 desc.fFlags = kRenderTarget_GrBackendTextureFlag; | |
| 98 desc.fWidth = tile->size().width(); | |
| 99 desc.fHeight = tile->size().height(); | |
| 100 desc.fConfig = toGrFormat(lock.format()); | |
| 101 desc.fOrigin = kTopLeft_GrSurfaceOrigin; | |
| 102 desc.fTextureHandle = lock.texture_id(); | |
| 103 skia::RefPtr<GrTexture> texture = | |
| 104 skia::AdoptRef(gr_context->wrapBackendTexture(desc)); | |
| 105 skia::RefPtr<SkGpuDevice> device = | |
| 106 skia::AdoptRef(SkGpuDevice::Create(texture.get())); | |
| 107 CHECK(device); | |
| 108 skia::RefPtr<SkCanvas> canvas = | |
| 109 skia::AdoptRef(new SkCanvas(device.get())); | |
| 110 | |
| 111 if (tile->opaque_rect().IsEmpty()) | |
|
vangelis
2013/11/28 00:35:01
Shouldn't we be checking here for an opaque_rect()
slavi
2013/11/28 00:47:49
This doesn't happen currently. The opaque_rect is
| |
| 112 canvas->clear(SK_ColorTRANSPARENT); | |
| 113 | |
| 114 tile->picture_pile_->RasterDirect( | |
| 115 canvas.get(), tile->content_rect_, tile->contents_scale_, | |
|
vmpstr
2013/11/27 23:45:42
nit: tile provides public getters for picture pile
slavi
2013/11/28 00:47:49
Done.
| |
| 116 rendering_stats_instrumentation); | |
| 117 } | |
| 118 | |
| 119 if (client_) | |
| 120 client_->OnGpuRasterTaskCompleted(tile, task->resource_.Pass(), false); | |
| 121 } | |
| 122 gr_context->flush(); | |
| 123 raster_tasks_.clear(); | |
| 124 } | |
| 125 | |
| 126 } // namespace cc | |
| OLD | NEW |